diff options
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Constants.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 30 |
2 files changed, 19 insertions, 13 deletions
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 } } } |