Skip to content

Commit 5dbd8ed

Browse files
committed
add close after launch or after explorer launch, add show gitbranch and launcher arguments code, add commandline launching, cleanup newlines from custom arguments and gitbranch data, fix upgradedialog appearing from commandline while shift is pressed,
1 parent 939850c commit 5dbd8ed

File tree

9 files changed

+208
-34
lines changed

9 files changed

+208
-34
lines changed

UnityLauncherPro/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
<setting name="showGitBranchColumn" serializeAs="String">
4343
<value>False</value>
4444
</setting>
45-
<setting name="gridColumnWidths" serializeAs="String">
46-
<value>123</value>
45+
<setting name="showFullModifiedTime" serializeAs="String">
46+
<value>False</value>
4747
</setting>
4848
</UnityLauncherPro.Properties.Settings>
4949
</userSettings>

UnityLauncherPro/GetProjects.cs

Lines changed: 7 additions & 9 deletions
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()
14+
public static Project[] Scan(bool getGitBranch = false, bool getArguments = false)
1515
{
1616
List<Project> projectsFound = new List<Project>();
1717

@@ -101,29 +101,27 @@ public static Project[] Scan()
101101
// get project version
102102
string projectVersion = Tools.GetProjectVersion(projectPath);
103103

104-
/*
105-
// TODO
106104
// get custom launch arguments, only if column in enabled
107105
string customArgs = "";
108-
if (chkShowLauncherArgumentsColumn.Checked == true)
106+
if (getArguments == true)
109107
{
110-
customArgs = Tools.ReadCustomLaunchArguments(projectPath, launcherArgumentsFile);
108+
customArgs = Tools.ReadCustomLaunchArguments(projectPath, MainWindow.launcherArgumentsFile);
111109
}
110+
112111
// get git branchinfo, only if column in enabled
113112
string gitBranch = "";
114-
if (chkShowGitBranchColumn.Checked == true)
113+
if (getGitBranch == true)
115114
{
116115
gitBranch = Tools.ReadGitBranchInfo(projectPath);
117116
}
118-
*/
119117

120118
var p = new Project();
121119
p.Title = projectName;
122120
p.Version = projectVersion;
123121
p.Path = projectPath;
124122
p.Modified = lastUpdated;
125-
//p.Arguments = customArgs;
126-
//p.GITBranch = gitBranch;
123+
p.Arguments = customArgs;
124+
p.GITBranch = gitBranch;
127125

128126
projectsFound.Add(p);
129127
} // valid key

UnityLauncherPro/MainWindow.xaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@
227227
</Window.Resources>
228228

229229

230-
231-
232230
<!-- UI -->
233231

234232
<Grid Margin="0">
@@ -596,13 +594,13 @@
596594
</StackPanel>
597595
<!-- settings-->
598596
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
599-
<CheckBox x:Name="chkMinimizeToTaskbar" Content="Minimize to taskbar" Foreground="{DynamicResource ButtonForeground}" Checked="ChkMinimizeToTaskbar_CheckedChanged" Unchecked="ChkMinimizeToTaskbar_CheckedChanged"/>
600-
<CheckBox x:Name="chkRegisterExplorerMenu" Content="Register Explorer context menu" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkRegisterExplorerMenu_CheckedChanged" Checked="ChkRegisterExplorerMenu_CheckedChanged"/>
601-
<CheckBox Content="Close after opening project" Foreground="{DynamicResource ButtonForeground}"/>
602-
<CheckBox Content="Close after launching from Explorer" Foreground="{DynamicResource ButtonForeground}"/>
603-
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show Arguments Column" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged"/>
604-
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show Git Branch Column" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged"/>
605-
<CheckBox Content="Show full modified time" Foreground="{DynamicResource ButtonForeground}" ToolTip="Full=dd/mm/yyyy hh:mm:ss, NotFull=x hours ago, x days ago.."/>
597+
<CheckBox x:Name="chkMinimizeToTaskbar" Content="Minimize to taskbar" Foreground="{DynamicResource ButtonForeground}" Checked="ChkMinimizeToTaskbar_CheckedChanged" Unchecked="ChkMinimizeToTaskbar_CheckedChanged" Margin="0,0,0,3"/>
598+
<CheckBox x:Name="chkRegisterExplorerMenu" Content="Register Explorer context menu" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkRegisterExplorerMenu_CheckedChanged" Checked="ChkRegisterExplorerMenu_CheckedChanged" Margin="0,0,0,3"/>
599+
<CheckBox x:Name="chkQuitAfterOpen" Content="Close after opening project" Foreground="{DynamicResource ButtonForeground}" Checked="ChkQuitAfterOpen_CheckedChanged" Unchecked="ChkQuitAfterOpen_CheckedChanged" Margin="0,0,0,3"/>
600+
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" Margin="0,0,0,3"/>
601+
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show Arguments Column" Foreground="{DynamicResource ButtonForeground}" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" Margin="0,0,0,3"/>
602+
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show Git Branch Column" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,3"/>
603+
<CheckBox x:Name="chkShowFullTime" Content="Show full modified time" Foreground="{DynamicResource ButtonForeground}" ToolTip="Full=dd/mm/yyyy hh:mm:ss, NotFull=x hours ago, x days ago.." Margin="0,0,0,3" Checked="ChkShowFullTime_CheckedChanged" Unchecked="ChkShowFullTime_CheckedChanged"/>
606604
</StackPanel>
607605

