@@ -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}
0 commit comments