Skip to content

Commit f6bab9e

Browse files
committed
upgrade window: add Download & Install button, show red outline if project version is missing, adjust ui aligments
1 parent 31bfb3d commit f6bab9e

File tree

4 files changed

+132
-15
lines changed

4 files changed

+132
-15
lines changed

Diff for: UnityLauncherPro/GetUnityInstallations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class GetUnityInstallations
1515
// returns unity installations
1616
public static UnityInstallation[] Scan()
1717
{
18-
// convert settings list to string array
18+
// get list from settings
1919
var rootFolders = Properties.Settings.Default.rootFolders;
2020

2121
// unityversion, exe_path

Diff for: UnityLauncherPro/Tools.cs

+80
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,86 @@ public static void DownloadInBrowser(string url, string version)
563563
}
564564
}
565565

566+
public static void DownloadAndInstall(string url, string version)
567+
{
568+
string exeURL = ParseDownloadURLFromWebpage(version);
569+
570+
Console.WriteLine("download exeURL= (" + exeURL + ")");
571+
572+
if (string.IsNullOrEmpty(exeURL) == false && exeURL.StartsWith("https") == true)
573+
{
574+
//SetStatus("Download installer in browser: " + exeURL);
575+
// download url file to temp
576+
string tempFile = Path.GetTempPath() + "UnityDownloadAssistant-" + version.Replace(".", "_") + ".exe";
577+
//Console.WriteLine("download tempFile= (" + tempFile + ")");
578+
if (File.Exists(tempFile) == true) File.Delete(tempFile);
579+
580+
// TODO make async
581+
if (DownloadFile(exeURL, tempFile) == true)
582+
{
583+
// run installer, copy current existing version path to clipboard, NOTE this probably never happens? unless install same version again..
584+
if (MainWindow.unityInstalledVersions.ContainsKey(version) == true)
585+
{
586+
string path = MainWindow.unityInstalledVersions[version];
587+
if (string.IsNullOrEmpty(path) == false)
588+
{
589+
// copy to clipboard
590+
Clipboard.SetText(path);
591+
}
592+
}
593+
else // no same version, copy last item from root folders
594+
{
595+
if (Properties.Settings.Default.rootFolders.Count > 0)
596+
{
597+
string path = Properties.Settings.Default.rootFolders[Properties.Settings.Default.rootFolders.Count - 1];
598+
if (string.IsNullOrEmpty(path) == false)
599+
{
600+
Clipboard.SetText(path);
601+
}
602+
}
603+
}
604+
605+
Process process = Process.Start(tempFile);
606+
process.EnableRaisingEvents = true;
607+
process.Exited += (sender, e) => DeleteTempFile(tempFile);
608+
// TODO refresh upgrade dialog after installer finished
609+
}
610+
}
611+
else // not found
612+
{
613+
//SetStatus("Error> Cannot find installer executable ... opening website instead");
614+
url = "https://unity3d.com/get-unity/download/archive";
615+
Process.Start(url + "#installer-not-found---version-" + version);
616+
}
617+
}
618+
619+
static void DeleteTempFile(string path)
620+
{
621+
if (File.Exists(path) == true)
622+
{
623+
Console.WriteLine("DeleteTempFile: " + path);
624+
File.Delete(path);
625+
}
626+
}
627+
628+
static bool DownloadFile(string url, string tempFile)
629+
{
630+
bool result = false;
631+
try
632+
{
633+
using (WebClient client = new WebClient())
634+
{
635+
client.DownloadFile(url, tempFile);
636+
result = true;
637+
}
638+
}
639+
catch (Exception e)
640+
{
641+
Console.WriteLine("Error> DownloadFile: " + e);
642+
}
643+
return result;
644+
}
645+
566646
// parse Unity installer exe from release page
567647
// thanks to https://github.com/softfruit
568648
public static string ParseDownloadURLFromWebpage(string version)

Diff for: UnityLauncherPro/UpgradeWindow.xaml