608606
<!-- links-->

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public partial class MainWindow : Window
2121
UnityInstallation[] unityInstallationsSource;
2222
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>();
2323
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
24+
public static readonly string launcherArgumentsFile = "LauncherArguments.txt";
2425
string _filterString = null;
2526

2627
public MainWindow()
@@ -29,8 +30,6 @@ public MainWindow()
2930
Start();
3031
}
3132

32-
33-
3433
void Start()
3534
{
3635
LoadSettings();
@@ -42,12 +41,14 @@ void Start()
4241
Resizable_BorderLess_Chrome.CaptionHeight = 1.0;
4342
WindowChrome.SetWindowChrome(this, Resizable_BorderLess_Chrome);
4443

45-
4644
// get unity installations
4745
dataGridUnitys.Items.Clear();
4846
UpdateUnityInstallationsList();
4947

50-
projectsSource = GetProjects.Scan();
48+
HandleCommandLineLaunch();
49+
50+
// update projects list
51+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
5152
gridRecent.Items.Clear();
5253
gridRecent.ItemsSource = projectsSource;
5354

@@ -60,6 +61,79 @@ void Start()
6061
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(NotifyIcon_MouseClick);
6162
}
6263

64+
void HandleCommandLineLaunch()
65+
{
66+
// check if received -projectPath argument (that means opening from explorer / cmdline)
67+
string[] args = Environment.GetCommandLineArgs();
68+
if (args != null && args.Length > 2)
69+
{
70+
// first argument needs to be -projectPath
71+
var commandLineArgs = args[1];
72+
if (commandLineArgs == "-projectPath")
73+
{
74+
Console.WriteLine("Launching from commandline ...");
75+
76+
// path
77+
var projectPathArgument = args[2];
78+
79+
// resolve full path if path parameter isn't a rooted path
80+
if (!Path.IsPathRooted(projectPathArgument))
81+
{
82+
projectPathArgument = Directory.GetCurrentDirectory() + projectPathArgument;
83+
}
84+
85+
var version = Tools.GetProjectVersion(projectPathArgument);
86+
87+
// take extra arguments also
88+
var commandLineArguments = "";
89+
for (int i = 3, len = args.Length; i < len; i++)
90+
{
91+
commandLineArguments += " " + args[i];
92+
}
93+
94+
95+
var proj = new Project();
96+
proj.Version = version;
97+
proj.Path = projectPathArgument;
98+
proj.Arguments = commandLineArguments;
99+
100+
// check if force-update button is down
101+
// NOTE if keydown, window doesnt become active and focused
102+
if ((Keyboard.Modifiers & ModifierKeys.Shift) != 0)
103+
{
104+
//DisplayUpgradeDialog(version, projectPathArgument, launchProject: true, commandLineArguments: commandLineArguments);
105+
//MessageBox.Show("Do you want to Save?", "3", MessageBoxButton.YesNo, MessageBoxImage.Question);
106+
//this.ShowActivated = false;
107+
//Hide();'
108+
//Show();
109+
//Height = 10;
110+
//Width = 10;
111+
//Topmost = true;
112+
Tools.DisplayUpgradeDialog(proj, null);
113+
}
114+
else
115+
{
116+
//MessageBox.Show("Do you want to Save?", "2", MessageBoxButton.YesNo, MessageBoxImage.Question);
117+
// try launching it
118+
//LaunchProject(projectPathArgument, version, openProject: true, commandLineArguments: commandLineArguments);
119+
Tools.LaunchProject(proj);
120+
}
121+
122+
// quit after launch if enabled in settings
123+
if (Properties.Settings.Default.closeAfterExplorer == true)
124+
{
125+
//MessageBox.Show("Do you want to Save?", "quit", MessageBoxButton.YesNo, MessageBoxImage.Question);
126+
//Environment.Exit(0);
127+
}
128+
//SetStatus("Ready");
129+
}
130+
else
131+
{
132+
Console.WriteLine("Error> Invalid arguments:" + args[1]);
133+
}
134+
}
135+
}
136+
63137
// main search
64138
void FilterRecentProjects()
65139
{
@@ -90,14 +164,12 @@ void LoadSettings()
90164
chkMinimizeToTaskbar.IsChecked = Properties.Settings.Default.minimizeToTaskbar;
91165
chkRegisterExplorerMenu.IsChecked = Properties.Settings.Default.registerExplorerMenu;
92166

93-
/*
94167
// update settings window
95-
chkQuitAfterCommandline.Checked = Properties.Settings.Default.closeAfterExplorer;
96-
ChkQuitAfterOpen.Checked = Properties.Settings.Default.closeAfterProject;
97-
*/
98-
168+
chkQuitAfterCommandline.IsChecked = Properties.Settings.Default.closeAfterExplorer;
169+
chkQuitAfterOpen.IsChecked = Properties.Settings.Default.closeAfterProject;
99170
chkShowLauncherArgumentsColumn.IsChecked = Properties.Settings.Default.showArgumentsColumn;
100171
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
172+
chkShowFullTime.IsChecked = Properties.Settings.Default.showFullModifiedTime;
101173

102174
// update optional grid columns, hidden or visible
103175
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -342,7 +414,7 @@ private void OnWindowKeyDown(object sender, KeyEventArgs e)
342414
switch (e.Key)
343415
{
344416
case Key.F5: // refresh projects
345-
projectsSource = GetProjects.Scan();
417+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
346418
gridRecent.ItemsSource = projectsSource;
347419
break;
348420
case Key.Escape: // clear project search
@@ -475,7 +547,7 @@ private void MenuItemCopyVersion_Click(object sender, RoutedEventArgs e)
475547

476548
private void BtnRefreshProjectList_Click(object sender, RoutedEventArgs e)
477549
{
478-
projectsSource = GetProjects.Scan();
550+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked);
479551
gridRecent.ItemsSource = projectsSource;
480552
}
481553

@@ -737,5 +809,24 @@ private void ChkShowGitBranchColumn_CheckedChanged(object sender, RoutedEventArg
737809
Properties.Settings.Default.Save();
738810
gridRecent.Columns[5].Visibility = (bool)chkShowGitBranchColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
739811
}
812+
813+
private void ChkQuitAfterOpen_CheckedChanged(object sender, RoutedEventArgs e)
814+
{
815+
Properties.Settings.Default.closeAfterProject = (bool)chkQuitAfterOpen.IsChecked;
816+
Properties.Settings.Default.Save();
817+
}
818+
819+
private void ChkQuitAfterCommandline_CheckedChanged(object sender, RoutedEventArgs e)
820+
{
821+
Properties.Settings.Default.closeAfterExplorer = (bool)chkQuitAfterCommandline.IsChecked;
822+
Properties.Settings.Default.Save();
823+
}
824+
825+
private void ChkShowFullTime_CheckedChanged(object sender, RoutedEventArgs e)
826+
{
827+
Properties.Settings.Default.showFullModifiedTime = (bool)chkShowFullTime.IsChecked;
828+
Properties.Settings.Default.Save();
829+
}
830+
740831
} // class
741832
} //namespace

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,8 @@
3535
<Setting Name="gridColumnWidths" Type="System.Int32[]" Scope="User">
3636
<Value Profile="(Default)" />
3737
</Setting>
38+
<Setting Name="showFullModifiedTime" Type="System.Boolean" Scope="User">
39+
<Value Profile="(Default)">False</Value>
40+
</Setting>
3841
</Settings>
3942
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ public static void LaunchProject(Project proj)
202202
}
203203
myProcess.Start();
204204

