Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
</StackPanel>
</xctk:SplitButton.DropDownContent>
</xctk:SplitButton>
<Button Name="Btn_save_as"
Margin="8, 0, 0, 0"
HorizontalAlignment="Left"
Content="Save As"
Click="Btn_save_as_Click"/>
<Button Margin="8,0,0,0"
HorizontalAlignment="Left"
Click="Btn_chunk_search_Click">
Expand Down
4 changes: 4 additions & 0 deletions Windows/MainWindow.xaml.buttons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
24 changes: 23 additions & 1 deletion Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down