Skip to content

Commit 771e8ae

Browse files
committed
Changed: get unity installs returns list instead of array, Editors: add uninstall context menu (fix #103)
1 parent 6356aae commit 771e8ae

File tree

5 files changed

+79
-12
lines changed

5 files changed

+79
-12
lines changed

Diff for: UnityLauncherPro/GetUnityInstallations.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class GetUnityInstallations
1313

1414

1515
// returns unity installations
16-
public static UnityInstallation[] Scan()
16+
public static List<UnityInstallation> Scan()
1717
{
1818
// get list from settings
1919
var rootFolders = Properties.Settings.Default.rootFolders;
@@ -86,7 +86,7 @@ public static UnityInstallation[] Scan()
8686
// sort by version
8787
results.Sort((s1, s2) => s2.VersionCode.CompareTo(s1.VersionCode));
8888

89-
return results.ToArray();
89+
return results;
9090
} // scan()
9191

9292
public static bool HasUnityInstallations(string path)

Diff for: UnityLauncherPro/MainWindow.xaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@
248248

249249
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh installations (F5)" x:Name="btnRefreshUnityList" Content="" Height="22" Width="26" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Margin="0,4,3,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnRefreshUnityList_Click"/>
250250

251-
<DataGrid x:Name="dataGridUnitys" SelectionMode="Single" Margin="4,30,2,42" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" AutoGenerateColumns="False" PreviewKeyDown="DataGridUnitys_PreviewKeyDown" PreviewMouseDoubleClick="DataGridUnitys_PreviewMouseDoubleClick">
251+
<DataGrid x:Name="dataGridUnitys" SelectionMode="Single" Margin="4,30,2,42" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="{DynamicResource ThemeGridForeground}" HorizontalGridLinesBrush="{DynamicResource ThemeDatagridLines}" VerticalGridLinesBrush="{DynamicResource ThemeGridVerticalGridLines}" CanUserAddRows="False" AutoGenerateColumns="False" PreviewKeyDown="DataGridUnitys_PreviewKeyDown" PreviewMouseDoubleClick="DataGridUnitys_PreviewMouseDoubleClick">
252252
<DataGrid.CommandBindings>
253253
<CommandBinding Command="ApplicationCommands.Copy" Executed="CopyRowFolderToClipBoard" CanExecute="CanExecute_Copy"/>
254254
</DataGrid.CommandBindings>
@@ -292,6 +292,9 @@
292292
<MenuItem x:Name="menuItemDownloadWinDedicatedServerModule" Header="Download Windows Dedicated module" Click="menuItemDownloadWinDedicatedServerModule_Click"/>
293293
<MenuItem x:Name="menuItemDownloadLinuxDedicatedServerModule" Header="Download Linux Dedicated module" Click="menuItemDownloadLinuxDedicatedServerModule_Click"/>
294294
</MenuItem>
295+
<Separator></Separator>
296+
<MenuItem x:Name="menuUninstallEditor" Header="Uninstall" Click="menuUninstallEditor_Click"/>
297+
295298
</ContextMenu>
296299
</DataGrid.ContextMenu>
297300

@@ -662,7 +665,7 @@
662665

663666
</StackPanel>
664667
</GroupBox>
665-
668+
666669
<GroupBox Grid.Row="3" Header="UI" VerticalAlignment="Top" Margin="3,0,0,0">
667670
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="3,5,0,0" >
668671
<CheckBox x:Name="chkHumanFriendlyDateTime" Content="Use human friendly Last Modified" ToolTip="Last modified date format" HorizontalAlignment="Left" Checked="ChkHumanFriendlyDateTime_Checked" Unchecked="ChkHumanFriendlyDateTime_Checked"/>

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public partial class MainWindow : Window
3030
public static bool useHumanFriendlyDateFormat = false;
3131
public static bool searchProjectPathAlso = false;
3232
public static List<Project> projectsSource;
33-
public static UnityInstallation[] unityInstallationsSource;
33+
public static List<UnityInstallation> unityInstallationsSource;
3434
public static ObservableDictionary<string, string> unityInstalledVersions = new ObservableDictionary<string, string>(); // versionID and installation folder
3535
public static readonly string launcherArgumentsFile = "LauncherArguments.txt";
3636
public static readonly string projectNameFile = "ProjectName.txt";
@@ -640,7 +640,7 @@ void UpdateUnityInstallationsList()
640640
// also make dictionary of installed unitys, to search faster
641641
unityInstalledVersions.Clear();
642642

643-
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
643+
for (int i = 0, len = unityInstallationsSource.Count; i < len; i++)
644644
{
645645
var version = unityInstallationsSource[i].Version;
646646
// NOTE cannot have same version id in 2 places with this
@@ -650,7 +650,7 @@ void UpdateUnityInstallationsList()
650650
}
651651
}
652652

653-
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Length + " installations";
653+
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Count + " installations";
654654
}
655655

