From d98113af8f1051eeb8a764df98808a1f23f3a878 Mon Sep 17 00:00:00 2001 From: ywmoyue Date: Sat, 26 Oct 2024 10:51:08 +0800 Subject: [PATCH] =?UTF-8?q?#884=20=E4=BF=AE=E5=A4=8DWin10=E4=B8=8B?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=B0=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E9=A1=B5=E8=83=8C=E6=99=AF=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BiliLite.UWP/Extensions/FileExtensions.cs | 14 ++++++++++++++ src/BiliLite.UWP/Pages/NewPage.xaml.cs | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/BiliLite.UWP/Extensions/FileExtensions.cs b/src/BiliLite.UWP/Extensions/FileExtensions.cs index 9544f523..05e36550 100644 --- a/src/BiliLite.UWP/Extensions/FileExtensions.cs +++ b/src/BiliLite.UWP/Extensions/FileExtensions.cs @@ -23,5 +23,19 @@ public static async Task GetExportFile(string fileTypeChoiceKey, st var file = await savePicker.PickSaveFileAsync(); return file; } + + public static async Task CheckFileExist(this string path) + { + try + { + var file = await StorageFile.GetFileFromPathAsync(path); + return file != null; + } + catch (Exception) + { + // 如果文件不存在或者路径无效,将捕获异常 + return false; + } + } } } diff --git a/src/BiliLite.UWP/Pages/NewPage.xaml.cs b/src/BiliLite.UWP/Pages/NewPage.xaml.cs index 7ec045ca..52ced345 100644 --- a/src/BiliLite.UWP/Pages/NewPage.xaml.cs +++ b/src/BiliLite.UWP/Pages/NewPage.xaml.cs @@ -41,7 +41,7 @@ private async void SetBackground() } else { - if (!File.Exists(background)) + if (!await background.CheckFileExist()) { Notify.ShowMessageToast("背景图片不存在,请重新设置"); return;