+27-11
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,46 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="Upgrade Project Version" Height="533.165" Width="418.684" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="319" MinHeight="555" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewKeyDown="Window_PreviewKeyDown" ShowInTaskbar="False">
8+
Title="Upgrade Project Version" Height="533.165" Width="419" Background="{DynamicResource ThemeDarkestBackground}" MinWidth="319" MinHeight="555" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewKeyDown="Window_PreviewKeyDown" ShowInTaskbar="False">
99

1010
<Grid>
1111
<StackPanel Orientation="Horizontal">
1212
<Label x:Name="lblCurrentVersion" Content="Project version:" HorizontalAlignment="Left" Margin="9,11,0,0" VerticalAlignment="Top" Foreground="{DynamicResource ThemeButtonForeground}"/>
1313
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" x:Name="txtCurrentVersion" Background="{DynamicResource ThemeDarkMenuBar}" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="0,16,0,0" UndoLimit="64" Text="Version" IsReadOnly="True" VerticalAlignment="Top" />
1414
</StackPanel>
1515
<Label x:Name="lblAvailableVersions" Content="Available Unity Versions" HorizontalAlignment="Left" Margin="9,94,0,0" VerticalAlignment="Top" Foreground="{DynamicResource ThemeButtonForeground}"/>
16-
<Button Style="{StaticResource CustomButton}" x:Name="btnDownload" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="0,47,8,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="35" Click="BtnDownload_Click" Width="150" >
17-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Download in Browser"/>
18-
</Button>
19-
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenReleasePage" ToolTip="Open Release Notes Page in Browser" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="9,47,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="35" Click="BtnOpenReleasePage_Click" Width="150" >
20-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Open Release Notes"/>
21-
</Button>
16+
17+
<StackPanel Orientation="Horizontal" Margin="9,47,9,0">
18+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenReleasePage" ToolTip="Open Release Notes Page in Browser" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="35" Click="BtnOpenReleasePage_Click" Width="125" >
19+
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Open Release Notes"/>
20+
</Button>
21+
<Button Style="{StaticResource CustomButton}" x:Name="btnDownload" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="9,0,9,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="35" Click="BtnDownload_Click" Width="125" >
22+
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="Download in _Browser"/>
23+
</Button>
24+
<Button Style="{StaticResource CustomButton}" x:Name="btnInstall" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="35" Width="125" Click="btnInstall_Click" >
25+
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Download &amp; Install"/>
26+
</Button>
27+
</StackPanel>
28+
2229
<Button Style="{StaticResource CustomButton}" x:Name="btnCancelUpgrade" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="9,434,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" Width="111" VerticalAlignment="Top" Height="51" Click="BtnCancelUpgrade_Click" >
2330
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Cancel"/>
2431
</Button>
25-
<Button Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" ToolTip="Launch with selected Unity version" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="0,434,8,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" Width="159" VerticalAlignment="Top" Height="51" Click="BtnUpgradeProject_Click" >
32+
<Button Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" ToolTip="Launch with selected Unity version" Background="{DynamicResource ThemeButtonBackground}" Foreground="#FFC1C1C1" Margin="0,434,10,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" Width="159" VerticalAlignment="Top" Height="51" Click="BtnUpgradeProject_Click" >
2633
<Label Foreground="{DynamicResource ThemeButtonForeground}" Content="_Upgrade Project"/>
2734
</Button>
28-
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" HorizontalAlignment="Left" Height="304" Margin="10,121,0,0" VerticalAlignment="Top" Width="393" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
35+
36+
<!--<DataGrid x:Name="gridAvailableVersions" KeyboardNavigation.TabNavigation = "None" SelectionMode="Single" Height="270" Margin="0" VerticalAlignment="Top" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" SelectionChanged="GridAvailableVersions_SelectionChanged" IsTabStop="True" TabIndex="1" Loaded="GridAvailableVersions_Loaded" EnableRowVirtualization="False" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" PreviewMouseDoubleClick="gridAvailableVersions_PreviewMouseDoubleClick">
37+
<DataGrid.Columns>
38+
<DataGridTextColumn Header="Version" Binding="{Binding Version}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
39+
<DataGridTextColumn Header="Platforms" Binding="{Binding PlatformsCombined}" IsReadOnly="True" CanUserResize="False" MinWidth="270" />
40+
<DataGridTextColumn Header="Release" Binding="{Binding ReleaseType}" IsReadOnly="True" CanUserResize="False" MinWidth="70" />
41+
</DataGrid.Columns>
42+
</DataGrid>-->
43+
44+
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" Height="304" Margin="10,121,10,0" VerticalAlignment="Top" Width="383" HeadersVisibility="None" AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" Foreground="{DynamicResource ThemeButtonForeground}" Background="{DynamicResource ThemeMainBackgroundColor}" PreviewKeyDown="GridAvailableVersions_PreviewKeyDown" Loaded="GridAvailableVersions_Loaded" PreviewMouseDoubleClick="GridAvailableVersions_PreviewMouseDoubleClick" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible">
2945
<DataGrid.Columns>
30-
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" />
31-
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" />
46+
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" CanUserResize="False" MinWidth="80" />
47+
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" CanUserResize="False" />
3248
</DataGrid.Columns>
3349
</DataGrid>
3450