656656
Project GetSelectedProject()
@@ -2747,7 +2747,6 @@ private void BtnThemeEditor_Click(object sender, RoutedEventArgs e)
27472747
private void MenuRemoveProject_Click(object sender, RoutedEventArgs e)
27482748
{
27492749
// delete if enabled in settings
2750-
27512750
var proj = GetSelectedProject();
27522751
if (proj == null) return;
27532752

@@ -3316,6 +3315,21 @@ private void menuItemDownloadLinuxDedicatedServerModule_Click(object sender, Rou
33163315
Tools.DownloadAdditionalModules(unity.Path, unity.Version, "Linux-Server");
33173316
}
33183317

3318+
private void menuUninstallEditor_Click(object sender, RoutedEventArgs e)
3319+
{
3320+
var unity = GetSelectedUnity();
3321+
if (unity == null) return;
3322+
Tools.UninstallEditor(unity.Path, unity.Version);
3323+
3324+
var currentIndex = dataGridUnitys.SelectedIndex;
3325+
3326+
// TODO refresh list after exe's have finished (but for now just remove after hit uninstall, since would need to keep track of uninstall exes)
3327+
unityInstallationsSource.Remove(unity);
3328+
dataGridUnitys.Items.Refresh();
3329+
Tools.SetFocusToGrid(dataGridUnitys);
3330+
dataGridUnitys.SelectedIndex = currentIndex - 1 < 0 ? 0 : currentIndex - 1;
3331+
}
3332+
33193333
private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
33203334
{
33213335
// if press up or down, while tab control is focused, move focus to grid
@@ -3338,6 +3352,8 @@ private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
33383352

33393353

33403354

3355+
3356+
33413357
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
33423358
//{
33433359
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

Diff for: UnityLauncherPro/NewProject.xaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
4242
if (gridAvailableVersions.ItemsSource == null)
4343
{
4444
// get release type info (not done in mainwindow yet, to avoid doing extra stuff)
45-
for (int i = 0, len = MainWindow.unityInstallationsSource.Length; i < len; i++)
45+
for (int i = 0, len = MainWindow.unityInstallationsSource.Count; i < len; i++)
4646
{
4747
var ver = MainWindow.unityInstallationsSource[i].Version;
4848
if (Tools.IsLTS(ver))
@@ -65,7 +65,7 @@ public NewProject(string unityVersion, string suggestedName, string targetFolder
6565
if (MainWindow.unityInstalledVersions.ContainsKey(unityVersion) == true)
6666
{
6767
// find this unity version, TODO theres probably easier way than looping all
68-
for (int i = 0; i < MainWindow.unityInstallationsSource.Length; i++)
68+
for (int i = 0; i < MainWindow.unityInstallationsSource.Count; i++)
6969
{
7070
if (MainWindow.unityInstallationsSource[i].Version == newVersion)
7171
{

Diff for: UnityLauncherPro/Tools.cs

+50-2
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public static void DownloadAndInstall(string url, string version)
576576
string tempFile = Path.GetTempPath() + "UnityDownloadAssistant-" + version.Replace(".", "_") + ".exe";
577577
//Console.WriteLine("download tempFile= (" + tempFile + ")");
578578
if (File.Exists(tempFile) == true) File.Delete(tempFile);
579-
579+
580580
// TODO make async
581581
if (DownloadFile(exeURL, tempFile) == true)
582582
{
@@ -1281,7 +1281,7 @@ public static string[] GetPlatformsForUnityVersion(string version)
12811281
{
12821282
// get platforms array for this unity version
12831283
// TODO use dictionary instead of looping versions
1284-
for (int i = 0; i < MainWindow.unityInstallationsSource.Length; i++)
1284+
for (int i = 0; i < MainWindow.unityInstallationsSource.Count; i++)
12851285
{
12861286
if (MainWindow.unityInstallationsSource[i].Version == version)
12871287
{
@@ -1883,6 +1883,54 @@ public static bool IsLTS(string versionRaw)
18831883
return (versionInt >= 2017 && versionMinor == 4) || (versionInt > 2019 && versionMinor == 3);
18841884
}
18851885

1886+
internal static void UninstallEditor(string path, string version)
1887+
{
1888+
if (string.IsNullOrEmpty(path)) return;
1889+
if (string.IsNullOrEmpty(version)) return;
1890+
1891+
// run uninstaller from path
1892+
var installFolder = Path.GetDirectoryName(path);
1893+
var uninstaller = Path.Combine(installFolder, "Uninstall.exe");
1894+
// TODO could be optional setting for non-silent uninstall
1895+
LaunchExe(uninstaller, "/S");
1896+
// remove firewall settings
1897+
var cmd = "netsh advfirewall firewall delete rule name=all program=\"" + path + "\"";
1898+
Console.WriteLine("Cleanup firewall: " + cmd);
1899+
LaunchExe("cmd.exe", "/c " + cmd);
1900+
1901+
if (int.Parse(version.Substring(0, 4)) <= 2017)
1902+
{
1903+
var nodeFolder = Path.Combine(installFolder, "Editor", "Data", "Tools", "nodejs", "node.exe");
1904+
cmd = "netsh advfirewall firewall delete rule name=all program=\"" + nodeFolder + "\"";
1905+
Console.WriteLine("Cleanup firewall <= 2017: " + cmd);
1906+
LaunchExe("cmd.exe", "/c " + cmd);
1907+
}
1908+
// remove registry entries
1909+
var unityKeyName = "HKEY_CURRENT_USER\\Software\\Unity Technologies\\Installer\\Unity " + version;
1910+
cmd = "reg delete " + unityKeyName + " /f";
1911+
Console.WriteLine("Removing registry key: " + cmd);
1912+
LaunchExe("cmd.exe", "/c " + cmd);
1913+
1914+
// remove startmenu item
1915+
var startMenuFolder = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
1916+
var unityIcon = Path.Combine(startMenuFolder, "Unity " + version + "(64-bit)");
1917+
if (Directory.Exists(unityIcon))
1918+
{
1919+
Console.WriteLine("Removing startmenu folder: " + unityIcon);
1920+
Directory.Delete(unityIcon, true);
1921+
}
1922+
1923+
// remove desktop icon
1924+
var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
1925+
unityIcon = Path.Combine(startMenuFolder, "Unity " + version + ".lnk");
1926+
if (File.Exists(unityIcon))
1927+
{
1928+
Console.WriteLine("Removing desktop icon: " + unityIcon);
1929+
File.Delete(unityIcon);
1930+
}
1931+
1932+
1933+
}
18861934
} // class
18871935

18881936
} // namespace

0 commit comments

Comments
 (0)