diff --git a/Windows/MainWindow.xaml b/Windows/MainWindow.xaml index 783af4c..691b27e 100644 --- a/Windows/MainWindow.xaml +++ b/Windows/MainWindow.xaml @@ -66,6 +66,11 @@ + diff --git a/Windows/MainWindow.xaml.buttons.cs b/Windows/MainWindow.xaml.buttons.cs index 8de1741..5a41360 100644 --- a/Windows/MainWindow.xaml.buttons.cs +++ b/Windows/MainWindow.xaml.buttons.cs @@ -42,6 +42,10 @@ private void Btn_save_as_json_merge_Click(object sender, RoutedEventArgs e) { SaveJson(true); } + private void Btn_save_as_Click(object sender, RoutedEventArgs e) { + SaveAs(); + } + private void Btn_chunk_search_Click(object sender, RoutedEventArgs e) { new FindFileInChunk().ShowDialog(); } diff --git a/Windows/MainWindow.xaml.cs b/Windows/MainWindow.xaml.cs index 87aafc3..9713191 100644 --- a/Windows/MainWindow.xaml.cs +++ b/Windows/MainWindow.xaml.cs @@ -332,12 +332,23 @@ public static void CheckHashAndSize(string targetFile) { } private async void Save() { + SaveTo(targetFile); + } + + private async void SaveAs() { if (string.IsNullOrEmpty(targetFile)) return; + SaveTo(GetSaveTargetForTargetFile()); + } + + private async void SaveTo(string file) { + if (string.IsNullOrEmpty(file)) return; try { var saveData = targetFileType.GetMethod("SaveData", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); Debug.Assert(saveData != null, nameof(saveData) + " != null"); - saveData.Invoke(null, new object[] {fileData, targetFile}); + saveData.Invoke(null, new object[] { fileData, file }); + targetFile = file; + Title = Path.GetFileName(file); await ShowChangesSaved(true); } catch (Exception e) when (!Debugger.IsAttached) { @@ -683,6 +694,17 @@ private string GetSaveTarget() { return sfdResult.ShowDialog() == true ? sfdResult.FileName : null; } + private string GetSaveTargetForTargetFile() { + var ext = Path.GetExtension(targetFile); + var sfdResult = new SaveFileDialog { + Filter = $"{ext.TrimStart('.').ToUpper()}|*{ext}", + FileName = $"{Path.GetFileNameWithoutExtension(targetFile)}", + InitialDirectory = targetFile == null ? string.Empty : Path.GetDirectoryName(targetFile) ?? string.Empty, + AddExtension = true + }; + return sfdResult.ShowDialog() == true ? sfdResult.FileName : null; + } + public static Type GetFileType(string targetFile) { var fileName = Path.GetFileName(targetFile).ToLower(); Debug.Assert(fileName != null, nameof(fileName) + " != null");