Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions UndertaleModTool/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,25 @@ public async Task<bool> DoOpenDialog()
}
return false;
}
public async Task<bool> DoSaveDialog(bool suppressDebug = false)
public async Task<bool> DoSaveDialog(bool suppressDebug = false, bool isEmergency = false)
{
if (isEmergency && (Data is null || FilePath is null || Data.UnsupportedBytecodeVersion))
{
return false;
}
SaveFileDialog dlg = new SaveFileDialog();

dlg.DefaultExt = "win";
dlg.Filter = "GameMaker data files (.win, .unx, .ios, .droid, audiogroup*.dat)|*.win;*.unx;*.ios;*.droid;audiogroup*.dat|All files|*";
dlg.FileName = FilePath;
if (isEmergency)
{
dlg.Title = "Emergency-save the current file (separate file recommended):";
}

if (dlg.ShowDialog(this) == true)
{
await SaveFile(dlg.FileName, suppressDebug);
await SaveFile(dlg.FileName, suppressDebug, isEmergency);
return true;
}
return false;
Expand Down Expand Up @@ -1129,7 +1137,7 @@ private async Task LoadFile(string filename, bool preventClose = false, bool onl
GC.Collect();
}

private async Task SaveFile(string filename, bool suppressDebug = false)
private async Task SaveFile(string filename, bool suppressDebug = false, bool isEmergency = false)
{
if (Data == null || Data.UnsupportedBytecodeVersion)
return;
Expand Down Expand Up @@ -1273,8 +1281,9 @@ private async Task SaveFile(string filename, bool suppressDebug = false)
else
{
// It failed, but since we made a temp file for saving, no data was overwritten or destroyed (hopefully)
// We need to delete the temp file though (if it exists).
if (File.Exists(filename + "temp"))
// We need to delete the temp file though (if it exists),
// except for emergency saves for possible data recovery.
if (!isEmergency && File.Exists(filename + "temp"))
File.Delete(filename + "temp");
// No profile system changes, since the save failed, like a save was never attempted.
}
Expand All @@ -1293,7 +1302,9 @@ private async Task SaveFile(string filename, bool suppressDebug = false)

Dispatcher.Invoke(() =>
{
dialog.Hide();
dialog.Hide();
if (isEmergency && SaveSucceeded)
this.ShowMessage("Emergency save successful.");
});
});
dialog.ShowDialog();
Expand Down Expand Up @@ -1630,7 +1641,7 @@ private async void CommandBox_PreviewKeyDown(object sender, KeyEventArgs e)
result = await CSharpScript.EvaluateAsync(CommandBox.Text, scriptOptions, this, typeof(IScriptInterface));
}
catch (CompilationErrorException exc)
{
{
result = exc.Message;
Debug.WriteLine(exc);
}
Expand Down
3 changes: 3 additions & 0 deletions UndertaleModTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
{
File.WriteAllText(Path.Combine(GetExecutableDirectory(), "crash.txt"), e.ToString());
MessageBox.Show(e.ToString());
if (Application.Current.MainWindow is MainWindow mw) {
mw.DoSaveDialog(false, true);

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, false)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

Check warning on line 44 in UndertaleModTool/Program.cs

View workflow job for this annotation

GitHub Actions / build_gui (windows-latest, Debug, false, true)

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.
}
}
}
private static void GlobalUnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
Expand Down