From f067350cd84120877c3d6d2377560c08e77bbb9f Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Wed, 21 Feb 2024 15:28:05 +0800 Subject: [PATCH] minor fix --- .../Snap.Hutao/Service/AppOptions.cs | 2 +- .../BackgroundImage/BackgroundImageService.cs | 18 ++- src/Snap.Hutao/Snap.Hutao/View/MainView.xaml | 4 +- .../Snap.Hutao/View/Page/SettingPage.xaml | 122 +++++++++--------- 4 files changed, 81 insertions(+), 65 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs index 43ea7cd5..34a082be 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs @@ -38,7 +38,7 @@ internal sealed partial class AppOptions : DbStoreOptions public BackgroundImageType BackgroundImageType { - get => GetOption(ref backgroundImageType, SettingEntry.BackgroundImageType, EnumParse, BackgroundImageType.HutaoOfficialLauncher).Value; + get => GetOption(ref backgroundImageType, SettingEntry.BackgroundImageType, EnumParse, BackgroundImageType.None).Value; set => SetOption(ref backgroundImageType, SettingEntry.BackgroundImageType, value, EnumToStringOrEmpty); } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/BackgroundImage/BackgroundImageService.cs b/src/Snap.Hutao/Snap.Hutao/Service/BackgroundImage/BackgroundImageService.cs index 530eca28..8421c5db 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/BackgroundImage/BackgroundImageService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/BackgroundImage/BackgroundImageService.cs @@ -7,7 +7,9 @@ using Snap.Hutao.Core.Caching; using Snap.Hutao.Core.IO; using Snap.Hutao.Web.Hutao.Wallpaper; using Snap.Hutao.Web.Response; +using Snap.Hutao.Win32.Foundation; using System.IO; +using System.Runtime.InteropServices; using Windows.Graphics.Imaging; namespace Snap.Hutao.Service.BackgroundImage; @@ -44,7 +46,21 @@ internal sealed partial class BackgroundImageService : IBackgroundImageService using (FileStream fileStream = File.OpenRead(path)) { - BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream()); + BitmapDecoder decoder; + try + { + decoder = await BitmapDecoder.CreateAsync(fileStream.AsRandomAccessStream()); + } + catch (COMException comException) + { + if (comException.HResult != HRESULT.E_FAIL) + { + throw; + } + + return new(false, default!); + } + SoftwareBitmap softwareBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight); Bgra32 accentColor = softwareBitmap.GetAccentColor(); diff --git a/src/Snap.Hutao/Snap.Hutao/View/MainView.xaml b/src/Snap.Hutao/Snap.Hutao/View/MainView.xaml index 2531acc4..a390a9e2 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/MainView.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/MainView.xaml @@ -31,8 +31,8 @@ diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index 214288e8..d8c45e0f 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -327,6 +327,67 @@ + + + + + + +