Diff for: UnityLauncherPro/UpgradeWindow.xaml.cs

+24-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,22 @@ public UpgradeWindow(string currentVersion, string projectPath, string commandLi
2020
InitializeComponent();
2121
txtCurrentVersion.Text = currentVersion;
2222
gridAvailableVersions.ItemsSource = MainWindow.unityInstalledVersions;
23-
2423
gridAvailableVersions.SelectedItem = null;
2524

26-
// autoselect nearest one FIXME doesnt work with 5.x (should suggest next highest installed in 201x.x)
25+
// we have current version info in project
2726
if (string.IsNullOrEmpty(currentVersion) == false)
2827
{
2928
// enable release and dl buttons
3029
btnOpenReleasePage.IsEnabled = true;
3130
btnDownload.IsEnabled = true;
3231

32+
// if dont have exact version, show red outline
33+
if (MainWindow.unityInstalledVersions.ContainsKey(currentVersion) == false)
34+
{
35+
txtCurrentVersion.BorderBrush = Brushes.Red;
36+
txtCurrentVersion.BorderThickness = new Thickness(1);
37+
}
38+
3339
// find nearest version
3440
string nearestVersion = Tools.FindNearestVersion(currentVersion, MainWindow.unityInstalledVersions.Keys.ToList());
3541
if (nearestVersion != null)
@@ -48,7 +54,7 @@ public UpgradeWindow(string currentVersion, string projectPath, string commandLi
4854
}
4955
}
5056
}
51-
else // we dont have current version
57+
else // we dont have current version info in project
5258
{
5359
btnOpenReleasePage.IsEnabled = false;
5460
btnDownload.IsEnabled = false;
@@ -110,6 +116,19 @@ private void BtnDownload_Click(object sender, RoutedEventArgs e)
110116
}
111117
}
112118

119+
private void btnInstall_Click(object sender, RoutedEventArgs e)
120+
{
121+
string url = Tools.GetUnityReleaseURL(txtCurrentVersion.Text);
122+
if (string.IsNullOrEmpty(url) == false)
123+
{
124+
Tools.DownloadAndInstall(url, txtCurrentVersion.Text);
125+
}
126+
else
127+
{
128+
Console.WriteLine("Failed getting Unity Installer URL for " + txtCurrentVersion.Text);
129+
}
130+
}
131+
113132
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
114133
{
115134
// override Enter for datagrid
@@ -168,5 +187,7 @@ void Upgrade()
168187
upgradeVersion = k.Value.Key;
169188
DialogResult = true;
170189
}
190+
191+
171192
}
172193
}

0 commit comments

Comments
 (0)