From 6d6e9f4749b6e18c776bc8f05fa4ac066872fd22 Mon Sep 17 00:00:00 2001 From: Chev <11602755+chev2@users.noreply.github.com> Date: Sat, 16 Jan 2021 22:40:05 -0800 Subject: [PATCH] SARC tab - add save & save as functionality --- botw-toolset/Control/TabSARC.xaml | 61 ++++++++++++++-------------- botw-toolset/Control/TabSARC.xaml.cs | 43 +++++++++++++++++++- 2 files changed, 73 insertions(+), 31 deletions(-) diff --git a/botw-toolset/Control/TabSARC.xaml b/botw-toolset/Control/TabSARC.xaml index f77c4f4..1046281 100644 --- a/botw-toolset/Control/TabSARC.xaml +++ b/botw-toolset/Control/TabSARC.xaml @@ -14,52 +14,53 @@ + - + - - diff --git a/botw-toolset/Control/TabSARC.xaml.cs b/botw-toolset/Control/TabSARC.xaml.cs index c5e50ab..d41c08d 100644 --- a/botw-toolset/Control/TabSARC.xaml.cs +++ b/botw-toolset/Control/TabSARC.xaml.cs @@ -1,6 +1,8 @@ using BOTWToolset.Debugging; using BOTWToolset.IO.SARC; using Microsoft.Win32; +using Microsoft.WindowsAPICodePack.Dialogs; +using System.IO; using System.Windows; using System.Windows.Controls; @@ -120,7 +122,7 @@ namespace BOTWToolset.Control { BOTWConsole.Log("Opening file"); - SARC s = SARC.ReadFile(openFileDialog.FileName); + SARC s = SARC.FromBytes(File.ReadAllBytes(openFileDialog.FileName)); // Set the current file location to the chosen file's location fileLocation = openFileDialog.FileName; @@ -134,6 +136,7 @@ namespace BOTWToolset.Control MenuFileClose.IsEnabled = true; MenuFileSave.IsEnabled = true; MenuFileSaveAs.IsEnabled = true; + MenuFileExportFiles.IsEnabled = true; } } @@ -153,16 +156,54 @@ namespace BOTWToolset.Control MenuFileClose.IsEnabled = false; MenuFileSave.IsEnabled = false; MenuFileSaveAs.IsEnabled = false; + MenuFileExportFiles.IsEnabled = false; } private void Menu_FileSave(object sender, RoutedEventArgs e) { + BOTWConsole.LogStatus($"Saved SARC to {fileLocation}."); + File.WriteAllBytes(fileLocation, SARC.ToBytes(currentSARC)); } private void Menu_FileSaveAs(object sender, RoutedEventArgs e) { + BOTWConsole.LogStatus($"Saving SARC as..."); + SaveFileDialog saveFileDialog = new SaveFileDialog + { + InitialDirectory = @"C:\", + RestoreDirectory = true, + Title = "Save SARC file", + Filter = "All files (*.*)|*.*" + }; + + if ((bool)saveFileDialog.ShowDialog()) + { + File.WriteAllBytes(saveFileDialog.FileName, SARC.ToBytes(currentSARC)); + + BOTWConsole.LogStatus($"Saved SARC to {saveFileDialog.FileName}."); + } + } + + private void Menu_FileExportFiles(object sender, RoutedEventArgs e) + { + BOTWConsole.LogStatus($"Exporting files to folder..."); + + CommonOpenFileDialog openFolderDialog = new CommonOpenFileDialog + { + InitialDirectory = @"C:\", + RestoreDirectory = true, + Title = "Export files to folder", + IsFolderPicker = true + }; + + if (openFolderDialog.ShowDialog() == CommonFileDialogResult.Ok) + { + SARC.WriteFiles(currentSARC, openFolderDialog.FileName); + + BOTWConsole.LogStatus($"Exported SARC files to {openFolderDialog.FileName}."); + } } } }