fix Save Backup not pruning old backups if they're uncompressed

This commit is contained in:
Jesse Plamondon-Willard 2019-02-09 15:16:14 -05:00
parent 40891a176f
commit afd1daef4c
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
2 changed files with 11 additions and 5 deletions

View File

@ -2,6 +2,9 @@
## 3.0 (upcoming release)
These changes have not been released yet.
* For players:
* Fixed Save Backup not pruning old backups if they're uncompressed.
* For modders:
* Added `IContentPack.HasFile` method.
* Updated to Json.NET 12.0.1.

View File

@ -124,20 +124,23 @@ namespace StardewModdingAPI.Mods.SaveBackup
try
{
var oldBackups = backupFolder
.GetFiles()
.GetFileSystemInfos()
.OrderByDescending(p => p.CreationTimeUtc)
.Skip(backupsToKeep);
foreach (FileInfo file in oldBackups)
foreach (FileSystemInfo entry in oldBackups)
{
try
{
this.Monitor.Log($"Deleting {file.Name}...", LogLevel.Trace);
file.Delete();
this.Monitor.Log($"Deleting {entry.Name}...", LogLevel.Trace);
if (entry is DirectoryInfo folder)
folder.Delete(recursive: true);
else
entry.Delete();
}
catch (Exception ex)
{
this.Monitor.Log($"Error deleting old save backup '{file.Name}': {ex}");
this.Monitor.Log($"Error deleting old save backup '{entry.Name}': {ex}");
}
}
}