minor fixes for log file purge code (#494)

This commit is contained in:
Jesse Plamondon-Willard 2018-06-08 19:24:37 -04:00
parent 30d6ff4253
commit a8be14a261
1 changed files with 5 additions and 2 deletions

View File

@ -1274,6 +1274,9 @@ namespace StardewModdingAPI
private void PurgeLogFiles() private void PurgeLogFiles()
{ {
DirectoryInfo logsDir = new DirectoryInfo(Constants.LogDir); DirectoryInfo logsDir = new DirectoryInfo(Constants.LogDir);
if (!logsDir.Exists)
return;
foreach (FileInfo logFile in logsDir.EnumerateFiles("*.txt")) foreach (FileInfo logFile in logsDir.EnumerateFiles("*.txt"))
{ {
if (logFile.Name.StartsWith(Constants.LogNamePrefix, StringComparison.InvariantCultureIgnoreCase)) if (logFile.Name.StartsWith(Constants.LogNamePrefix, StringComparison.InvariantCultureIgnoreCase))
@ -1282,9 +1285,9 @@ namespace StardewModdingAPI
{ {
FileUtilities.ForceDelete(logFile); FileUtilities.ForceDelete(logFile);
} }
catch (Exception ex) catch (IOException)
{ {
// leave file if it's locked // ignore file if it's in use
} }
} }
} }