Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit c3936f4

Browse files
committed
add run unity button, fix: open correct tab at start if missing root folder, fixed uninstall registry key error if no key
1 parent 37c03f1 commit c3936f4

File tree

3 files changed

+70
-37
lines changed

3 files changed

+70
-37
lines changed

UnityLauncher/Form1.Designer.cs

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

UnityLauncher/Form1.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public partial class Form1 : Form
1717
// version,exe path (example: 5.6.1f1,c:\prog\unity561\editor\unity.exe)
1818
Dictionary<string, string> unityList = new Dictionary<string, string>();
1919

20+
const int settingsTabIndex = 3;
21+
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
22+
2023
public Form1()
2124
{
2225
InitializeComponent();
@@ -48,7 +51,7 @@ void Start()
4851
{
4952
SetStatus("Error> Did not found any Unity installations, try setting correct root folder..");
5053
UpdateRecentProjectsList();
51-
tabControl1.SelectedIndex = 2; // settings tab
54+
tabControl1.SelectedIndex = settingsTabIndex;
5255
return;
5356
}
5457

@@ -62,7 +65,7 @@ void Start()
6265
SetStatus("Launching from commandline..");
6366

6467
var pathArg = args[2];
65-
LaunchProject(pathArg);
68+
LaunchProject(pathArg, true);
6669
SetStatus("Ready");
6770

6871
// quit after launch if enabled in settings
@@ -75,7 +78,6 @@ void Start()
7578
{
7679
SetStatus("Error> Invalid arguments:" + args[1]);
7780
}
78-
7981
}
8082

8183
UpdateRecentProjectsList();
@@ -285,30 +287,31 @@ void UpdateRecentProjectsList()
285287
}
286288
}
287289

288-
void LaunchProject(string pathArg = null)
290+
void LaunchProject(string pathArg = null, bool openProject = true)
289291
{
290-
// check if path is unity project folder
291292
if (Directory.Exists(pathArg) == true)
292293
{
293-
// validate folder
294294
if (Directory.Exists(Path.Combine(pathArg, "Assets")))
295295
{
296296
var version = GetProjectVersion(pathArg);
297-
Console.WriteLine("Detected project version: " + version);
297+
//Console.WriteLine("Detected project version: " + version);
298298

299299
bool installed = HaveExactVersionInstalled(version);
300300
if (installed == true)
301301
{
302-
// TODO: open?
303-
Console.WriteLine("Opening unity version " + version);
302+
//Console.WriteLine("Opening unity version " + version);
303+
SetStatus("Launching project in unity " + version);
304304

305305
try
306306
{
307307
Process myProcess = new Process();
308308
var cmd = "\"" + unityList[version] + "\"";
309-
var pars = " -projectPath " + "\"" + pathArg + "\"";
310309
myProcess.StartInfo.FileName = cmd;
311-
myProcess.StartInfo.Arguments = pars;
310+
if (openProject == true)
311+
{
312+
var pars = " -projectPath " + "\"" + pathArg + "\"";
313+
myProcess.StartInfo.Arguments = pars;
314+
}
312315
myProcess.Start();
313316
}
314317
catch (Exception ex)
@@ -317,8 +320,10 @@ void LaunchProject(string pathArg = null)
317320
}
318321

319322
}
320-
else
323+
else // we dont have this version installed
321324
{
325+
SetStatus("Missing unity version: " + version);
326+
322327
var yesno = MessageBox.Show("Unity version " + version + " is not installed! Yes = Download, No = Open Webpage", "UnityLauncher", MessageBoxButtons.YesNoCancel);
323328

324329
string url = GetUnityReleaseURL(version);
@@ -480,13 +485,13 @@ private void ShowForm()
480485
notifyIcon.Visible = false;
481486
}
482487

483-
void LaunchSelectedProject()
488+
void LaunchSelectedProject(bool openProject = true)
484489
{
485490
var selected = gridRecent.CurrentCell.RowIndex;
486491
if (selected > -1)
487492
{
488493
SetStatus("Launching project..");
489-
LaunchProject(gridRecent.Rows[selected].Cells["_path"].Value.ToString());
494+
LaunchProject(gridRecent.Rows[selected].Cells["_path"].Value.ToString(), openProject);
490495
SetStatus("Ready");
491496
}
492497
}
@@ -549,7 +554,7 @@ void AddPackageFolder()
549554

550555
void AddContextMenuRegistry()
551556
{
552-
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\Directory\\Background\\shell", true);
557+
RegistryKey key = Registry.CurrentUser.OpenSubKey(contextRegRoot, true);
553558
if (key != null)
554559
{
555560
var appName = "UnityLauncher";
@@ -568,22 +573,30 @@ void AddContextMenuRegistry()
568573
}
569574
else
570575
{
571-
SetStatus("Error> Cannot find registry key: Software\\Classes\\Directory\\Background\\shell");
576+
SetStatus("Error> Cannot find registry key: " + contextRegRoot);
572577
}
573578
}
574579

575580
void RemoveContextMenuRegistry()
576581
{
577-
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\Directory\\Background\\shell", true);
582+
RegistryKey key = Registry.CurrentUser.OpenSubKey(contextRegRoot, true);
578583
if (key != null)
579584
{
580585
var appName = "UnityLauncher";
581-
key.DeleteSubKeyTree(appName);
582-
SetStatus("Removed context menu registry items");
586+
RegistryKey appKey = Registry.CurrentUser.OpenSubKey(contextRegRoot + "\\" + appName, false);
587+
if (appKey != null)
588+
{
589+
key.DeleteSubKeyTree(appName);
590+
SetStatus("Removed context menu registry items");
591+
}
592+
else
593+
{
594+
SetStatus("Nothing to uninstall..");
595+
}
583596
}
584597
else
585598
{
586-
SetStatus("Error> Cannot find registry key: Software\\Classes\\Directory\\Background\\shell");
599+
SetStatus("Error> Cannot find registry key: " + contextRegRoot);
587600
}
588601
}
589602

@@ -800,12 +813,18 @@ private void btnAddRegister_Click(object sender, EventArgs e)
800813
{
801814
AddContextMenuRegistry();
802815
}
803-
#endregion
804816

805817
private void chkQuitAfterCommandline_CheckedChanged(object sender, EventArgs e)
806818
{
807819
Properties.Settings.Default.closeAfterExplorer = chkQuitAfterCommandline.Checked;
808820
Properties.Settings.Default.Save();
809821
}
822+
823+
private void btnRunUnityOnly_Click(object sender, EventArgs e)
824+
{
825+
LaunchSelectedProject(openProject: false);
826+
}
827+
828+
#endregion
810829
}
811830
}

UnityLauncher/Form1.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@
120120
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121121
<value>376, 18</value>
122122
</metadata>
123-
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124-
<value>14, 20</value>
125-
</metadata>
126123
<metadata name="_project.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
127124
<value>True</value>
128125
</metadata>
@@ -1054,6 +1051,9 @@
10541051
AAA=
10551052
</value>
10561053
</data>
1054+
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
1055+
<value>14, 20</value>
1056+
</metadata>
10571057
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
10581058
<value>43</value>
10591059
</metadata>

0 commit comments

Comments
 (0)