private static int FindExistingSavesOfType(out int totalCount, out string? oldestSave, string matchRegex) { int highestNumber = 0; totalCount = 0; oldestSave = null; ulong oldestModifiedTime = ulong.MaxValue; using var file = new File(); foreach (var name in SaveHelper.CreateListOfSaves(SaveHelper.SaveOrder.FileSystem)) { var match = Regex.Match(name, matchRegex); if (match.Success) { ++totalCount; int found = Convert.ToInt32(match.Groups[1].Value, CultureInfo.InvariantCulture); if (found > highestNumber) highestNumber = found; var modified = file.GetModifiedTime(Path.Combine(Constants.SAVE_FOLDER, name)); if (modified < oldestModifiedTime) { oldestModifiedTime = modified; oldestSave = name; } } } return highestNumber; }
private string CalculateNameForSave() { switch (Type) { case SaveInformation.SaveType.Manual: { if (!string.IsNullOrWhiteSpace(saveName)) { if (!saveName.EndsWith(Constants.SAVE_EXTENSION_WITH_DOT, StringComparison.Ordinal)) { return(saveName + Constants.SAVE_EXTENSION_WITH_DOT); } return(saveName); } // Find the next unused save number int number = 0; foreach (var name in SaveHelper.CreateListOfSaves(SaveHelper.SaveOrder.FileSystem)) { var match = Regex.Match(name, "^save_(\\d)+\\." + Constants.SAVE_EXTENSION); if (match.Success) { int found = Convert.ToInt32(match.Groups[1].Value, CultureInfo.InvariantCulture); if (found > number) { number = found; } } } ++number; return($"save_{number:n0}." + Constants.SAVE_EXTENSION); } case SaveInformation.SaveType.AutoSave: { return(GetNextNameForSaveType("^auto_save_(\\d)+\\." + Constants.SAVE_EXTENSION, "auto_save", Settings.Instance.MaxAutoSaves)); } case SaveInformation.SaveType.QuickSave: { return(GetNextNameForSaveType("^quick_save_(\\d)+\\." + Constants.SAVE_EXTENSION, "quick_save", Settings.Instance.MaxQuickSaves)); } default: throw new InvalidOperationException(); } }
public void Refresh() { if (refreshing) { return; } refreshing = true; refreshedAtLeastOnce = true; savesList.QueueFreeChildren(); loadingItem.Visible = true; readSavesList = new Task <List <string> >(() => SaveHelper.CreateListOfSaves()); TaskExecutor.Instance.AddTask(readSavesList); }