From 81de9bc02eaba83eb84e37a28b3acdb59e2d8d0b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 2 May 2024 00:50:34 +0100 Subject: [PATCH] [GUI] Replace file dialogs with file pickers. --- Aaru.Gui/FilePickerFileTypes.cs | 82 ++++++++++ .../ViewModels/Dialogs/ConsoleViewModel.cs | 23 +-- .../ViewModels/Panels/DeviceInfoViewModel.cs | 22 +-- .../ViewModels/Panels/MediaInfoViewModel.cs | 22 +-- .../Panels/SubdirectoryViewModel.cs | 17 ++- Aaru.Gui/ViewModels/Tabs/AtaInfoViewModel.cs | 42 ++---- .../ViewModels/Tabs/BlurayInfoViewModel.cs | 22 +-- .../Tabs/CompactDiscInfoViewModel.cs | 141 ++++++------------ Aaru.Gui/ViewModels/Tabs/DvdInfoViewModel.cs | 22 +-- .../Tabs/DvdWritableInfoViewModel.cs | 22 +-- .../ViewModels/Tabs/PcmciaInfoViewModel.cs | 22 +-- Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs | 121 +++++---------- Aaru.Gui/ViewModels/Tabs/XboxInfoViewModel.cs | 22 +-- .../Windows/ImageConvertViewModel.cs | 95 +++++------- .../Windows/ImageSidecarViewModel.cs | 29 ++-- .../ViewModels/Windows/MainWindowViewModel.cs | 23 +-- .../ViewModels/Windows/MediaDumpViewModel.cs | 62 ++++---- Aaru.Localization/UI.Designer.cs | 18 +++ Aaru.Localization/UI.es.resx | 6 + Aaru.Localization/UI.resx | 6 + 20 files changed, 370 insertions(+), 449 deletions(-) create mode 100644 Aaru.Gui/FilePickerFileTypes.cs diff --git a/Aaru.Gui/FilePickerFileTypes.cs b/Aaru.Gui/FilePickerFileTypes.cs new file mode 100644 index 000000000..fb367e412 --- /dev/null +++ b/Aaru.Gui/FilePickerFileTypes.cs @@ -0,0 +1,82 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : FilePickerFileTypes.cs +// Author(s) : Natalia Portillo +// +// Component : GUI. +// +// --[ Description ] ---------------------------------------------------------- +// +// Common file types to use with Avalonia file pickers. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General public License for more details. +// +// You should have received a copy of the GNU General public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2024 Natalia Portillo +// ****************************************************************************/ + +using Aaru.Localization; +using Avalonia.Platform.Storage; + +namespace Aaru.Gui; + +/// +/// Dictionary of well known file types. +/// +public static class FilePickerFileTypes +{ + public static FilePickerFileType All { get; } = new(UI.Dialog_All_files) + { + Patterns = ["*.*"], + MimeTypes = ["*/*"] + }; + + public static FilePickerFileType PlainText { get; } = new(UI.Dialog_Text_files) + { + Patterns = ["*.txt"], + AppleUniformTypeIdentifiers = ["public.plain-text"], + MimeTypes = ["text/plain"] + }; + + public static FilePickerFileType Log { get; } = new(UI.Dialog_Log_files) + { + Patterns = ["*.log"], + AppleUniformTypeIdentifiers = ["public.plain-text"], + MimeTypes = ["text/plain"] + }; + + public static FilePickerFileType Binary { get; } = new(UI.Dialog_Binary_files) + { + Patterns = ["*.bin"], + MimeTypes = ["application/octet-stream"] + }; + + public static FilePickerFileType AaruMetadata { get; } = new(UI.Dialog_Aaru_Metadata) + { + Patterns = ["*.json"], + AppleUniformTypeIdentifiers = ["public.json"], + MimeTypes = ["application/json"] + }; + + public static FilePickerFileType AaruResumeFile { get; } = new(UI.Dialog_Aaru_Resume) + { + Patterns = ["*.json"], + AppleUniformTypeIdentifiers = ["public.json"], + MimeTypes = ["application/json"] + }; +} \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs b/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs index e6580c07f..98f7f3d75 100644 --- a/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs +++ b/Aaru.Gui/ViewModels/Dialogs/ConsoleViewModel.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Reactive; @@ -39,7 +40,7 @@ using Aaru.CommonTypes.Interop; using Aaru.Console; using Aaru.Localization; -using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using MsBox.Avalonia; using MsBox.Avalonia.Enums; @@ -94,27 +95,19 @@ public bool DebugChecked async Task ExecuteSaveCommand() { - var dlgSave = new SaveFileDialog(); - - dlgSave.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "log" - } - ], - Name = UI.Dialog_Log_files + FileTypeChoices = new List + { + FilePickerFileTypes.Log + } }); - string result = await dlgSave.ShowAsync(_view); - if(result is null) return; try { - var logFs = new FileStream(result, FileMode.Create, FileAccess.ReadWrite); + var logFs = new FileStream(result.Path.AbsolutePath, FileMode.Create, FileAccess.ReadWrite); var logSw = new StreamWriter(logFs); logSw.WriteLine(UI.Log_saved_at_0, DateTime.Now); diff --git a/Aaru.Gui/ViewModels/Panels/DeviceInfoViewModel.cs b/Aaru.Gui/ViewModels/Panels/DeviceInfoViewModel.cs index fca3d0b8f..308c06670 100644 --- a/Aaru.Gui/ViewModels/Panels/DeviceInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Panels/DeviceInfoViewModel.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; @@ -40,6 +41,7 @@ using Aaru.Gui.Views.Tabs; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using Humanizer; using Humanizer.Localisation; using ReactiveUI; @@ -1018,25 +1020,17 @@ public SdMmcInfo SdMmcInfo async Task ExecuteSaveUsbDescriptorsCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_devInfo.UsbDescriptors, 0, _devInfo.UsbDescriptors.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs b/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs index 5f2aec40f..1d19aaf4b 100644 --- a/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Panels/MediaInfoViewModel.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Text; @@ -43,6 +44,7 @@ using Avalonia.Controls; using Avalonia.Media.Imaging; using Avalonia.Platform; +using Avalonia.Platform.Storage; using Humanizer.Bytes; using MsBox.Avalonia; using MsBox.Avalonia.Enums; @@ -388,25 +390,17 @@ public BlurayInfo BlurayInfo async Task SaveElement(byte[] data) { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(data, 0, data.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Panels/SubdirectoryViewModel.cs b/Aaru.Gui/ViewModels/Panels/SubdirectoryViewModel.cs index bf7a7ec3e..c03c4d9a9 100644 --- a/Aaru.Gui/ViewModels/Panels/SubdirectoryViewModel.cs +++ b/Aaru.Gui/ViewModels/Panels/SubdirectoryViewModel.cs @@ -46,6 +46,7 @@ using Aaru.Gui.Models; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using MsBox.Avalonia; using MsBox.Avalonia.Enums; @@ -141,18 +142,18 @@ async Task ExecuteExtractFilesCommand() { if(SelectedEntries.Count == 0) return; - var saveFilesFolderDialog = new OpenFolderDialog - { - Title = UI.Dialog_Choose_destination_folder - }; - - string result = await saveFilesFolderDialog.ShowAsync(_view); + IReadOnlyList result = + await _view.StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions + { + Title = UI.Dialog_Choose_destination_folder, + AllowMultiple = false + }); - if(result is null) return; + if(result.Count != 1) return; Statistics.AddCommand("extract-files"); - string folder = saveFilesFolderDialog.Directory; + string folder = result[0].Path.AbsolutePath; foreach(FileModel file in SelectedEntries) { diff --git a/Aaru.Gui/ViewModels/Tabs/AtaInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/AtaInfoViewModel.cs index b4a7e5db1..8c5024aab 100644 --- a/Aaru.Gui/ViewModels/Tabs/AtaInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/AtaInfoViewModel.cs @@ -30,12 +30,14 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; using Aaru.Decoders.ATA; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using ReactiveUI; @@ -112,25 +114,17 @@ public AtaInfoViewModel([CanBeNull] byte[] ataIdentify, byte[] atapiIdentify, At async Task ExecuteSaveAtaBinaryCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); if(_ata != null) saveFs.Write(_ata, 0, _ata.Length); @@ -141,25 +135,17 @@ async Task ExecuteSaveAtaBinaryCommand() async Task ExecuteSaveAtaTextCommand() { - var dlgSaveText = new SaveFileDialog(); - - dlgSaveText.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.txt" - } - ], - Name = UI.Dialog_Text_files + FileTypeChoices = new List + { + FilePickerFileTypes.PlainText + } }); - string result = await dlgSaveText.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); var saveSw = new StreamWriter(saveFs); await saveSw.WriteAsync(AtaIdentifyText); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/BlurayInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/BlurayInfoViewModel.cs index 87dd35109..8092a3f81 100644 --- a/Aaru.Gui/ViewModels/Tabs/BlurayInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/BlurayInfoViewModel.cs @@ -30,6 +30,7 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; @@ -37,6 +38,7 @@ using Aaru.Decoders.SCSI.MMC; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using ReactiveUI; @@ -174,25 +176,17 @@ public BlurayInfoViewModel([CanBeNull] byte[] blurayDiscInformation, [CanBe async Task SaveElement(byte[] data) { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(data, 0, data.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/CompactDiscInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/CompactDiscInfoViewModel.cs index e9e5fbc54..271b63748 100644 --- a/Aaru.Gui/ViewModels/Tabs/CompactDiscInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/CompactDiscInfoViewModel.cs @@ -40,6 +40,7 @@ using Aaru.Gui.Models; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using ReactiveUI; namespace Aaru.Gui.ViewModels.Tabs; @@ -149,25 +150,17 @@ public CompactDiscInfoViewModel(byte[] toc, byte[] atip, byte[] compactDiscInfor async Task ExecuteSaveCdInformationCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_compactDiscInformationData, 0, _compactDiscInformationData.Length); saveFs.Close(); @@ -175,25 +168,17 @@ async Task ExecuteSaveCdInformationCommand() async Task ExecuteSaveCdTocCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_tocData, 0, _tocData.Length); saveFs.Close(); @@ -201,25 +186,17 @@ async Task ExecuteSaveCdTocCommand() async Task ExecuteSaveCdFullTocCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_rawTocData, 0, _rawTocData.Length); saveFs.Close(); @@ -227,25 +204,17 @@ async Task ExecuteSaveCdFullTocCommand() async Task ExecuteSaveCdSessionCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_sessionData, 0, _sessionData.Length); saveFs.Close(); @@ -253,25 +222,17 @@ async Task ExecuteSaveCdSessionCommand() async Task ExecuteSaveCdTextCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_cdTextLeadInData, 0, _cdTextLeadInData.Length); saveFs.Close(); @@ -279,25 +240,17 @@ async Task ExecuteSaveCdTextCommand() async Task ExecuteSaveCdAtipCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_atipData, 0, _atipData.Length); saveFs.Close(); @@ -305,25 +258,17 @@ async Task ExecuteSaveCdAtipCommand() async Task ExecuteSaveCdPmaCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_pmaData, 0, _pmaData.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/DvdInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/DvdInfoViewModel.cs index 88e43b78f..8488bc991 100644 --- a/Aaru.Gui/ViewModels/Tabs/DvdInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/DvdInfoViewModel.cs @@ -30,12 +30,14 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; using Aaru.Decoders.DVD; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using ReactiveUI; @@ -124,25 +126,17 @@ public DvdInfoViewModel([CanBeNull] byte[] pfi, [CanBeNull] byte[] dmi, [CanBeNu async Task SaveElement(byte[] data) { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(data, 0, data.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/DvdWritableInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/DvdWritableInfoViewModel.cs index 4b9b87fe0..41c87df08 100644 --- a/Aaru.Gui/ViewModels/Tabs/DvdWritableInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/DvdWritableInfoViewModel.cs @@ -30,12 +30,14 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; using Aaru.Decoders.DVD; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using ReactiveUI; namespace Aaru.Gui.ViewModels.Tabs; @@ -250,25 +252,17 @@ public DvdWritableInfoViewModel(byte[] dds, byte[] cartridgeStatus, byte[] spare async Task SaveElement(byte[] data) { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(data, 0, data.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs index eb25de710..1da52c1ab 100644 --- a/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/PcmciaInfoViewModel.cs @@ -30,6 +30,7 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Reactive; @@ -39,6 +40,7 @@ using Aaru.Gui.Models; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using ReactiveUI; @@ -175,25 +177,17 @@ public PcmciaCisModel SelectedCis async Task ExecuteSavePcmciaCisCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_cis, 0, _cis.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs index a266e1ae0..607f546de 100644 --- a/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/ScsiInfoViewModel.cs @@ -44,6 +44,7 @@ using Aaru.Helpers; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using ReactiveUI; using Inquiry = Aaru.CommonTypes.Structs.Devices.SCSI.Inquiry; @@ -801,25 +802,17 @@ public string MmcFeatureText async Task ExecuteSaveInquiryBinaryCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(InquiryData, 0, InquiryData.Length); saveFs.Close(); @@ -827,25 +820,17 @@ async Task ExecuteSaveInquiryBinaryCommand() async Task ExecuteSaveInquiryTextCommand() { - var dlgSaveText = new SaveFileDialog(); - - dlgSaveText.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.txt" - } - ], - Name = UI.Dialog_Text_files + FileTypeChoices = new List + { + FilePickerFileTypes.PlainText + } }); - string result = await dlgSaveText.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); var saveSw = new StreamWriter(saveFs); await saveSw.WriteAsync(ScsiInquiryText); saveFs.Close(); @@ -853,25 +838,17 @@ async Task ExecuteSaveInquiryTextCommand() async Task ExecuteSaveModeSense6Command() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_scsiModeSense6, 0, _scsiModeSense6.Length); saveFs.Close(); @@ -879,25 +856,17 @@ async Task ExecuteSaveModeSense6Command() async Task ExecuteSaveModeSense10Command() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_scsiModeSense10, 0, _scsiModeSense10.Length); saveFs.Close(); @@ -907,25 +876,17 @@ async Task ExecuteSaveEvpdPageCommand() { if(SelectedEvpdPage is not ScsiPageModel pageModel) return; - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(pageModel.Data, 0, pageModel.Data.Length); saveFs.Close(); @@ -933,25 +894,17 @@ async Task ExecuteSaveEvpdPageCommand() async Task ExecuteSaveMmcFeaturesCommand() { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(_configuration, 0, _configuration.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Tabs/XboxInfoViewModel.cs b/Aaru.Gui/ViewModels/Tabs/XboxInfoViewModel.cs index 83a980b41..737629fbd 100644 --- a/Aaru.Gui/ViewModels/Tabs/XboxInfoViewModel.cs +++ b/Aaru.Gui/ViewModels/Tabs/XboxInfoViewModel.cs @@ -30,6 +30,7 @@ // Copyright © 2011-2024 Natalia Portillo // ****************************************************************************/ +using System.Collections.Generic; using System.IO; using System.Reactive; using System.Threading.Tasks; @@ -37,6 +38,7 @@ using Aaru.Decoders.Xbox; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using ReactiveUI; @@ -101,25 +103,17 @@ public XboxInfoViewModel([CanBeNull] XgdInfo xgdInfo, [CanBeNull] byte[] dmi, [C async Task SaveElement(byte[] data) { - var dlgSaveBinary = new SaveFileDialog(); - - dlgSaveBinary.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Extensions = - [ - ..new[] - { - "*.bin" - } - ], - Name = UI.Dialog_Binary_files + FileTypeChoices = new List + { + FilePickerFileTypes.Binary + } }); - string result = await dlgSaveBinary.ShowAsync(_view); - if(result is null) return; - var saveFs = new FileStream(result, FileMode.Create); + var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create); saveFs.Write(data, 0, data.Length); saveFs.Close(); diff --git a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs index abb7401f9..23a5a7694 100644 --- a/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ImageConvertViewModel.cs @@ -53,6 +53,7 @@ using Aaru.Gui.Models; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using Avalonia.Threading; using MsBox.Avalonia; using MsBox.Avalonia.Enums; @@ -2049,29 +2050,29 @@ async Task ExecuteDestinationCommand() { if(SelectedPlugin is null) return; - var dlgDestination = new SaveFileDialog + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Title = UI.Dialog_Choose_destination_file - }; - - dlgDestination.Filters?.Add(new FileDialogFilter - { - Name = SelectedPlugin.Plugin.Name, - Extensions = SelectedPlugin.Plugin.KnownExtensions.ToList() + Title = UI.Dialog_Choose_destination_file, + FileTypeChoices = new List + { + new(SelectedPlugin.Plugin.Name) + { + Patterns = SelectedPlugin.Plugin.KnownExtensions.ToList() + } + } }); - string result = await dlgDestination.ShowAsync(_view); - - if(result is null || result.Length != 1) + if(result is null) { DestinationText = ""; return; } - if(string.IsNullOrEmpty(Path.GetExtension(result))) result += SelectedPlugin.Plugin.KnownExtensions.First(); + DestinationText = result.Path.AbsolutePath; - DestinationText = result; + if(string.IsNullOrEmpty(Path.GetExtension(DestinationText))) + DestinationText += SelectedPlugin.Plugin.KnownExtensions.First(); } void ExecuteCreatorCommand() => CreatorText = _inputFormat.Info.Creator; @@ -2113,37 +2114,29 @@ async Task ExecuteAaruMetadataCommand() _aaruMetadata = null; MetadataJsonText = ""; - var dlgMetadata = new OpenFileDialog - { - Title = UI.Dialog_Choose_existing_metadata_sidecar - }; - - dlgMetadata.Filters?.Add(new FileDialogFilter - { - Name = UI.Dialog_Aaru_Metadata, - Extensions = - [ - ..new[] - { - ".json" - } - ] - }); - - string[] result = await dlgMetadata.ShowAsync(_view); + IReadOnlyList result = _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = UI.Dialog_Choose_existing_metadata_sidecar, + AllowMultiple = false, + FileTypeFilter = new List + { + FilePickerFileTypes.AaruMetadata + } + }) + .Result; - if(result is null || result.Length != 1) return; + if(result.Count != 1) return; try { - var fs = new FileStream(result[0], FileMode.Open); + var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open); _aaruMetadata = (await JsonSerializer.DeserializeAsync(fs, typeof(MetadataJson), MetadataJsonContext.Default) as MetadataJson)?.AaruMetadata; fs.Close(); - MetadataJsonText = result[0]; + MetadataJsonText = result[0].Path.AbsolutePath; } catch { @@ -2164,30 +2157,22 @@ async Task ExecuteResumeFileCommand() _dumpHardware = null; ResumeFileText = ""; - var dlgMetadata = new OpenFileDialog - { - Title = UI.Dialog_Choose_existing_resume_file - }; - - dlgMetadata.Filters?.Add(new FileDialogFilter - { - Name = UI.Dialog_Choose_existing_resume_file, - Extensions = - [ - ..new[] - { - ".json" - } - ] - }); - - string[] result = await dlgMetadata.ShowAsync(_view); + IReadOnlyList result = _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = UI.Dialog_Choose_existing_resume_file, + AllowMultiple = false, + FileTypeFilter = new List + { + FilePickerFileTypes.AaruResumeFile + } + }) + .Result; - if(result is null || result.Length != 1) return; + if(result.Count != 1) return; try { - var fs = new FileStream(result[0], FileMode.Open); + var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open); Resume resume = (await JsonSerializer.DeserializeAsync(fs, typeof(ResumeJson), ResumeJsonContext.Default) as ResumeJson) @@ -2198,7 +2183,7 @@ async Task ExecuteResumeFileCommand() if(resume?.Tries?.Any() == false) { _dumpHardware = resume.Tries; - ResumeFileText = result[0]; + ResumeFileText = result[0].Path.AbsolutePath; } else { diff --git a/Aaru.Gui/ViewModels/Windows/ImageSidecarViewModel.cs b/Aaru.Gui/ViewModels/Windows/ImageSidecarViewModel.cs index 730291913..f5de6f9d1 100644 --- a/Aaru.Gui/ViewModels/Windows/ImageSidecarViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/ImageSidecarViewModel.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Reactive; @@ -44,6 +45,7 @@ using Aaru.Core; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using Avalonia.Threading; using ReactiveUI; @@ -322,25 +324,15 @@ void ExecuteStopCommand() async Task ExecuteDestinationCommand() { - var dlgDestination = new SaveFileDialog + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Title = UI.Dialog_Choose_destination_file - }; - - dlgDestination.Filters?.Add(new FileDialogFilter - { - Name = UI.Dialog_Aaru_Metadata, - Extensions = - [ - ..new[] - { - "*.json" - } - ] + Title = UI.Dialog_Choose_destination_file, + FileTypeChoices = new List + { + FilePickerFileTypes.AaruMetadata + } }); - string result = await dlgDestination.ShowAsync(_view); - if(result is null) { DestinationText = ""; @@ -348,8 +340,7 @@ async Task ExecuteDestinationCommand() return; } - if(string.IsNullOrEmpty(Path.GetExtension(result))) result += ".json"; - - DestinationText = result; + DestinationText = result.Path.AbsolutePath; + if(string.IsNullOrEmpty(Path.GetExtension(DestinationText))) DestinationText += ".json"; } } \ No newline at end of file diff --git a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs index 1c9de961d..f81762a90 100644 --- a/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MainWindowViewModel.cs @@ -59,6 +59,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media.Imaging; using Avalonia.Platform; +using Avalonia.Platform.Storage; using JetBrains.Annotations; using MsBox.Avalonia; using MsBox.Avalonia.Enums; @@ -530,17 +531,19 @@ void ExecuteConsoleCommand() async Task ExecuteOpenCommand() { // TODO: Extensions - var dlgOpenImage = new OpenFileDialog + IReadOnlyList result = await _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions { Title = UI.Dialog_Choose_image_to_open, - AllowMultiple = false - }; - - string[] result = await dlgOpenImage.ShowAsync(_view); + AllowMultiple = false, + FileTypeFilter = new List + { + FilePickerFileTypes.All + } + }); - if(result?.Length != 1) return; + if(result.Count != 1) return; - IFilter inputFilter = PluginRegister.Singleton.GetFilter(result[0]); + IFilter inputFilter = PluginRegister.Singleton.GetFilter(result[0].Path.AbsolutePath); if(inputFilter == null) { @@ -587,7 +590,7 @@ async Task ExecuteOpenCommand() var imageModel = new ImageModel { - Path = result[0], + Path = result[0].Path.AbsolutePath, Icon = AssetLoader.Exists(mediaResource) ? new Bitmap(AssetLoader.Open(mediaResource)) : imageFormat.Info.MetadataMediaType == MetadataMediaType.BlockMedia @@ -595,9 +598,9 @@ async Task ExecuteOpenCommand() : imageFormat.Info.MetadataMediaType == MetadataMediaType.OpticalDisc ? _genericOpticalIcon : _genericFolderIcon, - FileName = Path.GetFileName(result[0]), + FileName = Path.GetFileName(result[0].Path.AbsolutePath), Image = imageFormat, - ViewModel = new ImageInfoViewModel(result[0], inputFilter, imageFormat, _view), + ViewModel = new ImageInfoViewModel(result[0].Path.AbsolutePath, inputFilter, imageFormat, _view), Filter = inputFilter }; diff --git a/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs b/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs index c005ac37a..cd8852027 100644 --- a/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs +++ b/Aaru.Gui/ViewModels/Windows/MediaDumpViewModel.cs @@ -55,6 +55,7 @@ using Aaru.Gui.Models; using Aaru.Localization; using Avalonia.Controls; +using Avalonia.Platform.Storage; using Avalonia.Threading; using DynamicData; using JetBrains.Annotations; @@ -505,26 +506,18 @@ public bool ExistingMetadata return; } - var dlgMetadata = new OpenFileDialog - { - Title = UI.Dialog_Choose_existing_metadata_sidecar - }; - - dlgMetadata.Filters?.Add(new FileDialogFilter - { - Name = UI.Dialog_Aaru_Metadata, - Extensions = - [ - ..new[] - { - ".json" - } - ] - }); - - string[] result = dlgMetadata.ShowAsync(_view).Result; - - if(result?.Length != 1) + IReadOnlyList result = _view.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions + { + Title = UI.Dialog_Choose_existing_metadata_sidecar, + AllowMultiple = false, + FileTypeFilter = new List + { + FilePickerFileTypes.AaruMetadata + } + }) + .Result; + + if(result.Count != 1) { ExistingMetadata = false; @@ -533,7 +526,7 @@ public bool ExistingMetadata try { - var fs = new FileStream(result[0], FileMode.Open); + var fs = new FileStream(result[0].Path.AbsolutePath, FileMode.Open); _sidecar = (JsonSerializer.Deserialize(fs, typeof(MetadataJson), MetadataJsonContext.Default) as MetadataJson) @@ -668,19 +661,18 @@ async Task ExecuteDestinationCommand() { if(SelectedPlugin is null) return; - var dlgDestination = new SaveFileDialog - { - Title = UI.Dialog_Choose_destination_file - }; - - dlgDestination.Filters?.Add(new FileDialogFilter + IStorageFile result = await _view.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { - Name = SelectedPlugin.Plugin.Name, - Extensions = SelectedPlugin.Plugin.KnownExtensions.ToList() + Title = UI.Dialog_Choose_destination_file, + FileTypeChoices = new List + { + new(SelectedPlugin.Plugin.Name) + { + Patterns = SelectedPlugin.Plugin.KnownExtensions.ToList() + } + } }); - string result = await dlgDestination.ShowAsync(_view); - if(result is null) { Destination = ""; @@ -689,11 +681,13 @@ async Task ExecuteDestinationCommand() return; } - if(string.IsNullOrEmpty(Path.GetExtension(result))) result += SelectedPlugin.Plugin.KnownExtensions.First(); + Destination = result.Path.AbsolutePath; - Destination = result; + _outputPrefix = Path.Combine(Path.GetDirectoryName(Destination) ?? "", + Path.GetFileNameWithoutExtension(Destination)); - _outputPrefix = Path.Combine(Path.GetDirectoryName(result) ?? "", Path.GetFileNameWithoutExtension(result)); + if(string.IsNullOrEmpty(Path.GetExtension(Destination))) + Destination += SelectedPlugin.Plugin.KnownExtensions.First(); Resume = true; } diff --git a/Aaru.Localization/UI.Designer.cs b/Aaru.Localization/UI.Designer.cs index 862a54819..370c43ba0 100644 --- a/Aaru.Localization/UI.Designer.cs +++ b/Aaru.Localization/UI.Designer.cs @@ -2197,6 +2197,24 @@ public static string Dialog_Aaru_Metadata { } } + /// + /// Looks up a localized string similar to Aaru resume file. + /// + public static string Dialog_Aaru_Resume { + get { + return ResourceManager.GetString("Dialog_Aaru_Resume", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to All. + /// + public static string Dialog_All_files { + get { + return ResourceManager.GetString("Dialog_All_files", resourceCulture); + } + } + /// /// Looks up a localized string similar to Binary. /// diff --git a/Aaru.Localization/UI.es.resx b/Aaru.Localization/UI.es.resx index 5a7364218..e035b66b1 100644 --- a/Aaru.Localization/UI.es.resx +++ b/Aaru.Localization/UI.es.resx @@ -3029,4 +3029,10 @@ Probadores: CD PMA: + + Todos + + + Fichero de resumen de Aaru + \ No newline at end of file diff --git a/Aaru.Localization/UI.resx b/Aaru.Localization/UI.resx index df43342ed..d525c1194 100644 --- a/Aaru.Localization/UI.resx +++ b/Aaru.Localization/UI.resx @@ -3105,4 +3105,10 @@ Do you want to continue? CD PMA: + + All + + + Aaru resume file + \ No newline at end of file