Skip to content

Commit 2f8ddc8

Browse files
committed
get list of unity installations, sort installed unity versions by version, show short date for unity updates, esc key to clear search, any key to start typing into search
1 parent 1119c4b commit 2f8ddc8

File tree

8 files changed

+151
-25
lines changed

8 files changed

+151
-25
lines changed
File renamed without changes.

UnityLauncherPro/UnityInstallations.cs renamed to UnityLauncherPro/Data/UnityInstallation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace UnityLauncherPro
44
{
5-
public class UnityInstallations
5+
public class UnityInstallation
66
{
77
public string Version { set; get; }
88
public string Path { set; get; }
9-
public DateTime Installed { set; get; }
10-
public string Platforms { set; get; }
9+
public DateTime? Installed { set; get; }
10+
//public string Platforms { set; get; }
1111
}
1212
}
File renamed without changes.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text.RegularExpressions;
5+
6+
namespace UnityLauncherPro
7+
{
8+
/// <summary>
9+
/// returns unity installations under given root folders
10+
/// </summary>
11+
public static class GetUnityInstallations
12+
{
13+
public static UnityInstallation[] Scan(string[] rootFolders)
14+
{
15+
// unityversion, exe_path
16+
//Dictionary<string, UnityInstallation> results = new ictionary<string, UnityInstallation>();
17+
List<UnityInstallation> results = new List<UnityInstallation>();
18+
19+
// iterate all root folders
20+
foreach (string rootFolder in rootFolders)
21+
{
22+
// if folder exists
23+
if (String.IsNullOrWhiteSpace(rootFolder) == true || Directory.Exists(rootFolder) == false) continue;
24+
25+
// get all folders
26+
var directories = Directory.GetDirectories(rootFolder);
27+
// parse all folders under root, and search for unity editor files
28+
for (int i = 0, length = directories.Length; i < length; i++)
29+
{
30+
// check if uninstaller is there, sure sign for unity
31+
var uninstallExe = Path.Combine(directories[i], "Editor", "Uninstall.exe");
32+
var haveUninstaller = File.Exists(uninstallExe);
33+
34+
var exePath = Path.Combine(directories[i], "Editor", "Unity.exe");
35+
if (File.Exists(exePath) == false) continue;
36+
37+
// get full version number from uninstaller (or try exe, if no uninstaller)
38+
var version = Tools.GetFileVersionData(haveUninstaller ? uninstallExe : exePath);
39+
40+
// we got new version to add
41+
var dataFolder = Path.Combine(directories[i], "Editor", "Data");
42+
DateTime? installDate = Tools.GetLastModifiedTime(dataFolder);
43+
UnityInstallation unity = new UnityInstallation();
44+
unity.Version = version;
45+
unity.Path = exePath;
46+
unity.Installed = installDate;
47+
48+
// add to dictionary, if not there yet NOTE should notify that there are 2 same versions..? this might happen with preview builds..
49+
if (results.Contains(unity) == true)
50+
{
51+
Console.WriteLine("Warning: 2 same versions found for " + version);
52+
continue;
53+
}
54+
55+
results.Add(unity);
56+
57+
} // got folders
58+
} // all root folders
59+
60+
// sort by unity version NOTE we might want to sort by install date also..
61+
results.Sort((s1, s2) => VersionAsFloat(s2.Version).CompareTo(VersionAsFloat(s1.Version)));
62+
63+
return results.ToArray();
64+
} // scan()
65+
66+
// string to float 2017.4.1f1 > 2017.411
67+
static float VersionAsFloat(string version)
68+
{
69+
float result = 0;
70+
if (string.IsNullOrEmpty(version)) return result;
71+
72+
// remove a,b,f,p
73+
string cleanVersion = version.Replace("a", ".");
74+
cleanVersion = cleanVersion.Replace("b", ".");
75+
cleanVersion = cleanVersion.Replace("f", ".");
76+
cleanVersion = cleanVersion.Replace("p", ".");
77+
78+
// split values
79+
string[] splitted = cleanVersion.Split('.');
80+
if (splitted != null && splitted.Length > 0)
81+
{
82+
// get float
83+
float multiplier = 1;
84+
for (int i = 0, length = splitted.Length; i < length; i++)
85+
{
86+
int n = int.Parse(splitted[i]);
87+
result += n * multiplier;
88+
multiplier /= 10;
89+
}
90+
}
91+
return result;
92+
}
93+
94+
} // class
95+
} // namespace

