fix Save Backup not pruning old backups if they're uncompressed
This commit is contained in:
parent
40891a176f
commit
afd1daef4c
|
@ -2,6 +2,9 @@
|
||||||
## 3.0 (upcoming release)
|
## 3.0 (upcoming release)
|
||||||
These changes have not been released yet.
|
These changes have not been released yet.
|
||||||
|
|
||||||
|
* For players:
|
||||||
|
* Fixed Save Backup not pruning old backups if they're uncompressed.
|
||||||
|
|
||||||
* For modders:
|
* For modders:
|
||||||
* Added `IContentPack.HasFile` method.
|
* Added `IContentPack.HasFile` method.
|
||||||
* Updated to Json.NET 12.0.1.
|
* Updated to Json.NET 12.0.1.
|
||||||
|
|
|
@ -124,20 +124,23 @@ namespace StardewModdingAPI.Mods.SaveBackup
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var oldBackups = backupFolder
|
var oldBackups = backupFolder
|
||||||
.GetFiles()
|
.GetFileSystemInfos()
|
||||||
.OrderByDescending(p => p.CreationTimeUtc)
|
.OrderByDescending(p => p.CreationTimeUtc)
|
||||||
.Skip(backupsToKeep);
|
.Skip(backupsToKeep);
|
||||||
|
|
||||||
foreach (FileInfo file in oldBackups)
|
foreach (FileSystemInfo entry in oldBackups)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.Monitor.Log($"Deleting {file.Name}...", LogLevel.Trace);
|
this.Monitor.Log($"Deleting {entry.Name}...", LogLevel.Trace);
|
||||||
file.Delete();
|
if (entry is DirectoryInfo folder)
|
||||||
|
folder.Delete(recursive: true);
|
||||||
|
else
|
||||||
|
entry.Delete();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue