|
|
@@ -40,7 +40,20 @@ public static class FilePicker
|
|
|
{
|
|
|
Title = $"{TranslationHelper.Translation.OpenFileDialog} - PicView",
|
|
|
AllowMultiple = false,
|
|
|
- FileTypeFilter = [AllFileType, FilePickerFileTypes.ImageAll, ArchiveFileType]
|
|
|
+ FileTypeFilter = [
|
|
|
+ AllFileType,
|
|
|
+ FilePickerFileTypes.ImageAll,
|
|
|
+ JpegFileType,
|
|
|
+ PngFileType,
|
|
|
+ GifFileType,
|
|
|
+ BmpFileType,
|
|
|
+ WebpFileType,
|
|
|
+ TiffFileType,
|
|
|
+ AvifFileType,
|
|
|
+ HeicFileType,
|
|
|
+ HeifFileType,
|
|
|
+ SvgFileType,
|
|
|
+ ArchiveFileType]
|
|
|
};
|
|
|
IReadOnlyList<IStorageFile> files;
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
@@ -65,43 +78,117 @@ public static class FilePicker
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private static FilePickerFileType AllFileType { get; } = new(TranslationHelper.GetTranslation("SupportedFiles"))
|
|
|
+ private static FilePickerFileType AllFileType { get; } = new(TranslationHelper.GetTranslation("SupportedFiles")) // TODO: Get translation
|
|
|
{
|
|
|
Patterns = SupportedFiles.ConvertFilesToGlobFormat(),
|
|
|
AppleUniformTypeIdentifiers = ["public.image"],
|
|
|
MimeTypes = ["image/*"],
|
|
|
};
|
|
|
+
|
|
|
+ private static FilePickerFileType AvifFileType { get; } = new(".avif")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.avif"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.image"], // TODO: Get AppleUniformTypeIdentifiers for avif
|
|
|
+ MimeTypes = ["image/avif"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType TiffFileType { get; } = new(".tiff")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.tiff", "*.tif"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.tiff"],
|
|
|
+ MimeTypes = ["image/tiff"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType WebpFileType { get; } = new(".webp")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.webp"},
|
|
|
+ AppleUniformTypeIdentifiers = ["org.webmproject.webp"],
|
|
|
+ MimeTypes = ["image/webp"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType PngFileType { get; } = new(".png")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.png"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.png"],
|
|
|
+ MimeTypes = ["image/png"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType JpegFileType { get; } = new(".jpg")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.jpg","*.jpeg, *.jfif"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.jpeg"],
|
|
|
+ MimeTypes = ["image/jpeg"],
|
|
|
+ };
|
|
|
|
|
|
- private static FilePickerFileType ArchiveFileType { get; } = new(TranslationHelper.GetTranslation("SupportedFiles"))
|
|
|
+ private static FilePickerFileType ArchiveFileType { get; } = new(TranslationHelper.GetTranslation("Archives")) // TODO: Get translation
|
|
|
{
|
|
|
Patterns = SupportedFiles.ConvertArchivesToGlobFormat(),
|
|
|
AppleUniformTypeIdentifiers = ["public.archive"],
|
|
|
MimeTypes = ["archive/*"]
|
|
|
};
|
|
|
+
|
|
|
+ private static FilePickerFileType GifFileType { get; } = new(".gif")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.gif"},
|
|
|
+ AppleUniformTypeIdentifiers = ["com.compuserve.gif"],
|
|
|
+ MimeTypes = ["image/gif"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType BmpFileType { get; } = new(".bmp")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.bmp"},
|
|
|
+ AppleUniformTypeIdentifiers = ["com.microsoft.bmp"],
|
|
|
+ MimeTypes = ["image/bmp"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType SvgFileType { get; } = new(".svg")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.svg"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.svg-image"],
|
|
|
+ MimeTypes = ["image/svg+xml"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType HeicFileType { get; } = new(".heic")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.heic"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.heic"],
|
|
|
+ MimeTypes = ["image/heic"],
|
|
|
+ };
|
|
|
+
|
|
|
+ private static FilePickerFileType HeifFileType { get; } = new(".heif")
|
|
|
+ {
|
|
|
+ Patterns = new List<string>{"*.heif"},
|
|
|
+ AppleUniformTypeIdentifiers = ["public.heif"],
|
|
|
+ MimeTypes = ["image/heif"],
|
|
|
+ };
|
|
|
|
|
|
public static async Task PickAndSaveFileAsAsync(string? fileName, MainViewModel vm)
|
|
|
{
|
|
|
if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop ||
|
|
|
desktop.MainWindow?.StorageProvider is not { } provider)
|
|
|
throw new NullReferenceException("Missing StorageProvider instance.");
|
|
|
-
|
|
|
- IStorageFile? file;
|
|
|
- if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
|
- {
|
|
|
- file = await provider.SaveFilePickerAsync(new FilePickerSaveOptions());
|
|
|
- }
|
|
|
- else
|
|
|
+
|
|
|
+ var options = new FilePickerSaveOptions
|
|
|
{
|
|
|
- var options = new FilePickerSaveOptions
|
|
|
- {
|
|
|
- Title = $"{TranslationHelper.Translation.OpenFileDialog} - PicView",
|
|
|
- FileTypeChoices = [AllFileType, FilePickerFileTypes.ImageAll, ArchiveFileType],
|
|
|
- SuggestedFileName = string.IsNullOrWhiteSpace(fileName) ? Path.GetRandomFileName() : fileName,
|
|
|
- SuggestedStartLocation = await desktop.MainWindow.StorageProvider.TryGetFolderFromPathAsync(fileName)
|
|
|
+ Title = $"{TranslationHelper.Translation.OpenFileDialog} - PicView",
|
|
|
+ FileTypeChoices = [
|
|
|
+ AllFileType,
|
|
|
+ FilePickerFileTypes.ImageAll,
|
|
|
+ JpegFileType,
|
|
|
+ PngFileType,
|
|
|
+ GifFileType,
|
|
|
+ BmpFileType,
|
|
|
+ WebpFileType,
|
|
|
+ TiffFileType,
|
|
|
+ AvifFileType,
|
|
|
+ HeicFileType,
|
|
|
+ HeifFileType,
|
|
|
+ SvgFileType],
|
|
|
+ SuggestedFileName = string.IsNullOrWhiteSpace(fileName) ? Path.GetRandomFileName() : fileName,
|
|
|
+ SuggestedStartLocation = await desktop.MainWindow.StorageProvider.TryGetFolderFromPathAsync(fileName)
|
|
|
|
|
|
- };
|
|
|
- file = await provider.SaveFilePickerAsync(options);
|
|
|
- }
|
|
|
+ };
|
|
|
+ var file = await provider.SaveFilePickerAsync(options);
|
|
|
|
|
|
if (file is null)
|
|
|
{
|