diff --git a/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorkerOptions.cs b/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorkerOptions.cs index afa5ab83..21df6075 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorkerOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/IO/Http/Sharding/HttpShardCopyWorkerOptions.cs @@ -2,9 +2,9 @@ // Licensed under the MIT license. using Microsoft.Win32.SafeHandles; +using Snap.Hutao.Web.Request.Builder; using System.IO; using System.Net.Http; -using Snap.Hutao.Web.Request.Builder; namespace Snap.Hutao.Core.IO.Http.Sharding; diff --git a/src/Snap.Hutao/Snap.Hutao/Extension/WinRTExtension.cs b/src/Snap.Hutao/Snap.Hutao/Extension/WinRTExtension.cs index 608eb0a4..f07285eb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Extension/WinRTExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Extension/WinRTExtension.cs @@ -19,7 +19,7 @@ internal static class WinRTExtension } // protected bool disposed; - [UnsafeAccessor(UnsafeAccessorKind.Field, Name ="disposed")] + [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "disposed")] private static extern ref bool GetProtectedDisposed(IObjectReference objRef); // private object _disposedLock diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs index 1baf293c..56167c1b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Abstraction/DbStoreOptions.cs @@ -116,7 +116,7 @@ internal abstract partial class DbStoreOptions : ObservableObject, IOptions反序列化器 /// 默认值 /// - [return:NotNull] + [return: NotNull] protected T GetOption(ref T? storage, string key, Func deserializer, [DisallowNull] T defaultValue) { if (storage is not null) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs index 8e9f18a5..164971a4 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationDbService.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Internal; using Snap.Hutao.Core.Database; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.Entity.Database; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogDbService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogDbService.cs index cfa27516..4d6b8abb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogDbService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogDbService.cs @@ -287,7 +287,7 @@ internal sealed partial class GachaLogDbService : IGachaLogDbService Time = i.Time, Id = i.Id, }); - return [..result]; + return [.. result]; } } diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/AvatarProperty/AvatarPropertyViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/AvatarProperty/AvatarPropertyViewModel.cs index 2e8b94c8..c758b59f 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/AvatarProperty/AvatarPropertyViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/AvatarProperty/AvatarPropertyViewModel.cs @@ -279,41 +279,6 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I } } - [Command("ExportAsImageCommand")] - private async Task ExportAsImageAsync(FrameworkElement? element) - { - if (element is { IsLoaded: true }) - { - RenderTargetBitmap bitmap = new(); - await bitmap.RenderAsync(element); - - IBuffer buffer = await bitmap.GetPixelsAsync(); - bool clipboardOpened = false; - using (SoftwareBitmap softwareBitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, bitmap.PixelWidth, bitmap.PixelHeight)) - { - Bgra32 tint = appResourceProvider.GetResource("CompatBackgroundColor"); - softwareBitmap.NormalBlend(tint); - using (InMemoryRandomAccessStream memory = new()) - { - BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, memory); - encoder.SetSoftwareBitmap(softwareBitmap); - await encoder.FlushAsync(); - - clipboardOpened = clipboardInterop.SetBitmap(memory); - } - } - - if (clipboardOpened) - { - infoBarService.Success(SH.ViewModelAvatarPropertyExportImageSuccess); - } - else - { - infoBarService.Warning(SH.ViewModelAvatarPropertyOpenClipboardFail); - } - } - } - private async ValueTask CultivateCoreAsync(Model.Entity.User user, CalculatorAvatarPromotionDelta delta, AvatarView avatar) { Response consumptionResponse = await calculatorClient.ComputeAsync(user, delta).ConfigureAwait(false); @@ -352,4 +317,39 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I return CultivateCoreResult.Ok; } + + [Command("ExportAsImageCommand")] + private async Task ExportAsImageAsync(FrameworkElement? element) + { + if (element is { IsLoaded: true }) + { + RenderTargetBitmap bitmap = new(); + await bitmap.RenderAsync(element); + + IBuffer buffer = await bitmap.GetPixelsAsync(); + bool clipboardOpened = false; + using (SoftwareBitmap softwareBitmap = SoftwareBitmap.CreateCopyFromBuffer(buffer, BitmapPixelFormat.Bgra8, bitmap.PixelWidth, bitmap.PixelHeight)) + { + Bgra32 tint = appResourceProvider.GetResource("CompatBackgroundColor"); + softwareBitmap.NormalBlend(tint); + using (InMemoryRandomAccessStream memory = new()) + { + BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, memory); + encoder.SetSoftwareBitmap(softwareBitmap); + await encoder.FlushAsync(); + + clipboardOpened = clipboardInterop.SetBitmap(memory); + } + } + + if (clipboardOpened) + { + infoBarService.Success(SH.ViewModelAvatarPropertyExportImageSuccess); + } + else + { + infoBarService.Warning(SH.ViewModelAvatarPropertyOpenClipboardFail); + } + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Request/NameValueCollectionExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Request/NameValueCollectionExtension.cs index 8375b0ef..1ac71767 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Request/NameValueCollectionExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Request/NameValueCollectionExtension.cs @@ -18,21 +18,21 @@ internal static class NameValueCollectionExtension } StringBuilder sb = new(); - string?[] keys = collection.AllKeys; - for (int i = 0; i < count; i++) + foreach (string? key in collection.AllKeys) { - string? key = keys[i]; - if (collection.GetValues(key) is { } values) + if (collection.GetValues(key) is not { } values) { - foreach (ref readonly string value in values.AsSpan()) - { - if (!string.IsNullOrEmpty(key)) - { - sb.Append(key).Append('='); - } + continue; + } - sb.Append(HttpUtility.UrlEncode(value)).Append('&'); + foreach (ref readonly string value in values.AsSpan()) + { + if (!string.IsNullOrEmpty(key)) + { + sb.Append(key).Append('='); } + + sb.Append(HttpUtility.UrlEncode(value)).Append('&'); } }