UnityLauncherPro/MainWindow.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:UnityLauncherPro"
77
mc:Ignorable="d"
8-
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" >
8+
Title="UnityLauncherPro" Height="650" Width="600" WindowStartupLocation="CenterScreen" Background="{DynamicResource DarkestBackground}" MinWidth="600" MinHeight="650" AllowsTransparency="True" WindowStyle="None" Margin="0" KeyDown="OnWindowKeyDown" >
99

1010
<Window.Resources>
1111
<!-- tabs -->
@@ -251,7 +251,7 @@
251251
<!-- search box -->
252252
<Grid Background="{DynamicResource TextBoxBackground}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Margin="6,5,0,0" Height="20" >
253253
<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="#7F919191" Visibility="{Binding ElementName=txtSearchBox, Path=Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}}" Height="24" />
254-
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" Name="txtSearchBox" Background="Transparent" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" />
254+
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" Name="txtSearchBox" Background="Transparent" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="2,2,0,0" UndoLimit="64" TextChanged="OnSearchTextChanged" />
255255
<Button Name="btnClearSearch" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" BorderThickness="0" HorizontalAlignment="Right" VerticalAlignment="Top" Height="23" Width="23" Background="Transparent" Padding="0,2" Visibility="Visible" BorderBrush="{x:Null}">
256256
<TextBlock Text="" FontSize="8" Foreground="{DynamicResource ButtonForeground}" Padding="5,3,4,4" HorizontalAlignment="Center">
257257
<TextBlock.Style>
@@ -416,7 +416,7 @@
416416
</DataGrid.ContextMenu>
417417

418418
<!-- sample data for testing -->
419-
<local:UnityInstallations Version="3000.1.2f1" Path="c:/proggies/unity3000" Installed="12.12.2020" />
419+
<local:UnityInstallation Version="3000.1.2f1" Path="c:/proggies/unity3000" Installed="12.12.2020" />
420420
</DataGrid>
421421

422422
<!-- bottom buttoms row -->
@@ -474,7 +474,7 @@
474474
<DataGrid x:Name="dataGridUpdates" SelectionMode="Single" Margin="4,30,2,42" Background="{x:Null}" BorderBrush="{x:Null}" ColumnHeaderStyle="{StaticResource HeaderStyle}" Padding="0" HorizontalScrollBarVisibility="Disabled" HeadersVisibility="Column" Foreground="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False">
475475

476476
<DataGrid.Columns>
477-
<DataGridTextColumn Binding="{Binding ReleaseDate,StringFormat=\{0:dd/MM/yyyy HH:mm:ss\}}" ClipboardContentBinding="{x:Null}" Header="ReleaseDate" IsReadOnly="True"/>
477+
<DataGridTextColumn Binding="{Binding ReleaseDate,StringFormat=\{0:dd/MM/yyyy\}}" ClipboardContentBinding="{x:Null}" Header="ReleaseDate" IsReadOnly="True"/>
478478
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123"/>
479479
</DataGrid.Columns>
480480

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public partial class MainWindow : Window
1919

2020
Project[] projectsSource;
2121
Updates[] updatesSource;
22+
UnityInstallation[] unityInstallationsSource;
2223

