diff options
-rw-r--r-- | docs/release-notes.md | 1 | ||||
-rw-r--r-- | src/SMAPI/Constants.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 30 |
3 files changed, 20 insertions, 13 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index e7434c3c..57fb33a4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -21,6 +21,7 @@ * Fixed translation issues not shown as warnings. * Fixed dependencies not correctly enforced if the dependency is installed but failed to load. * Fixed some errors logged as SMAPI instead of the affected mod. + * Fixed crash log deleted immediately when you relaunch the game. * Updated compatibility list. * For the web UI: diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 83b17401..67f03fab 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -82,7 +82,7 @@ namespace StardewModdingAPI /// <summary>The filename extension for SMAPI log files.</summary> internal static string LogExtension { get; } = "txt"; - /// <summary>A copy of the log leading up to the previous fatal crash, if any.</summary> + /// <summary>The file path for the log containing 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> diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e76e7a1d..3e8766c2 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -120,7 +120,7 @@ namespace StardewModdingAPI.Framework this.ModsPath = modsPath; // init log file - this.PurgeLogFiles(); + this.PurgeNormalLogs(); string logPath = this.GetLogPath(); // init basics @@ -1329,8 +1329,8 @@ namespace StardewModdingAPI.Framework throw new InvalidOperationException("Could not find an available log path."); } - /// <summary>Delete all log files created by SMAPI.</summary> - private void PurgeLogFiles() + /// <summary>Delete normal (non-crash) log files created by SMAPI.</summary> + private void PurgeNormalLogs() { DirectoryInfo logsDir = new DirectoryInfo(Constants.LogDir); if (!logsDir.Exists) @@ -1338,16 +1338,22 @@ namespace StardewModdingAPI.Framework foreach (FileInfo logFile in logsDir.EnumerateFiles()) { - if (logFile.Name.StartsWith(Constants.LogNamePrefix, StringComparison.InvariantCultureIgnoreCase)) + // skip non-SMAPI file + if (!logFile.Name.StartsWith(Constants.LogNamePrefix, StringComparison.InvariantCultureIgnoreCase)) + continue; + + // skip crash log + if (logFile.FullName == Constants.FatalCrashLog) + continue; + + // delete file + try { - try - { - FileUtilities.ForceDelete(logFile); - } - catch (IOException) - { - // ignore file if it's in use - } + FileUtilities.ForceDelete(logFile); + } + catch (IOException) + { + // ignore file if it's in use } } } |