Skip to content

Commit 3632167

Browse files
committed
add doubleclick to datagrids (launch project, run unity, open release page), add option to show projects with missing folder, add option for allow single instance only (to not run multiple launchers), update unity button takes you into updates tab with that version selected, #build
1 parent 3659738 commit 3632167

File tree

6 files changed

+135
-11
lines changed

6 files changed

+135
-11
lines changed

Diff for: UnityLauncherPro/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<setting name="showGitBranchColumn" serializeAs="String">
4343
<value>False</value>
4444
</setting>
45+
<setting name="showProjectsMissingFolder" serializeAs="String">
46+
<value>False</value>
47+
</setting>
48+
<setting name="AllowSingleInstanceOnly" serializeAs="String">
49+
<value>False</value>
50+
</setting>
4551
</UnityLauncherPro.Properties.Settings>
4652
</userSettings>
4753
</configuration>

Diff for: UnityLauncherPro/GetProjects.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class GetProjects
1111
// which registries we want to scan for projects
1212
static readonly string[] registryPathsToCheck = new string[] { @"SOFTWARE\Unity Technologies\Unity Editor 5.x", @"SOFTWARE\Unity Technologies\Unity Editor 4.x" };
1313

14-
public static Project[] Scan(bool getGitBranch = false, bool getArguments = false)
14+
public static Project[] Scan(bool getGitBranch = false, bool getArguments = false, bool showMissingFolders = false)
1515
{
1616
List<Project> projectsFound = new List<Project>();
1717

@@ -49,10 +49,8 @@ public static Project[] Scan(bool getGitBranch = false, bool getArguments = fals
4949
projectPath = (string)key.GetValue(valueName);
5050
}
5151

52-
//Console.WriteLine("projectPath=" + projectPath);
53-
5452
// first check if whole folder exists, if not, skip
55-
if (Directory.Exists(projectPath) == false)
53+
if (showMissingFolders == false && Directory.Exists(projectPath) == false)
5654
{
5755
//Console.WriteLine("Recent project directory not found, skipping: " + projectPath);
5856
continue;

Diff for: UnityLauncherPro/MainWindow.xaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
<Button Style="{StaticResource CustomButton}" ToolTip="Add existing project" x:Name="btnAddProjectFolder" Content="Add Project.." Height="22" Width="78" HorizontalAlignment="Right" VerticalAlignment="Top" Background="#FF3F3F46" Foreground="#FFC1C1C1" Margin="0,4,34,0" Click="BtnAddProjectFolder_Click" BorderBrush="{x:Null}" TabIndex="10" />
303303
<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" TabIndex="11"/>
304304

305-
<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" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding">
305+
<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" PreviewKeyDown="GridRecent_PreviewKeyDown" Loaded="GridRecent_Loaded" TabIndex="2" CellEditEnding="GridRecent_CellEditEnding" PreviewMouseDoubleClick="GridRecent_PreviewMouseDoubleClick">
306306
<DataGrid.Columns>
307307
<DataGridTextColumn CellStyle="{StaticResource NoFocusCellStyle}" Binding="{Binding Title}" ClipboardContentBinding="{x:Null}" Header="Project" IsReadOnly="True" Width="150"/>
308308
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" Width="72">
@@ -423,7 +423,7 @@
423423

424424
<Button Style="{StaticResource CustomButton}" ToolTip="Refresh installations (F5)" x:Name="btnRefreshUnityList" 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="BtnRefreshUnityList_Click"/>
425425

426-
<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="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" PreviewKeyDown="DataGridUnitys_PreviewKeyDown">
426+
<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="#FFD8D8D8" HorizontalGridLinesBrush="#4C000000" VerticalGridLinesBrush="#19000000" AutoGenerateColumns="False" PreviewKeyDown="DataGridUnitys_PreviewKeyDown" PreviewMouseDoubleClick="DataGridUnitys_PreviewMouseDoubleClick">
427427

428428
<DataGrid.Columns>
429429
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="123"/>
@@ -501,7 +501,7 @@
501501

502502
<Button Style="{StaticResource CustomButton}" ToolTip="Fetch released versions" x:Name="btnRefreshUpdatesList" 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="OnGetUnityUpdatesClick"/>
503503

504-
<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" PreviewKeyDown="DataGridUpdates_PreviewKeyDown">
504+
<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" PreviewKeyDown="DataGridUpdates_PreviewKeyDown" PreviewMouseDoubleClick="DataGridUpdates_PreviewMouseDoubleClick">
505505

506506
<DataGrid.Columns>
507507
<DataGridTextColumn Binding="{Binding ReleaseDate, StringFormat=\{0:dd/MM/yyyy\}}" ClipboardContentBinding="{x:Null}" MinWidth="100" Header="ReleaseDate" IsReadOnly="True"/>
@@ -620,6 +620,8 @@
620620
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" Margin="0,0,0,3" ToolTip="Close launcher after running form commandline or Explorer (recommended to be enabed)"/>
621621
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show commandline arguments Column" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" Margin="0,0,0,3"/>
622622
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show Git Branch Column" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,3"/>
623+
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that dont exist on disk" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" Margin="0,0,0,3" ToolTip="List recent projects, even if the project folder is missing"/>
624+
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,3" ToolTip="Activates already running instance, instead of starting new exe"/>
623625
</StackPanel>
624626

625627
<!-- links-->

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+92-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
using System.Diagnostics;
88
using System.Drawing; // for notifyicon
99
using System.IO;
10+
using System.Runtime.InteropServices;
11+
using System.Threading;
1012
using System.Windows;
1113
using System.Windows.Controls;
1214
using System.Windows.Data;
@@ -18,6 +20,16 @@ namespace UnityLauncherPro
1820
public partial class MainWindow : Window
1921
{
2022
private System.Windows.Forms.NotifyIcon notifyIcon;
23+
const string appName = "UnityLauncherPro";
24+
25+
[DllImport("user32", CharSet = CharSet.Unicode)]
26+
static extern IntPtr FindWindow(string cls, string win);
27+
[DllImport("user32")]
28+
static extern IntPtr SetForegroundWindow(IntPtr hWnd);
29+
[DllImport("user32")]
30+
static extern bool IsIconic(IntPtr hWnd);
31+
[DllImport("user32")]
32+
static extern bool OpenIcon(IntPtr hWnd);
2133

2234
Project[] projectsSource;
2335
Updates[] updatesSource;
@@ -28,6 +40,8 @@ public partial class MainWindow : Window
2840
string _filterString = null;
2941
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
3042

43+
Mutex myMutex;
44+
3145
public MainWindow()
3246
{
3347
InitializeComponent();
@@ -53,8 +67,20 @@ void Start()
5367

5468
HandleCommandLineLaunch();
5569

70+
// check for duplicate instance, and activate that instead
71+
if (chkAllowSingleInstanceOnly.IsChecked == true)
72+
{
73+
bool aIsNewInstance = false;
74+
myMutex = new Mutex(true, appName, out aIsNewInstance);
75+
if (!aIsNewInstance)
76+
{
77+
ActivateOtherWindow();
78+
App.Current.Shutdown();
79+
}
80+
}
81+
5682
// update projects list
57-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
83+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked);
5884
gridRecent.Items.Clear();
5985
gridRecent.ItemsSource = projectsSource;
6086

@@ -67,6 +93,18 @@ void Start()
6793
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
6894
}
6995

96+
// bring old window to front, but needs matching appname.. https://stackoverflow.com/a/36804161/5452781
97+
private static void ActivateOtherWindow()
98+
{
99+
var other = FindWindow(null, appName);
100+
if (other != IntPtr.Zero)
101+
{
102+
SetForegroundWindow(other);
103+
if (IsIconic(other))
104+
OpenIcon(other);
105+
}
106+
}
107+
70108
void HandleCommandLineLaunch()
71109
{
72110
// check if received -projectPath argument (that means opening from explorer / cmdline)
@@ -197,6 +235,8 @@ void LoadSettings()
197235
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
198236
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
199237
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
238+
chkShowMissingFolderProjects.IsChecked = Properties.Settings.Default.showProjectsMissingFolder;
239+
chkAllowSingleInstanceOnly.IsChecked = Properties.Settings.Default.AllowSingleInstanceOnly;
200240

201241
// update optional grid columns, hidden or visible
202242
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -445,7 +485,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
445485
switch (e.Key)
446486
{
447487
case Key.F5: // refresh projects
448-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
488+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked);
449489
gridRecent.ItemsSource = projectsSource;
450490
break;
451491
case Key.Escape: // clear project search
@@ -589,7 +629,7 @@ private void MenuItemCopyVersion_Click(object sender, RoutedEventArgs e)
589629

590630
private void BtnRefreshProjectList_Click(object sender, RoutedEventArgs e)
591631
{
592-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
632+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked);
593633
gridRecent.ItemsSource = projectsSource;
594634
}
595635

@@ -639,7 +679,25 @@ private void BtnReleaseNotes_Click(object sender, RoutedEventArgs e)
639679

640680
private void BtnUpdateUnity_Click(object sender, RoutedEventArgs e)
641681
{
642-
// TODO check for newer available version in Updates tab, select that row and jump to tab
682+
var unity = GetSelectedUnity();
683+
if (unity == null) return;
684+
// NOTE for now, just select the same version.. then user can see what has been released after this
685+
// NOTE if updates are not loaded, should wait for that
686+
if (dataGridUpdates.ItemsSource != null)
687+
{
688+
tabControl.SelectedIndex = 2;
689+
// find matching version
690+
for (int i = 0; i < dataGridUpdates.Items.Count; i++)
691+
{
692+
Updates row = (Updates)dataGridUpdates.Items[i];
693+
if (row.Version == unity.Version)
694+
{
695+
dataGridUpdates.SelectedIndex = i;
696+
dataGridUpdates.ScrollIntoView(row);
697+
break;
698+
}
699+
}
700+
}
643701
}
644702

645703
// if press up/down in search box, move to first item in results
@@ -987,5 +1045,35 @@ private void TxtSearchBoxUnity_TextChanged(object sender, TextChangedEventArgs e
9871045
{
9881046
FilterUnitys();
9891047
}
1048+
1049+
private void GridRecent_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
1050+
{
1051+
Tools.LaunchProject(GetSelectedProject());
1052+
}
1053+
1054+
private void DataGridUnitys_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
1055+
{
1056+
var unity = GetSelectedUnity();
1057+
var unitypath = Tools.GetUnityExePath(unity?.Version);
1058+
Tools.LaunchExe(unitypath);
1059+
}
1060+
1061+
private void DataGridUpdates_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
1062+
{
1063+
var unity = GetSelectedUpdate();
1064+
Tools.OpenReleaseNotes(unity?.Version);
1065+
}
1066+
1067+
private void ChkShowMissingFolderProjects_CheckedChanged(object sender, RoutedEventArgs e)
1068+
{
1069+
Properties.Settings.Default.showProjectsMissingFolder = (bool)chkShowMissingFolderProjects.IsChecked;
1070+
Properties.Settings.Default.Save();
1071+
}
1072+
1073+
private void ChkAllowSingleInstanceOnly_CheckedChanged(object sender, RoutedEventArgs e)
1074+
{
1075+
Properties.Settings.Default.AllowSingleInstanceOnly = (bool)chkAllowSingleInstanceOnly.IsChecked;
1076+
Properties.Settings.Default.Save();
1077+
}
9901078
} // class
9911079
} //namespace

Diff for: UnityLauncherPro/Properties/Settings.Designer.cs

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: UnityLauncherPro/Properties/Settings.settings

+6
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@
3535
<Setting Name="gridColumnWidths" Type="System.Int32[]" Scope="User">
3636
<Value Profile="(Default)" />
3737
</Setting>
38+
<Setting Name="showProjectsMissingFolder" Type="System.Boolean" Scope="User">
39+
<Value Profile="(Default)">False</Value>
40+
</Setting>
41+
<Setting Name="AllowSingleInstanceOnly" Type="System.Boolean" Scope="User">
42+
<Value Profile="(Default)">False</Value>
43+
</Setting>
3844
</Settings>
3945
</SettingsFile>

0 commit comments

Comments
 (0)