private void RestoreBackup_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Filter = "Stardew Valley backup (*.svbu)|*.svbu"; if (openFileDialog.ShowDialog() == true) { try { string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string stardewValleySavesPath = Path.Combine(appDataPath, "StardewValley", "Saves"); string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tempDirectory); ZipFile.ExtractToDirectory(openFileDialog.FileName, tempDirectory); string[] directories = Directory.GetDirectories(tempDirectory); if (directories.Length == 1) { string tempBackupDirectory = directories[0]; string savedGameName = Path.GetFileName(tempBackupDirectory); string savedGameDestination = Path.Combine(stardewValleySavesPath, savedGameName); if (Directory.Exists(savedGameDestination)) { MessageBoxResult result = MessageBox.Show($"The saved game {savedGameName} exists, overwrite?", "Error", MessageBoxButton.YesNoCancel, MessageBoxImage.Information); if (result != MessageBoxResult.Yes) { return; } string savedGameTempDestination = savedGameDestination + "_" + ((int)new Random().Next(1, Int32.MaxValue)); Directory.Move(savedGameDestination, savedGameTempDestination); Directory.Delete(savedGameTempDestination, true); } Directory.Move(tempBackupDirectory, savedGameDestination); MessageBoxResult openResult = MessageBox.Show("Backup restored. Open it now?", "Success", MessageBoxButton.YesNo); if (openResult == MessageBoxResult.Yes) { SavedGame savedGame = OpenGameWindow.GetSavedGameFromPath(savedGameDestination); OpenSavedGame(savedGame); } } else { MessageBox.Show($"Backup appears to be malformed.", "Error"); } } catch (Exception err) { MessageBox.Show($"Unable to restore backup. ({err.Message})", "Error"); } } }
private void OpenMenu_Click(object sender, RoutedEventArgs e) { OpenGameWindow openGameWindow = new OpenGameWindow(); bool didOpen = openGameWindow.ShowDialog() ?? false; if (didOpen) { SavedGame savedGame = openGameWindow.SelectedSavedGame; if (savedGame == null) { MessageBox.Show("No saved game selected.", "Error"); } else { OpenSavedGame(savedGame); } } }