Skip to content

Commit e62edb8

Browse files
committed
add dictionary to quickly access installed unity version, set project version text color based on availability (red/green)
1 parent 94ae764 commit e62edb8

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
using System;
2+
using System.Drawing;
3+
using System.Windows;
4+
using System.Windows.Data;
25

36
namespace UnityLauncherPro
47
{
5-
public class UnityInstallation
8+
public class UnityInstallation : IValueConverter
69
{
710
public string Version { set; get; }
811
public string Path { set; get; }
912
public DateTime? Installed { set; get; }
1013
//public string Platforms { set; get; }
14+
15+
// color project unity version cells, depending if have that version installed
16+
// https://stackoverflow.com/a/5551986/5452781
17+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
18+
{
19+
string version = value as string;
20+
//return MainWindow.unityInstalledVersions.ContainsKey(version) ? Brushes.Yellow : Brushes.Red;
21+
return MainWindow.unityInstalledVersions.ContainsKey(version);// ? "Red" : "Blue";
22+
//return Brushes.Yellow;
23+
// DependencyProperty.UnsetValue
24+
}
25+
26+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
27+
{
28+
throw new NotSupportedException();
29+
}
30+
1131
}
1232
}

UnityLauncherPro/MainWindow.xaml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
<Window.Resources>
1111

12+
<!-- colors for unity missing installatios -->
13+
<local:UnityInstallation x:Key="MyConverter"/>
1214

1315
<!-- tabs -->
1416
<Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}">
@@ -290,10 +292,20 @@
290292
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh list (F5)" x:Name="btnRefreshProjectList" Content="" Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,3,0" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="BtnRefreshProjectList_Click"/>
291293

292294
<DataGrid x:Name="gridRecent" 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">
293-
294295
<DataGrid.Columns>
295296
<DataGridTextColumn Binding="{Binding Title}" ClipboardContentBinding="{x:Null}" Header="Project" IsReadOnly="True" Width="150"/>
296-
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" Width="72"/>
297+
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" Width="72">
298+
<DataGridTextColumn.CellStyle>
299+
<Style TargetType="{x:Type DataGridCell}">
300+
<Setter Property="Foreground" Value="#FFF54F4F" />
301+
<Style.Triggers>
302+
<DataTrigger Binding="{Binding Version, Converter={StaticResource MyConverter}}" Value="true">
303+
<Setter Property="Foreground" Value="#FF00C500" />
304+
</DataTrigger>
305+
</Style.Triggers>
306+
</Style>
307+
</DataGridTextColumn.CellStyle>
308+
</DataGridTextColumn>
297309
<DataGridTextColumn Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" Header="Path" IsReadOnly="True" Width="185"/>
298310
<DataGridTextColumn Binding="{Binding Modified, StringFormat=\{0:dd/MM/yyyy HH:mm:ss\}}" ClipboardContentBinding="{x:Null}" Header="Modified" IsReadOnly="True" Width="120"/>
299311
<DataGridTextColumn Binding="{Binding Arguments}" ClipboardContentBinding="{x:Null}" Header="Arguments" IsReadOnly="True" Width="100"/>
@@ -311,28 +323,28 @@
311323

