Skip to content

Commit 46c1d85

Browse files
committed
Keep at least 5 backups rather than those from the last 5 days
1 parent 7908c9b commit 46c1d85

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

ExtendedColorSchemes/HarmonyPatches/PlayerDataFileManagerSO.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ private static void Postfix()
4040
try
4141
{
4242
File.Copy(filePath, backupFilePath, true);
43-
44-
// Only keep the last 5 days worth of files to stop file spam.
45-
var fiveDaysAgo = DateTime.Now.Date.AddDays(-5);
46-
var oldFiles = Directory.EnumerateFiles(Application.persistentDataPath, "PlayerData_*", SearchOption.TopDirectoryOnly)
47-
.Where(path => File.GetCreationTime(path) < fiveDaysAgo)
48-
.ToList();
49-
50-
oldFiles.ForEach(File.Delete);
43+
44+
// Only keep the last 5 most recent backups to stop file spam.
45+
Directory.EnumerateFiles(Application.persistentDataPath, "PlayerData_*")
46+
.OrderByDescending(File.GetCreationTime)
47+
.Skip(5)
48+
.Do(File.Delete);
5149
}
5250
catch (Exception e)
5351
{

0 commit comments

Comments
 (0)