Skip to content

Commit 4c89ebf

Browse files
committed
Added setting to delete recovered scene or display load popup
1 parent dd60754 commit 4c89ebf

4 files changed

Lines changed: 77 additions & 48 deletions

File tree

UnityLauncherPro/MainWindow.xaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@
741741
<CheckBox x:Name="chkFetchAdditionalInfo" Content="Fetch additional info about Editor" ToolTip="Reads releases API for security related info" Checked="chkFetchAdditionalInfo_Checked" Unchecked="chkFetchAdditionalInfo_Checked"/>
742742
<CheckBox x:Name="chkFetchOnlineTemplates" Content="New Project window: Fetch online templates" ToolTip="Automatically fetch template listfrom Unity servers" Checked="chkFetchOnlineTemplates_Checked" Unchecked="chkFetchOnlineTemplates_Checked"/>
743743
<CheckBox x:Name="chkStreamerMode" Content="Streamer Mode (hide project names and folders)" ToolTip="Hide project names and folders in main view" Checked="ChkStreamerMode_Checked" Unchecked="ChkStreamerMode_Checked" HorizontalAlignment="Left"/>
744+
<CheckBox x:Name="chkDeleteRecoveredScene" Content="Delete recovered scene after editor crash" ToolTip="Delete recovered scene or display load popup" Checked="ChkDeleteRecoveredScene_Checked" Unchecked="ChkDeleteRecoveredScene_Checked" HorizontalAlignment="Left"/>
744745
<!--<StackPanel Orientation="Horizontal" Margin="0,0,0,4">
745746
<TextBox x:Name="txtTemplatePackagesFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" ToolTip="Folder for your custom unitypackage templates (for new project)" Padding="0,3,0,0" Width="110" TextChanged="TxtTemplatePackagesFolder_TextChanged" />
746747
<Button Style="{StaticResource CustomButton}" x:Name="btnBrowseTemplateUnityPackagesFolder" Content="..." Margin="6,0,0,0" MinWidth="22" MinHeight="22" FontSize="16" ToolTip="Browse for new projects root folder.." Click="BtnBrowseTemplateUnityPackagesFolder_Click" />
@@ -758,23 +759,23 @@
758759
<CheckBox x:Name="chkRunAutomatically" Content="Run automatically on startup" ToolTip="Run automatically using startup registry key" HorizontalAlignment="Left" Checked="ChkRunAutomatically_Checked" Unchecked="ChkRunAutomatically_Checked"/>
759760
<CheckBox x:Name="chkRunAutomaticallyMinimized" Content="as minimized" ToolTip="Minimize to tray when started automatically" HorizontalAlignment="Left" Checked="ChkRunAutomaticallyMinimized_Checked" Unchecked="ChkRunAutomaticallyMinimized_Checked" Margin="5,0,0,3"/>
760761
</StackPanel>
761-
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,6,0,0">
762+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,-1,0,0">
762763
<Label Content="Initial WebGL server port" Foreground="{DynamicResource ThemeButtonForeground}" />
763764
<TextBox x:Name="txtWebglPort" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="80" ToolTip="Initial port for first local WebGL webserver process (next one will be +1)" Padding="0,3,0,0" TextChanged="txtWebglPort_TextChanged" HorizontalAlignment="Left" Text="50000" LostFocus="txtWebglPort_LostFocus" Margin="1,0,0,0" Height="22" />
764765
</StackPanel>
765-
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4" HorizontalAlignment="Left">
766+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,-1,0,4" HorizontalAlignment="Left">
766767
<Label Content="Shortcut .bat files folder" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />
767768
<TextBox x:Name="txtShortcutBatchFileFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="169" ToolTip="Save generated .bat files here (they are run from Desktop Shortcut)" Padding="0,3,0,0" HorizontalAlignment="Left" MaxWidth="169" LostFocus="TxtShortcutBatchFileFolder_LostFocus" TextChanged="TxtShortcutBatchFileFolder_TextChanged" Margin="5,0,0,0" Height="22" />
768769
<Button Style="{StaticResource CustomButton}" x:Name="btnBrowseBatchFileFolder" Content="..." Margin="5,0,0,0" MinWidth="22" Click="BtnBrowseBatchFileFolder_Click" MinHeight="22" FontSize="16" ToolTip="Browse for .bat folder (default location is inside AppData/UnityLauncherPro/ and works fine, so this is optional)" HorizontalAlignment="Left" />
769770
</StackPanel>
770-
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4" HorizontalAlignment="Left">
771-
<Label Content="ADB args:" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" VerticalContentAlignment="Center" Margin="0,1,0,-4" />
771+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,-1,0,4" HorizontalAlignment="Left">
772+
<Label Content="ADB args:" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" VerticalContentAlignment="Center" Margin="0,0,0,-4" />
772773
<TextBox x:Name="txtLogCatArgs" BorderBrush="Transparent" Text="-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="250" ToolTip="ADB commandline arguments" Padding="0,3,0,0" TextChanged="TxtLogCatArgs_TextChanged" Width="250" Height="22" />
773774
<Button Style="{StaticResource CustomButton}" x:Name="btnResetLogCatArgs" Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Reset to default logcat args" Click="BtnResetLogCatArgs_Click">
774775
<Label Content="Reset" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
775776
</Button>
776777
</StackPanel>
777-
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,6,0,0">
778+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,-2,0,0">
778779
<Button x:Name="btnPatchHubConfig" ToolTip="Modifies json file to set 'manual:true' values into 'false', so that can add modules using Hub. NOTE: This cannot be reversed (not keeping track which values were already 'false')" Style="{StaticResource CustomButton}" HorizontalAlignment="Left" VerticalAlignment="Top" Click="btnPatchHubConfig_Click">
779780
<Label Content="Patch Hub editors.json" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
780781
</Button>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ void LoadSettings()
583583
chkAskNameForQuickProject.IsChecked = Settings.Default.askNameForQuickProject;
584584
chkEnableProjectRename.IsChecked = Settings.Default.enableProjectRename;
585585
chkStreamerMode.IsChecked = Settings.Default.streamerMode;
586+
chkDeleteRecoveredScene.IsChecked = Settings.Default.deleteRecoveredScene;
586587
chkShowPlatform.IsChecked = Settings.Default.showTargetPlatform;
587588
chkCheckSRP.IsChecked = Settings.Default.checkSRP;
588589
chkUseCustomTheme.IsChecked = Settings.Default.useCustomTheme;
@@ -2219,6 +2220,14 @@ private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)
22192220
SetStatus("Streamer mode " + (isChecked ? "enabled" : "disabled"), MessageType.Info);
22202221
}
22212222

