private static void PurgeOldBackups(String OriginalName) { //Now delete any old ones greater than the list to keep List <System.IO.FileInfo> SaveBackups = new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("KACBACKUP*{0}", OriginalName)).ToList <System.IO.FileInfo>(); SaveBackups.AddRange(new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("zKACBACKUP*{0}", OriginalName)).ToList <System.IO.FileInfo>()); Log.dbg("{0} KACBackup...{1} Saves found", SaveBackups.Count, OriginalName); List <System.IO.FileInfo> SaveBackupsToDelete = SaveBackups.OrderByDescending(fi => fi.CreationTime).Skip(KerbalAlarmClock.settings.BackupSavesToKeep).ToList <System.IO.FileInfo>(); Log.dbg("{0} KACBackup...{1} Saves to purge", SaveBackupsToDelete.Count, OriginalName); for (int i = SaveBackupsToDelete.Count - 1; i >= 0; i--) { Log.dbg("\tDeleting {0}", SaveBackupsToDelete[i].Name); //bin the loadmeta if it exists too string loadmetaFile = SaveBackupsToDelete[i].DirectoryName + "/" + System.IO.Path.GetFileNameWithoutExtension(SaveBackupsToDelete[i].FullName) + ".loadmeta"; if (System.IO.File.Exists(loadmetaFile)) { System.IO.File.Delete(loadmetaFile); } SaveBackupsToDelete[i].Delete(); } }
private static void PurgeOldBackups(String OriginalName) { //Now delete any old ones greater than the list to keep List <System.IO.FileInfo> SaveBackups = new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("KACBACKUP*{0}", OriginalName)).ToList <System.IO.FileInfo>(); KACWorker.DebugLogFormatted("{0} KACBackup...{1} Saves found", SaveBackups.Count, OriginalName); List <System.IO.FileInfo> SaveBackupsToDelete = SaveBackups.OrderByDescending(fi => fi.CreationTime).Skip(KerbalAlarmClock.Settings.BackupSavesToKeep).ToList <System.IO.FileInfo>(); KACWorker.DebugLogFormatted("{0} KACBackup...{1} Saves to purge", SaveBackupsToDelete.Count, OriginalName); for (int i = SaveBackupsToDelete.Count - 1; i >= 0; i--) { KACWorker.DebugLogFormatted("\tDeleting {0}", SaveBackupsToDelete[i].Name); SaveBackupsToDelete[i].Delete(); } }
private static void PurgeOldBackups(String OriginalName) { //Now delete any old ones greater than the list to keep List<System.IO.FileInfo> SaveBackups = new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("KACBACKUP*{0}",OriginalName)).ToList<System.IO.FileInfo>(); SaveBackups.AddRange(new System.IO.DirectoryInfo(SavePath).GetFiles(string.Format("zKACBACKUP*{0}", OriginalName)).ToList<System.IO.FileInfo>()); MonoBehaviourExtended.LogFormatted("{0} KACBackup...{1} Saves found", SaveBackups.Count,OriginalName); List<System.IO.FileInfo> SaveBackupsToDelete = SaveBackups.OrderByDescending(fi => fi.CreationTime).Skip(KerbalAlarmClock.settings.BackupSavesToKeep).ToList<System.IO.FileInfo>(); MonoBehaviourExtended.LogFormatted("{0} KACBackup...{1} Saves to purge", SaveBackupsToDelete.Count, OriginalName); for (int i = SaveBackupsToDelete.Count - 1; i >= 0; i--) { MonoBehaviourExtended.LogFormatted("\tDeleting {0}", SaveBackupsToDelete[i].Name); SaveBackupsToDelete[i].Delete(); } }