private void loadBackups() { if (!Directory.Exists(backupDirPath)) { logMessage("Backups folder not found, creating..."); Directory.CreateDirectory(backupDirPath); } dataBackups.ItemsSource = null; listBackups.Clear(); Dictionary <long, string> backupNames = getSavedBackupNames(); Dictionary <long, bool> backupKeeps = getSavedBackupKeeps(); string[] files = Directory.GetDirectories(backupDirPath); SaveBackup activeBackup = null; for (int i = 0; i < files.Length; i++) { if (RemnantSave.ValidSaveFolder(files[i])) { SaveBackup backup = new SaveBackup(files[i]); if (backupNames.ContainsKey(backup.SaveDate.Ticks)) { backup.Name = backupNames[backup.SaveDate.Ticks]; } if (backupKeeps.ContainsKey(backup.SaveDate.Ticks)) { backup.Keep = backupKeeps[backup.SaveDate.Ticks]; } if (backupActive(backup)) { backup.Active = true; activeBackup = backup; } backup.Updated += saveUpdated; listBackups.Add(backup); } } dataBackups.ItemsSource = listBackups; logMessage("Backups found: " + listBackups.Count); if (listBackups.Count > 0) { logMessage("Last backup save date: " + listBackups[listBackups.Count - 1].SaveDate.ToString()); } if (activeBackup != null) { dataBackups.SelectedItem = activeBackup; } ActiveSaveIsBackedUp = (activeBackup != null); }
private void doBackup() { try { int existingSaveIndex = -1; DateTime saveDate = File.GetLastWriteTime(saveDirPath + "\\profile.sav"); string backupFolder = backupDirPath + "\\" + saveDate.Ticks; if (!Directory.Exists(backupFolder)) { Directory.CreateDirectory(backupFolder); } else if (RemnantSave.ValidSaveFolder(backupFolder)) { for (int i = listBackups.Count - 1; i >= 0; i--) { if (listBackups[i].SaveDate.Ticks == saveDate.Ticks) { existingSaveIndex = i; break; } } } foreach (string file in Directory.GetFiles(saveDirPath)) { File.Copy(file, backupFolder + "\\" + System.IO.Path.GetFileName(file), true); } if (RemnantSave.ValidSaveFolder(backupFolder)) { Dictionary <long, string> backupNames = getSavedBackupNames(); Dictionary <long, bool> backupKeeps = getSavedBackupKeeps(); SaveBackup backup = new SaveBackup(backupFolder); if (backupNames.ContainsKey(backup.SaveDate.Ticks)) { backup.Name = backupNames[backup.SaveDate.Ticks]; } if (backupKeeps.ContainsKey(backup.SaveDate.Ticks)) { backup.Keep = backupKeeps[backup.SaveDate.Ticks]; } foreach (SaveBackup saveBackup in listBackups) { saveBackup.Active = false; } backup.Active = true; backup.Updated += saveUpdated; if (existingSaveIndex > -1) { listBackups[existingSaveIndex] = backup; } else { listBackups.Add(backup); } } checkBackupLimit(); dataBackups.Items.Refresh(); this.ActiveSaveIsBackedUp = true; logMessage($"Backup completed ({saveDate.ToString()})!"); } catch (IOException ex) { if (ex.Message.Contains("being used by another process")) { logMessage("Save file in use; waiting 0.5 seconds and retrying."); System.Threading.Thread.Sleep(500); doBackup(); } } }
private void loadBackups() { if (!Directory.Exists(backupDirPath)) { logMessage("Backups folder not found, creating..."); Directory.CreateDirectory(backupDirPath); } dataBackups.ItemsSource = null; listBackups.Clear(); Dictionary <long, string> backupNames = getSavedBackupNames(); Dictionary <long, bool> backupKeeps = getSavedBackupKeeps(); string[] files = Directory.GetDirectories(backupDirPath); SaveBackup activeBackup = null; /*DataGridTextColumn col1 = new DataGridTextColumn(); * col1.Header = "Name"; * col1.Binding = new Binding("Name"); * dataBackups.Columns.Add(col1); * DataGridTextColumn col2 = new DataGridTextColumn(); * col2.Header = "Date"; * col2.Binding = new Binding("SaveDate"); * dataBackups.Columns.Add(col2); * DataGridCheckBoxColumn col3 = new DataGridCheckBoxColumn(); * col3.Header = "Keep"; * col3.Binding = new Binding("Keep"); * dataBackups.Columns.Add(col3);*/ for (int i = 0; i < files.Length; i++) { if (RemnantSave.ValidSaveFolder(files[i])) { SaveBackup backup = new SaveBackup(files[i]); if (backupNames.ContainsKey(backup.SaveDate.Ticks)) { backup.Name = backupNames[backup.SaveDate.Ticks]; } if (backupKeeps.ContainsKey(backup.SaveDate.Ticks)) { backup.Keep = backupKeeps[backup.SaveDate.Ticks]; } if (backupActive(backup)) { backup.Active = true; activeBackup = backup; } backup.Updated += saveUpdated; listBackups.Add(backup); } } dataBackups.ItemsSource = listBackups; logMessage("Backups found: " + listBackups.Count); if (listBackups.Count > 0) { logMessage("Last backup save date: " + listBackups[listBackups.Count - 1].SaveDate.ToString()); } if (activeBackup != null) { dataBackups.SelectedItem = activeBackup; } SetActiveSaveIsBackedup(activeBackup != null); }