summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Constants.cs6
-rw-r--r--src/StardewModdingAPI/Program.cs22
2 files changed, 27 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs
index 1860795d..1d6c9fa1 100644
--- a/src/StardewModdingAPI/Constants.cs
+++ b/src/StardewModdingAPI/Constants.cs
@@ -71,6 +71,12 @@ namespace StardewModdingAPI
/// <summary>The file path to the log where the latest output should be saved.</summary>
internal static string DefaultLogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt");
+ /// <summary>A copy of the log leading up to the previous fatal crash, if any.</summary>
+ internal static string FatalCrashLog => Path.Combine(Constants.LogDir, "SMAPI-crash.txt");
+
+ /// <summary>The file path which stores a fatal crash message for the next run.</summary>
+ internal static string FatalCrashMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.crash.marker");
+
/// <summary>The full path to the folder containing mods.</summary>
internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods");
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