summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-06 21:24:46 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-06 21:24:46 -0500
commit6a1994b850b30889459e650629ed9e1357e8abac (patch)
treef34ef4c14711510e70b28837a7ff878ba520e537 /src
parent0f231064d54316853912294fed603444f9faf293 (diff)
downloadSMAPI-6a1994b850b30889459e650629ed9e1357e8abac.tar.gz
SMAPI-6a1994b850b30889459e650629ed9e1357e8abac.tar.bz2
SMAPI-6a1994b850b30889459e650629ed9e1357e8abac.zip
fix crash log deleted immediately on game relaunch
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Constants.cs2
-rw-r--r--src/SMAPI/Framework/SCore.cs30
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
}
}
}