From 68a385159538edece2eefe63711d52b30b114a7e Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Sat, 18 Nov 2023 22:47:09 +0800 Subject: [PATCH] refine #1096 --- .../Snap.Hutao/Core/IO/PickerExtension.cs | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Core/IO/PickerExtension.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Core/IO/PickerExtension.cs b/src/Snap.Hutao/Snap.Hutao/Core/IO/PickerExtension.cs deleted file mode 100644 index 1dda04d6fd..0000000000 --- a/src/Snap.Hutao/Snap.Hutao/Core/IO/PickerExtension.cs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Service.Notification; -using Windows.Storage; -using Windows.Storage.Pickers; - -namespace Snap.Hutao.Core.IO; - -/// -/// 选择器拓展 -/// -internal static class PickerExtension -{ - /// - public static async ValueTask> TryPickSingleFileAsync(this FileOpenPicker picker) - { - StorageFile? file; - Exception? exception = null; - try - { - file = await picker.PickSingleFileAsync().AsTask().ConfigureAwait(false); - } - catch (Exception ex) - { - exception = ex; - file = null; - } - - if (file is not null) - { - return new(true, file.Path); - } - else - { - InfoBarWaringPickerException(exception); - return new(false, default!); - } - } - - /// - public static async ValueTask> TryPickSaveFileAsync(this FileSavePicker picker) - { - StorageFile? file; - Exception? exception = null; - try - { - file = await picker.PickSaveFileAsync().AsTask().ConfigureAwait(false); - } - catch (Exception ex) - { - exception = ex; - file = null; - } - - if (file is not null) - { - return new(true, file.Path); - } - else - { - InfoBarWaringPickerException(exception); - return new(false, default!); - } - } - - /// - public static async ValueTask> TryPickSingleFolderAsync(this FolderPicker picker) - { - StorageFolder? folder; - Exception? exception = null; - try - { - folder = await picker.PickSingleFolderAsync().AsTask().ConfigureAwait(false); - } - catch (Exception ex) - { - exception = ex; - folder = null; - } - - if (folder is not null) - { - return new(true, folder.Path); - } - else - { - InfoBarWaringPickerException(exception); - return new(false, default!); - } - } - - private static void InfoBarWaringPickerException(Exception? exception) - { - if (exception is not null) - { - Ioc.Default - .GetRequiredService() - .Warning( - SH.CoreIOPickerExtensionPickerExceptionInfoBarTitle, - SH.FormatCoreIOPickerExtensionPickerExceptionInfoBarMessage(exception.Message)); - } - } -} \ No newline at end of file