@@ -17,6 +17,9 @@ public partial class Form1 : Form
17
17
// version,exe path (example: 5.6.1f1,c:\prog\unity561\editor\unity.exe)
18
18
Dictionary < string , string > unityList = new Dictionary < string , string > ( ) ;
19
19
20
+ const int settingsTabIndex = 3 ;
21
+ const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
22
+
20
23
public Form1 ( )
21
24
{
22
25
InitializeComponent ( ) ;
@@ -48,7 +51,7 @@ void Start()
48
51
{
49
52
SetStatus ( "Error> Did not found any Unity installations, try setting correct root folder.." ) ;
50
53
UpdateRecentProjectsList ( ) ;
51
- tabControl1 . SelectedIndex = 2 ; // settings tab
54
+ tabControl1 . SelectedIndex = settingsTabIndex ;
52
55
return ;
53
56
}
54
57
@@ -62,7 +65,7 @@ void Start()
62
65
SetStatus ( "Launching from commandline.." ) ;
63
66
64
67
var pathArg = args [ 2 ] ;
65
- LaunchProject ( pathArg ) ;
68
+ LaunchProject ( pathArg , true ) ;
66
69
SetStatus ( "Ready" ) ;
67
70
68
71
// quit after launch if enabled in settings
@@ -75,7 +78,6 @@ void Start()
75
78
{
76
79
SetStatus ( "Error> Invalid arguments:" + args [ 1 ] ) ;
77
80
}
78
-
79
81
}
80
82
81
83
UpdateRecentProjectsList ( ) ;
@@ -285,30 +287,31 @@ void UpdateRecentProjectsList()
285
287
}
286
288
}
287
289
288
- void LaunchProject ( string pathArg = null )
290
+ void LaunchProject ( string pathArg = null , bool openProject = true )
289
291
{
290
- // check if path is unity project folder
291
292
if ( Directory . Exists ( pathArg ) == true )
292
293
{
293
- // validate folder
294
294
if ( Directory . Exists ( Path . Combine ( pathArg , "Assets" ) ) )
295
295
{
296
296
var version = GetProjectVersion ( pathArg ) ;
297
- Console . WriteLine ( "Detected project version: " + version ) ;
297
+ // Console.WriteLine("Detected project version: " + version);
298
298
299
299
bool installed = HaveExactVersionInstalled ( version ) ;
300
300
if ( installed == true )
301
301
{
302
- // TODO: open?
303
- Console . WriteLine ( "Opening unity version " + version ) ;
302
+ //Console.WriteLine("Opening unity version " + version);
303
+ SetStatus ( "Launching project in unity " + version ) ;
304
304
305
305
try
306
306
{
307
307
Process myProcess = new Process ( ) ;
308
308
var cmd = "\" " + unityList [ version ] + "\" " ;
309
- var pars = " -projectPath " + "\" " + pathArg + "\" " ;
310
309
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
+ }
312
315
myProcess . Start ( ) ;
313
316
}
314
317
catch ( Exception ex )
@@ -317,8 +320,10 @@ void LaunchProject(string pathArg = null)
317
320
}
318
321
319
322
}
320
- else
323
+ else // we dont have this version installed
321
324
{
325
+ SetStatus ( "Missing unity version: " + version ) ;
326
+
322
327
var yesno = MessageBox . Show ( "Unity version " + version + " is not installed! Yes = Download, No = Open Webpage" , "UnityLauncher" , MessageBoxButtons . YesNoCancel ) ;
323
328
324
329
string url = GetUnityReleaseURL ( version ) ;
@@ -480,13 +485,13 @@ private void ShowForm()
480
485
notifyIcon . Visible = false ;
481
486
}
482
487
483
- void LaunchSelectedProject ( )
488
+ void LaunchSelectedProject ( bool openProject = true )
484
489
{
485
490
var selected = gridRecent . CurrentCell . RowIndex ;
486
491
if ( selected > - 1 )
487
492
{
488
493
SetStatus ( "Launching project.." ) ;
489
- LaunchProject ( gridRecent . Rows [ selected ] . Cells [ "_path" ] . Value . ToString ( ) ) ;
494
+ LaunchProject ( gridRecent . Rows [ selected ] . Cells [ "_path" ] . Value . ToString ( ) , openProject ) ;
490
495
SetStatus ( "Ready" ) ;
491
496
}
492
497
}
@@ -549,7 +554,7 @@ void AddPackageFolder()
549
554
550
555
void AddContextMenuRegistry ( )
551
556
{
552
- RegistryKey key = Registry . CurrentUser . OpenSubKey ( "Software \\ Classes \\ Directory \\ Background \\ shell" , true ) ;
557
+ RegistryKey key = Registry . CurrentUser . OpenSubKey ( contextRegRoot , true ) ;
553
558
if ( key != null )
554
559
{
555
560
var appName = "UnityLauncher" ;
@@ -568,22 +573,30 @@ void AddContextMenuRegistry()
568
573
}
569
574
else
570
575
{
571
- SetStatus ( "Error> Cannot find registry key: Software \\ Classes \\ Directory \\ Background \\ shell" ) ;
576
+ SetStatus ( "Error> Cannot find registry key: " + contextRegRoot ) ;
572
577
}
573
578
}
574
579
575
580
void RemoveContextMenuRegistry ( )
576
581
{
577
- RegistryKey key = Registry . CurrentUser . OpenSubKey ( "Software \\ Classes \\ Directory \\ Background \\ shell" , true ) ;
582
+ RegistryKey key = Registry . CurrentUser . OpenSubKey ( contextRegRoot , true ) ;
578
583
if ( key != null )
579
584
{
580
585
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
+ }
583
596
}
584
597
else
585
598
{
586
- SetStatus ( "Error> Cannot find registry key: Software \\ Classes \\ Directory \\ Background \\ shell" ) ;
599
+ SetStatus ( "Error> Cannot find registry key: " + contextRegRoot ) ;
587
600
}
588
601
}
589
602
@@ -800,12 +813,18 @@ private void btnAddRegister_Click(object sender, EventArgs e)
800
813
{
801
814
AddContextMenuRegistry ( ) ;
802
815
}
803
- #endregion
804
816
805
817
private void chkQuitAfterCommandline_CheckedChanged ( object sender , EventArgs e )
806
818
{
807
819
Properties . Settings . Default . closeAfterExplorer = chkQuitAfterCommandline . Checked ;
808
820
Properties . Settings . Default . Save ( ) ;
809
821
}
822
+
823
+ private void btnRunUnityOnly_Click ( object sender , EventArgs e )
824
+ {
825
+ LaunchSelectedProject ( openProject : false ) ;
826
+ }
827
+
828
+ #endregion
810
829
}
811
830
}
0 commit comments