205-
/*
205+
206206
if (Properties.Settings.Default.closeAfterProject)
207207
{
208208
Environment.Exit(0);
209-
}*/
209+
}
210210
}
211211
catch (Exception e)
212212
{
@@ -494,6 +494,13 @@ public static void HandleDataGridScrollKeys(object sender, KeyEventArgs e)
494494
public static void DisplayUpgradeDialog(Project proj, MainWindow owner)
495495
{
496496
UpgradeWindow modalWindow = new UpgradeWindow(proj.Version, proj.Path, proj.Arguments);
497+
498+
modalWindow.ShowInTaskbar = owner == null;
499+
modalWindow.WindowStartupLocation = owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner;
500+
//modalWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
501+
modalWindow.Topmost = owner == null;
502+
//modalWindow.Topmost = true;
503+
modalWindow.ShowActivated = true;
497504
modalWindow.Owner = owner;
498505
modalWindow.ShowDialog();
499506
var results = modalWindow.DialogResult.HasValue && modalWindow.DialogResult.Value;
@@ -578,5 +585,69 @@ public static void RemoveContextMenuRegistry(string contextRegRoot)
578585
}
579586
}
580587

588+
/// <summary>
589+
/// reads .git/HEAD file from the project to get current branch name
590+
/// </summary>
591+
/// <param name="projectPath"></param>
592+
/// <returns></returns>
593+
public static string ReadGitBranchInfo(string projectPath)
594+
{
595+
string results = null;
596+
DirectoryInfo gitDirectory = FindDir(".git", projectPath);
597+
if (gitDirectory != null)
598+
{
599+
string branchFile = Path.Combine(gitDirectory.FullName, "HEAD");
600+
if (File.Exists(branchFile))
601+
{
602+
// removes extra end of line
603+
results = string.Join(" ", File.ReadAllLines(branchFile));
604+
// get branch only
605+
int pos = results.LastIndexOf("/") + 1;
606+
results = results.Substring(pos, results.Length - pos);
607+
}
608+
}
609+
return results;
610+
}
611+
612+
/// <summary>
613+
/// Searches for a directory beginning with "startPath".
614+
/// If the directory is not found, then parent folders are searched until
615+
/// either it is found or the root folder has been reached.
616+
/// Null is returned if the directory was not found.
617+
/// </summary>
618+
/// <param name="dirName"></param>
619+
/// <param name="startPath"></param>
620+
/// <returns></returns>
621+
public static DirectoryInfo FindDir(string dirName, string startPath)
622+
{
623+
DirectoryInfo dirInfo = new DirectoryInfo(Path.Combine(startPath, dirName));
624+
while (!dirInfo.Exists)
625+
{
626+
if (dirInfo.Parent.Parent == null)
627+
{
628+
return null;
629+
}
630+
dirInfo = new DirectoryInfo(Path.Combine(dirInfo.Parent.Parent.FullName, dirName));
631+
}
632+
return dirInfo;
633+
}
634+
635+
/// <summary>
636+
/// reads LauncherArguments.txt file from ProjectSettings-folder
637+
/// </summary>
638+
/// <param name="projectPath">full project root path</param>
639+
/// <param name="launcherArgumentsFile">default filename is "LauncherArguments.txt"</param>
640+
/// <returns></returns>
641+
public static string ReadCustomLaunchArguments(string projectPath, string launcherArgumentsFile)
642+
{
643+
string results = null;
644+
string argumentsFile = Path.Combine(projectPath, "ProjectSettings", launcherArgumentsFile);
645+
if (File.Exists(argumentsFile) == true)
646+
{
647+
results = string.Join(" ", File.ReadAllLines(argumentsFile));
648+
}
649+
return results;
650+
}
651+
581652
} // class
582653
} // namespace

UnityLauncherPro/UpgradeWindow.xaml

Lines changed: 1 addition & 1 deletion
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="Upgrade Project Version" Height="533.165" Width="418.684" Background="{DynamicResource DarkestBackground}" MinWidth="319" MinHeight="555" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewKeyDown="Window_PreviewKeyDown">
8+
Title="Upgrade Project Version" Height="533.165" Width="418.684" Background="{DynamicResource DarkestBackground}" MinWidth="319" MinHeight="555" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewKeyDown="Window_PreviewKeyDown" ShowInTaskbar="False">
99
<Window.Resources>
1010
<!-- custom buttons -->
1111
<Style x:Key="CustomButton" TargetType="{x:Type Button}">

0 commit comments

Comments
 (0)