11using System ;
22using System . ComponentModel ;
3+ using System . Diagnostics ;
34using System . Drawing ; // for notifyicon
45using System . IO ;
56using System . Windows ;
@@ -336,5 +337,122 @@ private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
336337 Properties . Settings . Default . windowHeight = ( int ) win . Height ;
337338 Properties . Settings . Default . Save ( ) ;
338339 }
339- }
340- }
340+
341+ private void BtnLaunchProject_Click ( object sender , RoutedEventArgs e )
342+ {
343+ LaunchProject ( GetSelectedProject ( ) ) ;
344+ }
345+
346+ void LaunchProject ( Project proj )
347+ {
348+ // validate
349+ if ( proj == null ) return ;
350+ if ( Directory . Exists ( proj . Path ) == false ) return ;
351+
352+ Console . WriteLine ( "launching " + proj . Title ) ;
353+
354+ // there is no assets path, probably we want to create new project then
355+ var assetsFolder = Path . Combine ( proj . Path , "Assets" ) ;
356+ if ( Directory . Exists ( assetsFolder ) == false )
357+ {
358+ // TODO could ask if want to create project..?
359+ Directory . CreateDirectory ( assetsFolder ) ;
360+ }
361+
362+ /*
363+ // TODO when opening project, check for crashed backup scene first
364+ if (openProject == true)
365+ {
366+ var cancelLaunch = CheckCrashBackupScene(projectPath);
367+ if (cancelLaunch == true)
368+ {
369+ return;
370+ }
371+ }*/
372+
373+
374+ // we dont have this version installed (or no version info available)
375+ var unityExePath = GetSelectedUnityExePath ( proj . Version ) ;
376+ if ( unityExePath == null )
377+ {
378+ Console . WriteLine ( "Missing unity version " + proj . Version ) ;
379+ // SetStatus("Missing Unity version: " + version);
380+ // TODO
381+ //if (openProject == true) DisplayUpgradeDialog(version, projectPath);
382+ return ;
383+ }
384+
385+ /*
386+ if (openProject == true)
387+ {
388+ SetStatus("Launching project in Unity " + version);
389+ }
390+ else
391+ {
392+ SetStatus("Launching Unity " + version);
393+ }*/
394+
395+
396+ try
397+ {
398+ Process myProcess = new Process ( ) ;
399+ var cmd = "\" " + unityExePath + "\" " ;
400+ myProcess . StartInfo . FileName = cmd ;
401+
402+ //if (openProject == true)
403+ {
404+ var pars = " -projectPath " + "\" " + proj . Path + "\" " ;
405+
406+ // TODO check for custom launch parameters and append them
407+ //string customArguments = GetSelectedRowData("_launchArguments");
408+ //if (string.IsNullOrEmpty(customArguments) == false)
409+ //{
410+ // pars += " " + customArguments;
411+ //}
412+
413+ myProcess . StartInfo . Arguments = pars ; // TODO args + commandLineArguments;
414+ }
415+ myProcess . Start ( ) ;
416+
417+ /*
418+ if (Properties.Settings.Default.closeAfterProject)
419+ {
420+ Environment.Exit(0);
421+ }*/
422+ }
423+ catch ( Exception e )
424+ {
425+ Console . WriteLine ( e ) ;
426+ }
427+ }
428+
429+
430+ string GetSelectedUnityExePath ( string version )
431+ {
432+ for ( int i = 0 , len = unityInstallationsSource . Length ; i < len ; i ++ )
433+ {
434+ if ( version == unityInstallationsSource [ i ] . Version ) return unityInstallationsSource [ i ] . Path ;
435+ }
436+ return null ;
437+ }
438+
439+
440+ Project GetSelectedProject ( )
441+ {
442+ return ( Project ) gridRecent . SelectedItem ;
443+ }
444+
445+ private void Window_PreviewKeyDown ( object sender , KeyEventArgs e )
446+ {
447+ // override Enter for datagrid
448+ if ( e . Key == Key . Return && e . KeyboardDevice . Modifiers == ModifierKeys . None )
449+ {
450+ e . Handled = true ;
451+ LaunchProject ( GetSelectedProject ( ) ) ;
452+ return ;
453+ }
454+
455+ base . OnKeyDown ( e ) ;
456+ }
457+ } // class
458+ } //namespace
0 commit comments