312324
<!-- sample data for testing -->
313325
<local:Project GITBranch="" Modified="" Title="M dfgh dfghMO" Path="A:/temp" Version="2099.1.2.3"/>
314-
<local:Project GITBranch="" Modified="" Title="asdgdfg" Path="A:/temp" Version="2099.1.2.3"/>
315-
<local:Project GITBranch="" Modified="" Title="Mghdfghdf dfghdfgMO" Path="A:/temp" Version="2099.1.2.3"/>
326+
<local:Project GITBranch="" Modified="" Title="asdgdfg" Path="A:/temp" Version="5.6.7f1"/>
327+
<local:Project GITBranch="" Modified="" Title="Mghdfghdf dfghdfgMO" Path="A:/temp" Version="2018.3.13f1"/>
316328
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
317-
<local:Project GITBranch="" Modified="" Title="fghdhdfgh" Path="A:/temp" Version="2099.1.2.3"/>
329+
<local:Project GITBranch="" Modified="" Title="fghdhdfgh" Path="A:/temp" Version="2018.3.13f1"/>
318330
<local:Project GITBranch="" Modified="" Title="MdfMO" Path="A:/temp" Version="2099.1.2.3"/>
319331
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
320332
<local:Project GITBranch="" Modified="" Title="MdfgMO" Path="A:/temp" Version="2099.1.2.3"/>
321333
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
322334
<local:Project GITBranch="" Modified="" Title="MdfghMO" Path="A:/temp" Version="2099.1.2.3"/>
323335
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
324-
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
336+
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="5.6.7f1"/>
325337
<local:Project GITBranch="" Modified="" Title="ddfghfghdfgh" Path="A:/temp" Version="2099.1.2.3"/>
326338
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
327-
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
339+
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2018.3.13f1"/>
328340
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
329341
<local:Project GITBranch="" Modified="" Title="MMdfghO" Path="A:/temp" Version="2099.1.2.3"/>
330342
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
331343
<local:Project GITBranch="" Modified="" Title="MdfghMO" Path="A:/temp" Version="2099.1.2.3"/>
332344
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
333345
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
334-
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="2099.1.2.3"/>
335-
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
346+
<local:Project GITBranch="" Modified="" Title="dfgh" Path="A:/temp" Version="5.6.7f1"/>
347+
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2018.3.13f1"/>
336348
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
337349
<local:Project GITBranch="" Modified="" Title="MMO" Path="A:/temp" Version="2099.1.2.3"/>
338350
<local:Project GITBranch="" Modified="" Title="Mdfg hMO" Path="A:/temp" Version="2099.1.2.3"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel;
34
using System.Diagnostics;
45
using System.Drawing; // for notifyicon
@@ -13,18 +14,19 @@ namespace UnityLauncherPro
1314
{
1415
public partial class MainWindow : Window
1516
{
16-
1717
private System.Windows.Forms.NotifyIcon notifyIcon;
1818

1919
Project[] projectsSource;
2020
Updates[] updatesSource;
2121
UnityInstallation[] unityInstallationsSource;
22+
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>();
2223

2324
string _filterString = null;
2425

2526
public MainWindow()
2627
{
2728
InitializeComponent();
29+
//this.DataContext = this;
2830
Start();
2931
}
3032

@@ -45,6 +47,17 @@ void Start()
4547
unityInstallationsSource = GetUnityInstallations.Scan(tempRootFolders);
4648
dataGridUnitys.Items.Clear();
4749
dataGridUnitys.ItemsSource = unityInstallationsSource;
50+
// make dictionary of installed unitys, to search faster
51+
unityInstalledVersions.Clear();
52+
for (int i = 0; i < unityInstallationsSource.Length; i++)
53+
{
54+
var version = unityInstallationsSource[i].Version;
55+
if (unityInstalledVersions.ContainsKey(version) == false)
56+
{
57+
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
58+
}
59+
}
60+
4861

4962
//dataGrid.Items.Add(GetProjects.Scan());
5063
projectsSource = GetProjects.Scan();
@@ -429,11 +442,7 @@ void LaunchProject(Project proj)
429442

430443
string GetSelectedUnityExePath(string version)
431444
{
432-
for (int i = 0, len = unityInstallationsSource.Length; i < len; i++)
433-
{
434-
if (version == unityInstallationsSource[i].Version) return unityInstallationsSource[i].Path;
435-
}
436-
return null;
445+
return unityInstalledVersions.ContainsKey(version) ? unityInstalledVersions[version] : null;
437446
}
438447

439448

@@ -473,5 +482,10 @@ private void BtnRefreshProjectList_Click(object sender, RoutedEventArgs e)
473482
projectsSource = GetProjects.Scan();
474483
gridRecent.ItemsSource = projectsSource;
475484
}
485+
486+
487+
476488
} // class
477-
} //namespace
489+
} //namespace
490+
491+

0 commit comments

Comments
 (0)