fix crash log deleted immediately on game relaunch
This commit is contained in:
parent
0f231064d5
commit
6a1994b850
|
@ -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:
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue