bool LoadGlobalSaves() { globalSaves.Clear(); //populate list of global saves from folder names var dirs = Directory.EnumerateDirectories(Settings.Default.savesFolder); foreach (string dir in dirs) { string dirName = Path.GetFileName(dir); if (GlobalSave.IsValidFolder(dirName)) { globalSaves.Add(new GlobalSave(dirName)); } } if (globalSaves.Count == 0) { return(false); } globalSaves.Sort(); bGlobalSaves.ResetBindings(); //globalSaveBox.BindingGroup //select the right one from the settings currGlobalSave = globalSaves.Find(gs => gs.name.Equals(Settings.Default.lastGlobalSaveName)); globalSaveBox.SelectedItem = currGlobalSave; return(true); }
bool ChangeGlobalSave(GlobalSave gs, Save?s = null) { if (!Utils.isGTRunning()) { if (currGlobalSave.Equals(gs) && s == null) { return(true); } var prompt = MessageBox.Show("Do you want to backup the current story point?", "Global save swap", MessageBoxButton.YesNoCancel); if (prompt.Equals(MessageBoxResult.Yes)) { NewSave(); } else if (prompt.Equals(MessageBoxResult.Cancel)) { return(false); } //back up the current global save string gssource = Utils.getOrigGlobalSavePath(); string gsdest = GetGlobalSaveFilePath(); File.Copy(gssource, gsdest, true); //swap the new global save gssource = GetGlobalSaveFilePath(gs); gsdest = Utils.getOrigGlobalSavePath(); File.Copy(gssource, gsdest, true); //swap the corresponding save string sdest = Utils.getOrigSavePath(); File.Delete(sdest); if (s != null) { RestoreSave(s.Value); } else { File.Create(sdest).Dispose(); } currGlobalSave = gs; globalSaveLabel.Content = $"Current global save: {currGlobalSave}"; LoadSaves(gs); return(true); } else { MessageBox.Show("Cannot swap a global save file while Golden Treasure is running! Close Golden Treasure before trying again.", "Error"); globalSaveBox.SelectedItem = currGlobalSave; return(false); } }
void LoadAllSaves() { //populate global saves LoadGlobalSaves(); currGlobalSave = globalSaves.Find(gs => gs.name.Equals(Settings.Default.lastGlobalSaveName)); if (currGlobalSave.name == null) { currGlobalSave = globalSaves.Find(gs => gs.num.Equals(globalSaves.Min(gs1 => gs1.num))); } //populate local saves with current global save globalSaveBox.SelectedItem = currGlobalSave; LoadSaves(currGlobalSave); }
void LoadSaves(GlobalSave gs) { saves.Clear(); var gsFolder = GetSaveDirPath(gs); var files = Directory.EnumerateFiles(gsFolder); foreach (string filePath in files) { string file = Path.GetFileName(filePath); if (Save.IsValid(file)) { saves.Add(new Save(file)); } } saves.Sort(); bSaves.ResetBindings(); }
void NewGlobalSave(int?num = null, bool first = false) { //set the right number and create the gsave struct int theNum = num ?? globalSaves.Max(s => s.num) + 1; GlobalSave gs = new GlobalSave(theNum); //create the folder and file Directory.CreateDirectory(GetSaveDirPath(gs)); File.Create(GetGlobalSaveFilePath(gs)).Dispose(); if (first) { //automatically backup the global save on first open File.Copy(Utils.getOrigGlobalSavePath(), GetGlobalSaveFilePath(gs), true); currGlobalSave = gs; globalSaveBox.SelectedItem = gs; } else { ChangeGlobalSave(gs); } }
public int CompareTo(object obj) { GlobalSave gs2 = (GlobalSave)obj; return(this.num.CompareTo(gs2.num)); }