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;