From 3d732275874e2f36e13f10813e08b7ed2fc143f8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 9 May 2017 01:46:40 -0400 Subject: when a fatal crash happens, keep a copy of the log and notify the player on relaunch --- src/StardewModdingAPI/Program.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index aa78ff41..725ac94f 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -154,7 +154,16 @@ namespace StardewModdingAPI this.CancellationTokenSource.Token.WaitHandle.WaitOne(); if (this.IsGameRunning) { - this.GameInstance.Exiting += (sender, e) => this.PressAnyKeyToExit(); + try + { + File.WriteAllText(Constants.FatalCrashMarker, string.Empty); + File.Copy(Constants.DefaultLogPath, Constants.FatalCrashLog, overwrite: true); + } + catch (Exception ex) + { + this.Monitor.Log($"SMAPI failed trying to track the crash details: {ex.GetLogSummary()}"); + } + this.GameInstance.Exit(); } }).Start(); @@ -179,6 +188,17 @@ namespace StardewModdingAPI return; } + // show details if game crashed during last session + if (File.Exists(Constants.FatalCrashMarker)) + { + this.Monitor.Log("The game crashed last time you played. That can be due to bugs in the game, but if it happens repeatedly you can ask for help here: http://community.playstarbound.com/threads/108375/.", LogLevel.Error); + this.Monitor.Log($"If you ask for help, make sure to attach this file: {Constants.FatalCrashLog}", LogLevel.Error); + this.Monitor.Log("Press any key to delete the crash data and continue playing.", LogLevel.Info); + Console.ReadKey(); + File.Delete(Constants.FatalCrashLog); + File.Delete(Constants.FatalCrashMarker); + } + // start game this.Monitor.Log("Starting game..."); try -- cgit