Пример #1
0
 public RestoreDialog(MainWindow @mw, SaveBackup @sb, RemnantSave @as)
 {
     InitializeComponent();
     this.txtSave.Content = $"Save Name:\t{sb.Name}\nSave Date:\t{sb.SaveDate.ToString(CultureInfo.CurrentCulture)}";
     this._saveBackup     = sb;
     this._activeSave     = @as;
 }
        private void deleteMenuItem_Click(object sender, System.EventArgs e)
        {
            SaveBackup save          = (SaveBackup)dataBackups.SelectedItem;
            var        confirmResult = MessageBox.Show("Are you sure to delete backup \"" + save.Name + "\" (" + save.SaveDate.ToString() + ")?",
                                                       "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);

            if (confirmResult == MessageBoxResult.Yes)
            {
                if (save.Keep)
                {
                    confirmResult = MessageBox.Show("This backup is marked for keeping. Are you SURE to delete backup \"" + save.Name + "\" (" + save.SaveDate.ToString() + ")?",
                                                    "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
                    if (confirmResult != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }
                if (save.Active)
                {
                    this.ActiveSaveIsBackedUp = false;
                }
                if (Directory.Exists(backupDirPath + "\\" + save.SaveDate.Ticks))
                {
                    Directory.Delete(backupDirPath + "\\" + save.SaveDate.Ticks, true);
                }
                listBackups.Remove(save);
                dataBackups.Items.Refresh();
                logMessage("Backup \"" + save.Name + "\" (" + save.SaveDate + ") deleted.");
            }
        }
        private void DataBackups_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MenuItem analyzeMenu = ((MenuItem)dataBackups.ContextMenu.Items[0]);
            MenuItem deleteMenu  = ((MenuItem)dataBackups.ContextMenu.Items[1]);

            if (e.AddedItems.Count > 0)
            {
                SaveBackup selectedBackup = (SaveBackup)(dataBackups.SelectedItem);
                if (backupActive(selectedBackup))
                {
                    btnRestore.IsEnabled = false;
                    btnRestore.Content   = FindResource("RestoreGrey");
                }
                else
                {
                    btnRestore.IsEnabled = true;
                    btnRestore.Content   = FindResource("Restore");
                }

                analyzeMenu.IsEnabled = true;
                deleteMenu.IsEnabled  = true;
            }
            else
            {
                analyzeMenu.IsEnabled = false;
                deleteMenu.IsEnabled  = false;
                btnRestore.IsEnabled  = false;
                btnRestore.Content    = FindResource("RestoreGrey");
            }
        }
        private void updateSavedNames()
        {
            List <string> savedNames = new List <string>();

            for (int i = 0; i < listBackups.Count; i++)
            {
                SaveBackup s = listBackups[i];
                if (!s.Name.Equals(s.SaveDate.Ticks.ToString()))
                {
                    savedNames.Add(s.SaveDate.Ticks + "=" + System.Net.WebUtility.UrlEncode(s.Name));
                }
                else
                {
                }
            }
            if (savedNames.Count > 0)
            {
                Properties.Settings.Default.BackupName = string.Join(",", savedNames.ToArray());
            }
            else
            {
                Properties.Settings.Default.BackupName = "";
            }
            Properties.Settings.Default.Save();
        }
 private Boolean backupActive(SaveBackup saveBackup)
 {
     if (DateTime.Compare(saveBackup.SaveDate, File.GetLastWriteTime(saveDirPath + "\\profile.sav")) == 0)
     {
         return(true);
     }
     return(false);
 }
        private void menuRestoreWorlds_Click(object sender, RoutedEventArgs e)
        {
            if (isRemnantRunning())
            {
                logMessage("Exit the game before restoring a save backup.");
                return;
            }

            if (dataBackups.SelectedItem == null)
            {
                logMessage("Choose a backup to restore from the list!");
                return;
            }

            SaveBackup selectedBackup = (SaveBackup)dataBackups.SelectedItem;

            if (selectedBackup.Save.Characters.Count != activeSave.Characters.Count)
            {
                logMessage("Backup character count does not match current character count.");
                MessageBoxResult confirmResult = MessageBox.Show("The active save has a different number of characters than the backup worlds you are restoring. This may result in unexpected behavior. Proceed?",
                                                                 "Character Mismatch", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
                if (confirmResult == MessageBoxResult.No)
                {
                    logMessage("Canceling world restore.");
                    return;
                }
            }

            if (this.ActiveSaveIsBackedUp)
            {
                saveWatcher.EnableRaisingEvents = false;
                System.IO.DirectoryInfo di = new DirectoryInfo(saveDirPath);
                foreach (FileInfo file in di.GetFiles("save_?.sav"))
                {
                    file.Delete();
                }
                di = new DirectoryInfo(backupDirPath + "\\" + selectedBackup.SaveDate.Ticks);
                foreach (FileInfo file in di.GetFiles("save_?.sav"))
                {
                    File.Copy(file.FullName, saveDirPath + "\\" + file.Name);
                }
                foreach (SaveBackup saveBackup in listBackups)
                {
                    saveBackup.Active = false;
                }
                updateCurrentWorldAnalyzer();
                dataBackups.Items.Refresh();
                this.ActiveSaveIsBackedUp = false;
                btnBackup.IsEnabled       = false;
                btnBackup.Content         = FindResource("SaveGrey");
                logMessage("Backup world data restored!");
                saveWatcher.EnableRaisingEvents = Properties.Settings.Default.AutoBackup;
            }
            else
            {
                logMessage("Backup your current save before restoring another!");
            }
        }
 private void DataBackups_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
 {
     if (e.Column.Header.ToString().Equals("Name") && e.EditAction == DataGridEditAction.Commit)
     {
         SaveBackup sb = (SaveBackup)e.Row.Item;
         if (sb.Name.Equals(""))
         {
             sb.Name = sb.SaveDate.Ticks.ToString();
         }
     }
 }
        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 BtnRestore_Click(object sender, RoutedEventArgs e)
        {
            if (isRemnantRunning())
            {
                logMessage("Exit the game before restoring a save backup.");
                return;
            }

            if (dataBackups.SelectedItem == null)
            {
                logMessage("Choose a backup to restore from the list!");
                return;
            }

            if (this.ActiveSaveIsBackedUp)
            {
                saveWatcher.EnableRaisingEvents = false;
                System.IO.DirectoryInfo di = new DirectoryInfo(saveDirPath);
                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                SaveBackup selectedBackup = (SaveBackup)dataBackups.SelectedItem;
                foreach (var file in Directory.GetFiles(backupDirPath + "\\" + selectedBackup.SaveDate.Ticks))
                {
                    File.Copy(file, saveDirPath + "\\" + System.IO.Path.GetFileName(file));
                }
                foreach (SaveBackup saveBackup in listBackups)
                {
                    saveBackup.Active = false;
                }
                selectedBackup.Active = true;
                updateCurrentWorldAnalyzer();
                dataBackups.Items.Refresh();
                btnRestore.IsEnabled = false;
                btnRestore.Content   = FindResource("RestoreGrey");
                logMessage("Backup restored!");
                saveWatcher.EnableRaisingEvents = Properties.Settings.Default.AutoBackup;
            }
            else
            {
                logMessage("Backup your current save before restoring another!");
            }
        }
Пример #10
0
        private void analyzeMenuItem_Click(object sender, System.EventArgs e)
        {
            SaveBackup saveBackup = (SaveBackup)dataBackups.SelectedItem;

            logMessage("Showing backup save (" + saveBackup.Name + ") world analyzer...");
            SaveAnalyzer analyzer = new SaveAnalyzer(this);

            analyzer.Title    = "Backup Save (" + saveBackup.Name + ") World Analyzer";
            analyzer.Closing += Backup_Analyzer_Closing;
            List <RemnantCharacter> chars = saveBackup.Save.Characters;

            for (int i = 0; i < chars.Count; i++)
            {
                chars[i].LoadWorldData(i);
            }
            analyzer.LoadData(chars);
            backupSaveAnalyzers.Add(analyzer);
            analyzer.Show();
        }
Пример #11
0
        private void updateSavedKeeps()
        {
            List <string> savedKeeps = new List <string>();

            for (int i = 0; i < listBackups.Count; i++)
            {
                SaveBackup s = listBackups[i];
                if (s.Keep)
                {
                    savedKeeps.Add(s.SaveDate.Ticks + "=True");
                }
            }
            if (savedKeeps.Count > 0)
            {
                Properties.Settings.Default.BackupKeep = string.Join(",", savedKeeps.ToArray());
            }
            else
            {
                Properties.Settings.Default.BackupKeep = "";
            }
            Properties.Settings.Default.Save();
        }
Пример #12
0
 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);
        }