TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ DeleteOldArchives()

static void Terraria.ModLoader.BackupIO.DeleteOldArchives ( string dir,
bool isCloudSave,
string name )
inlinestaticprivate

Will delete old archive files Algorithm details:

  • One backup per day for the last week
  • One backup per week for the last month
  • One backup per month for all time

Definition at line 203 of file BackupIO.cs.

204 {
205 string path = Path.Combine(dir, TodaysBackup(name, isCloudSave));
206 if (File.Exists(path))
207 {
208 DeleteArchive(path);
209 }
210 DateTime result;
211 (FileInfo f, DateTime)[] array = (from f in new DirectoryInfo(dir).GetFiles("*" + GetArchiveName(name, isCloudSave) + "*.zip", SearchOption.TopDirectoryOnly)
212 select (f: f, TryGetTime(f.Name, out result) ? result : default(DateTime)) into tuple
213 where tuple.Item2 != default(DateTime)
214 orderby tuple.Item2
216 (FileInfo, DateTime)? previous = null;
217 (FileInfo, DateTime)[] array2 = array;
218 for (int i = 0; i < array2.Length; i++)
219 {
220 (FileInfo, DateTime) archived = array2[i];
221 if (!previous.HasValue)
222 {
224 continue;
225 }
226 int freshness = (IsArchiveOlder(archived.Item2, TimeSpan.FromDays(30.0)) ? 30 : ((!IsArchiveOlder(archived.Item2, TimeSpan.FromDays(7.0))) ? 1 : 7));
227 if ((archived.Item2 - previous.Value.Item2).Days < freshness)
228 {
229 DeleteArchive(previous.Value.Item1.FullName);
230 }
232 }
233 }
static bool IsArchiveOlder(DateTime time, TimeSpan thresholdAge)
Definition BackupIO.cs:115
static string GetArchiveName(string name, bool isCloudSave)
Definition BackupIO.cs:120
static string TodaysBackup(string name, bool isCloudSave)
Definition BackupIO.cs:125
static bool TryGetTime(string file, out DateTime result)
Definition BackupIO.cs:130
static void DeleteArchive(string path)
Definition BackupIO.cs:235

References Terraria.ModLoader.BackupIO.DeleteArchive(), Terraria.ModLoader.BackupIO.GetArchiveName(), Terraria.ModLoader.BackupIO.IsArchiveOlder(), Terraria.ModLoader.BackupIO.TodaysBackup(), and Terraria.ModLoader.BackupIO.TryGetTime().

Referenced by Terraria.ModLoader.BackupIO.RunArchiving().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: