[Refactor] Replace SaveFileDialog with StorageProvider for file saving

This commit is contained in:
2025-07-08 00:58:21 +01:00
parent 8c12694fd6
commit 7bc6da0780
2 changed files with 13 additions and 14 deletions

View File

@@ -275,17 +275,16 @@ public class MainWindowViewModel : ViewModelBase
{
if(SelectedRomSet == null) return;
var dlgSave = new SaveFileDialog
IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
InitialFileName = SelectedRomSet.Filename
};
string result = await dlgSave.ShowAsync(_view);
SuggestedFileName = SelectedRomSet.Filename,
SuggestedStartLocation = await _view.StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents)
});
if(result == null) return;
var dialog = new ExportDat();
var viewModel = new ExportDatViewModel(dialog, SelectedRomSet.Sha384, result);
var viewModel = new ExportDatViewModel(dialog, SelectedRomSet.Sha384, result.Path.LocalPath);
dialog.DataContext = viewModel;
_ = dialog.ShowDialog(_view);
}

View File

@@ -28,7 +28,6 @@ using System.Collections.Generic;
using System.IO;
using System.Reactive;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using Microsoft.EntityFrameworkCore;
@@ -216,16 +215,17 @@ public sealed class SettingsViewModel : ViewModelBase
async Task ExecuteDatabaseCommandAsync()
{
var dlgFile = new SaveFileDialog
IStorageFile resultFile = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
{
InitialFileName = "romrepo.db",
Directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
Title = Localization.ChooseDatabaseFile
};
SuggestedFileName = "romrepo.db",
SuggestedStartLocation = await _view.StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents),
Title = Localization.ChooseDatabaseFile,
ShowOverwritePrompt = true
});
string result = await dlgFile.ShowAsync(_view);
if(resultFile == null) return;
if(result == null) return;
string result = resultFile.Path.LocalPath;
if(File.Exists(result))
{