@@ -312,8 +312,15 @@ void LaunchProject(string projectPath, string version, bool openProject = true)
312312 Directory . CreateDirectory ( assetsFolder ) ;
313313 }
314314
315- bool haveExactVersion = HaveExactVersionInstalled ( version ) ;
316- if ( haveExactVersion == true )
315+ // check for crashed backup scene first
316+ var cancelLaunch = CheckCrashBackupScene ( projectPath ) ;
317+ Console . WriteLine ( cancelLaunch ) ;
318+ if ( cancelLaunch == true )
319+ {
320+ return ;
321+ }
322+
323+ if ( HaveExactVersionInstalled ( version ) == true )
317324 {
318325 //Console.WriteLine("Opening unity version " + version);
319326 SetStatus ( "Launching project in unity " + version ) ;
@@ -352,6 +359,41 @@ void LaunchProject(string projectPath, string version, bool openProject = true)
352359 }
353360 }
354361
362+ bool CheckCrashBackupScene ( string projectPath )
363+ {
364+ var cancelRunningUnity = false ;
365+ var recoveryFile = Path . Combine ( projectPath , "Temp" , "__Backupscenes" , "0.backup" ) ;
366+ if ( File . Exists ( recoveryFile ) )
367+ {
368+ DialogResult dialogResult = MessageBox . Show ( "Crash recovery scene founded, do you want to copy it into Assets/_Recovery/-folder?" , "UnityLauncher - Scene Recovery" , MessageBoxButtons . YesNoCancel ) ;
369+ if ( dialogResult == DialogResult . Yes ) // restore
370+ {
371+ var restoreFolder = Path . Combine ( projectPath , "Assets" , "_Recovery" ) ;
372+ if ( Directory . Exists ( restoreFolder ) == false )
373+ {
374+ Directory . CreateDirectory ( restoreFolder ) ;
375+ }
376+ if ( Directory . Exists ( restoreFolder ) == true )
377+ {
378+ Int32 unixTimestamp = ( Int32 ) ( DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 ) ) ) . TotalSeconds ;
379+ var uniqueFileName = "Recovered_Scene" + unixTimestamp + ".unity" ;
380+ File . Copy ( recoveryFile , Path . Combine ( restoreFolder , uniqueFileName ) ) ;
381+ SetStatus ( "Recovered crashed scene into: " + restoreFolder ) ;
382+ }
383+ else
384+ {
385+ SetStatus ( "Error: Failed to create restore folder: " + restoreFolder ) ;
386+ cancelRunningUnity = true ;
387+ }
388+ }
389+ else if ( dialogResult == DialogResult . Cancel ) // dont do restore, but run unity
390+ {
391+ cancelRunningUnity = true ;
392+ }
393+ }
394+ return cancelRunningUnity ;
395+ }
396+
355397 // parse unity installer exe from release page
356398 // thanks to https://github.com/softfruit
357399 string GetDownloadUrlForUnityVersion ( string releaseUrl )
@@ -712,7 +754,7 @@ private void Form1_KeyPress(object sender, KeyPressEventArgs e)
712754 {
713755 tbSearchBar . Focus ( ) ;
714756 tbSearchBar . Text += e . KeyChar ;
715- tbSearchBar . Select ( tbSearchBar . Text . Length , 0 ) ;
757+ tbSearchBar . Select ( tbSearchBar . Text . Length , 0 ) ;
716758 }
717759 break ;
718760 }
@@ -743,7 +785,7 @@ private void gridRecent_KeyDown(object sender, KeyEventArgs e)
743785 //Checks if you are doubleclicking the current cell
744786 private void GridRecent_CellMouseDoubleClick ( object sender , DataGridViewCellMouseEventArgs e )
745787 {
746- if ( e . Button == MouseButtons . Left && e . RowIndex == gridRecent . CurrentCell . RowIndex )
788+ if ( e . Button == MouseButtons . Left && e . RowIndex == gridRecent . CurrentCell . RowIndex )
747789 {
748790 LaunchSelectedProject ( ) ;
749791 }
0 commit comments