2223+
private void ChkDeleteRecoveredScene_Checked(object sender, RoutedEventArgs e)
2224+
{
2225+
var isChecked = (bool)((CheckBox)sender).IsChecked;
2226+
2227+
Settings.Default.deleteRecoveredScene = isChecked;
2228+
Settings.Default.Save();
2229+
}
2230+
22222231
private void ChkShowPlatform_Checked(object sender, RoutedEventArgs e)
22232232
{
22242233
if (this.IsActive == false) return; // dont run code on window init

UnityLauncherPro/Properties/Settings.Designer.cs

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

UnityLauncherPro/Tools.cs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Windows.Media;
2020
using System.Windows.Threading;
2121
using UnityLauncherPro.Helpers;
22+
using UnityLauncherPro.Properties;
2223

2324
namespace UnityLauncherPro
2425
{
@@ -410,49 +411,55 @@ static bool CheckCrashBackupScene(string projectPath)
410411
var recoveryFile = Path.Combine(projectPath, "Temp", "__Backupscenes", "0.backup");
411412
if (File.Exists(recoveryFile))
412413
{
413-
File.Delete(recoveryFile);
414-
Directory.Delete(Path.GetDirectoryName(recoveryFile));
415-
416-
// var result = MessageBox.Show("Crash recovery scene found, do you want to MOVE it into Assets/_Recovery/-folder?", "UnityLauncherPro - Scene Recovery", MessageBoxButton.YesNo, MessageBoxImage.Question);
417-
// if (result == MessageBoxResult.Yes)
418-
// {
419-
// var restoreFolder = Path.Combine(projectPath, "Assets", "_Recovery");
420-
// if (Directory.Exists(restoreFolder) == false)
421-
// {
422-
// Directory.CreateDirectory(restoreFolder);
423-
// }
424-
// if (Directory.Exists(restoreFolder) == true)
425-
// {
426-
// Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
427-
// var uniqueFileName = "Recovered_Scene" + unixTimestamp + ".unity";
428-
//
429-
// try
430-
// {
431-
// File.Move(recoveryFile, Path.Combine(restoreFolder, uniqueFileName));
432-
// // remove folder, otherwise unity 6000.2 asks for recovery
433-
// Directory.Delete(Path.Combine(projectPath, "Temp", "__Backupscenes"), true);
434-
//
435-
// Console.WriteLine("moved file to " + uniqueFileName);
436-
// }
437-
// catch (IOException)
438-
// {
439-
// // if move failed, try copy
440-
// File.Copy(recoveryFile, Path.Combine(restoreFolder, uniqueFileName));
441-
// Console.WriteLine("copied file");
442-
// }
443-
//
444-
// Console.WriteLine("Recovered crashed scene into: " + restoreFolder);
445-
// }
446-
// else
447-
// {
448-
// Console.WriteLine("Error: Failed to create restore folder: " + restoreFolder);
449-
// cancelRunningUnity = true;
450-
// }
451-
// }
452-
// else if (result == MessageBoxResult.Cancel) // dont do restore, but run Unity
453-
// {
454-
// cancelRunningUnity = true;
455-
// }
414+
if (Settings.Default.deleteRecoveredScene)
415+
{
416+
File.Delete(recoveryFile);
417+
Directory.Delete(Path.GetDirectoryName(recoveryFile));
418+
}
419+
else
420+
{
421+
var result = MessageBox.Show("Crash recovery scene found, do you want to MOVE it into Assets/_Recovery/-folder?", "UnityLauncherPro - Scene Recovery", MessageBoxButton.YesNo, MessageBoxImage.Question);
422+
if (result == MessageBoxResult.Yes)
423+
{
424+
var restoreFolder = Path.Combine(projectPath, "Assets", "_Recovery");
425+
if (Directory.Exists(restoreFolder) == false)
426+
{
427+
Directory.CreateDirectory(restoreFolder);
428+
}
429+
430+
if (Directory.Exists(restoreFolder) == true)
431+
{
432+
Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
433+
var uniqueFileName = "Recovered_Scene" + unixTimestamp + ".unity";
434+
435+
try
436+
{
437+
File.Move(recoveryFile, Path.Combine(restoreFolder, uniqueFileName));
438+
// remove folder, otherwise unity 6000.2 asks for recovery
439+
Directory.Delete(Path.Combine(projectPath, "Temp", "__Backupscenes"), true);
440+
441+
Console.WriteLine("moved file to " + uniqueFileName);
442+
}
443+
catch (IOException)
444+
{
445+
// if move failed, try copy
446+
File.Copy(recoveryFile, Path.Combine(restoreFolder, uniqueFileName));
447+
Console.WriteLine("copied file");
448+
}
449+
450+
Console.WriteLine("Recovered crashed scene into: " + restoreFolder);
451+
}
452+
else
453+
{
454+
Console.WriteLine("Error: Failed to create restore folder: " + restoreFolder);
455+
cancelRunningUnity = true;
456+
}
457+
}
458+
else if (result == MessageBoxResult.Cancel) // dont do restore, but run Unity
459+
{
460+
cancelRunningUnity = true;
461+
}
462+
}
456463
}
457464
return cancelRunningUnity;
458465
}

0 commit comments

Comments
 (0)