2324
public MainWindow()
2425
{
@@ -35,22 +36,16 @@ void Start()
3536
Resizable_BorderLess_Chrome.CaptionHeight = 1.0;
3637
WindowChrome.SetWindowChrome(this, Resizable_BorderLess_Chrome);
3738

38-
// add test data
39-
dataGrid.Items.Clear();
40-
/*
41-
for (int i = 0; i < 6; i++)
42-
{
43-
dataGrid.Items.Add(new Project { Title = "asdf" + i, Version = "5000", Path = "A:/", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
44-
dataGrid.Items.Add(new Project { Title = "asdf asd", Version = "2", Path = "C:/", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
45-
dataGrid.Items.Add(new Project { Title = "kuykkyu" + i * 2, Version = "23.23.23", Path = "8,1", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
46-
dataGrid.Items.Add(new Project { Title = "RT435y", Version = "3333", Path = "X:/", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
47-
dataGrid.Items.Add(new Project { Title = "asdf", Version = "5000", Path = "A:/", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
48-
dataGrid.Items.Add(new Project { Title = "asdf asd" + i * 3, Version = "2", Path = "C:/", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
49-
dataGrid.Items.Add(new Project { Title = "kuykkyu", Version = "23.23.23", Path = "8,1", Modified = DateTime.Now, Arguments = "", GITBranch = "-" });
50-
}*/
39+
40+
// get unity installations
41+
var tempRootFolders = new string[] { "D:/Program Files/" };
42+
unityInstallationsSource = GetUnityInstallations.Scan(tempRootFolders);
43+
dataGridUnitys.Items.Clear();
44+
dataGridUnitys.ItemsSource = unityInstallationsSource;
5145

5246
//dataGrid.Items.Add(GetProjects.Scan());
5347
projectsSource = GetProjects.Scan();
48+
dataGrid.Items.Clear();
5449
dataGrid.ItemsSource = projectsSource;
5550

5651
// updates grid
@@ -62,7 +57,6 @@ void Start()
6257
notifyIcon.Icon = new Icon(System.Windows.Application.GetResourceStream(new Uri("pack://application:,,,/Images/icon.ico")).Stream);
6358
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
6459

65-
6660
}
6761

6862
void NotifyIcon_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
@@ -171,7 +165,36 @@ private async void OnGetUnityUpdatesClick(object sender, RoutedEventArgs e)
171165
button.IsEnabled = true;
172166
}
173167

168+
private void OnWindowKeyDown(object sender, KeyEventArgs e)
169+
{
170+
// TODO if editing cells, dont focus on search
171+
//if (gridRecent.IsCurrentCellInEditMode == true) return;
174172

175-
173+
switch (e.Key)
174+
{
175+
case Key.Escape: // clear project search
176+
if (tabControl.SelectedIndex == 0 && txtSearchBox.Text != "")
177+
{
178+
txtSearchBox.Text = "";
179+
}
180+
// clear updates search
181+
else if (tabControl.SelectedIndex == 2 && txtSearchBoxUpdates.Text != "")
182+
{
183+
txtSearchBoxUpdates.Text = "";
184+
}
185+
break;
186+
default: // any key
187+
// activate searchbar if not active and we are in tab#1
188+
if (tabControl.SelectedIndex == 0 && txtSearchBox.IsFocused == false)
189+
{
190+
// dont write tab key on search field
191+
if (e.Key == Key.Tab) break;
192+
txtSearchBox.Focus();
193+
txtSearchBox.Text += e.Key;
194+
txtSearchBox.Select(txtSearchBox.Text.Length, 0);
195+
}
196+
break;
197+
}
198+
}
176199
}
177200
}

UnityLauncherPro/Tools.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.Text;
45

@@ -102,6 +103,12 @@ public static string GetProjectVersion(string path)
102103
return version;
103104
}
104105

106+
// returns unity version number string from file
107+
public static string GetFileVersionData(string path)
108+
{
109+
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(path);
110+
return fvi.ProductName.Replace("(64-bit)", "").Replace("Unity", "").Trim();
111+
}
105112

106113
} // class
107114
} // namespace

UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@
7676
<SubType>Designer</SubType>
7777
</ApplicationDefinition>
7878
<Compile Include="GetProjects.cs" />
79+
<Compile Include="GetUnityInstallations.cs" />
7980
<Compile Include="GetUnityUpdates.cs" />
8081
<Compile Include="Tools.cs" />
81-
<Compile Include="UnityInstallations.cs" />
82-
<Compile Include="Updates.cs" />
82+
<Compile Include="Data\UnityInstallation.cs" />
83+
<Compile Include="Data\Updates.cs" />
8384
<Page Include="Resources\Colors.xaml">
8485
<SubType>Designer</SubType>
8586
<Generator>MSBuild:Compile</Generator>
@@ -98,7 +99,7 @@
9899
</Compile>
99100
</ItemGroup>
100101
<ItemGroup>
101-
<Compile Include="Project.cs" />
102+
<Compile Include="Data\Project.cs" />
102103
<Compile Include="Properties\AssemblyInfo.cs">
103104
<SubType>Code</SubType>
104105
</Compile>

0 commit comments

Comments
 (0)