mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
code style
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Snap.Hutao.Test.BaseClassLibrary;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class UnsafeAccessorTest
|
||||
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_TestProperty")]
|
||||
private static extern int InternalGetInterfaceProperty(ITestInterface instance);
|
||||
|
||||
interface ITestInterface
|
||||
internal interface ITestInterface
|
||||
{
|
||||
internal int TestProperty { get; }
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Snap.Hutao.Control.Collection.AdvancedCollectionView;
|
||||
|
||||
internal sealed class VectorChangedEventArgs : IVectorChangedEventArgs
|
||||
{
|
||||
public VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = null!)
|
||||
public VectorChangedEventArgs(CollectionChange cc, int index = -1, object item = default!)
|
||||
{
|
||||
CollectionChange = cc;
|
||||
Index = (uint)index;
|
||||
|
||||
@@ -25,10 +25,7 @@ internal sealed class WrapLayoutState
|
||||
|
||||
public WrapItem GetItemAt(int index)
|
||||
{
|
||||
if (index < 0)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(index);
|
||||
|
||||
if (index <= (items.Count - 1))
|
||||
{
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
/// <summary>
|
||||
/// 数据库损坏异常
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Obsolete("Use HutaoException instead")]
|
||||
internal sealed class DatabaseCorruptedException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造一个新的用户数据损坏异常
|
||||
/// </summary>
|
||||
/// <param name="message">消息</param>
|
||||
/// <param name="innerException">内部错误</param>
|
||||
public DatabaseCorruptedException(string message, Exception? innerException)
|
||||
: base(SH.FormatCoreExceptionServiceDatabaseCorruptedMessage($"{message}\n{innerException?.Message}"), innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
internal sealed class HutaoException : Exception
|
||||
@@ -11,11 +13,13 @@ internal sealed class HutaoException : Exception
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static HutaoException Throw(string message, Exception? innerException = default)
|
||||
{
|
||||
throw new HutaoException(message, innerException);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void ThrowIf([DoesNotReturnIf(true)] bool condition, string message, Exception? innerException = default)
|
||||
{
|
||||
if (condition)
|
||||
@@ -24,6 +28,7 @@ internal sealed class HutaoException : Exception
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void ThrowIfNot([DoesNotReturnIf(false)] bool condition, string message, Exception? innerException = default)
|
||||
{
|
||||
if (!condition)
|
||||
@@ -33,18 +38,28 @@ internal sealed class HutaoException : Exception
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static ArgumentException Argument(string message, string? paramName)
|
||||
{
|
||||
throw new ArgumentException(message, paramName);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static HutaoException GachaStatisticsInvalidItemId(uint id, Exception? innerException = default)
|
||||
{
|
||||
throw new HutaoException(SH.FormatServiceGachaStatisticsFactoryItemIdInvalid(id), innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static HutaoException UserdataCorrupted(string message, Exception? innerException = default)
|
||||
{
|
||||
throw new HutaoException(message, innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static InvalidCastException InvalidCast<TFrom, TTo>(string name, Exception? innerException = default)
|
||||
{
|
||||
string message = $"This instance of '{typeof(TFrom).FullName}' '{name}' doesn't implement '{typeof(TTo).FullName}'";
|
||||
@@ -52,18 +67,21 @@ internal sealed class HutaoException : Exception
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static InvalidOperationException InvalidOperation(string message, Exception? innerException = default)
|
||||
{
|
||||
throw new InvalidOperationException(message, innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static NotSupportedException NotSupported(string? message = default, Exception? innerException = default)
|
||||
{
|
||||
throw new NotSupportedException(message, innerException);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static OperationCanceledException OperationCanceled(string message, Exception? innerException = default)
|
||||
{
|
||||
throw new OperationCanceledException(message, innerException);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
/// <summary>
|
||||
/// 运行环境异常
|
||||
/// 用户的计算机中的某些设置不符合要求
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Obsolete("Use HutaoException instead")]
|
||||
internal sealed class RuntimeEnvironmentException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造一个新的运行环境异常
|
||||
/// </summary>
|
||||
/// <param name="message">消息</param>
|
||||
/// <param name="innerException">内部错误</param>
|
||||
public RuntimeEnvironmentException(string message, Exception? innerException)
|
||||
: base($"{message}\n{innerException?.Message}", innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Service.Game;
|
||||
using Snap.Hutao.Service.Game.Package;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
@@ -22,92 +19,4 @@ internal static class ThrowHelper
|
||||
{
|
||||
throw new ArgumentException(message, paramName);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static DatabaseCorruptedException DatabaseCorrupted(string message, Exception? inner)
|
||||
{
|
||||
throw new DatabaseCorruptedException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static GameFileOperationException GameFileOperation(string message, Exception? inner)
|
||||
{
|
||||
throw new GameFileOperationException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static InvalidDataException InvalidData(string message, Exception? inner = default)
|
||||
{
|
||||
throw new InvalidDataException(message, inner);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void InvalidDataIf([DoesNotReturnIf(true)] bool condition, string message, Exception? inner = default)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
throw new InvalidDataException(message, inner);
|
||||
}
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static InvalidOperationException InvalidOperation(string message, Exception? inner = default)
|
||||
{
|
||||
throw new InvalidOperationException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static NotSupportedException NotSupported()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static NotSupportedException NotSupported(string message)
|
||||
{
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void NotSupportedIf(bool condition, string message)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static OperationCanceledException OperationCanceled(string message, Exception? inner = default)
|
||||
{
|
||||
throw new OperationCanceledException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static PackageConvertException PackageConvert(string message, Exception? inner = default)
|
||||
{
|
||||
throw new PackageConvertException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static RuntimeEnvironmentException RuntimeEnvironment(string message, Exception? inner)
|
||||
{
|
||||
throw new RuntimeEnvironmentException(message, inner);
|
||||
}
|
||||
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static UserdataCorruptedException UserdataCorrupted(string message, Exception? inner)
|
||||
{
|
||||
throw new UserdataCorruptedException(message, inner);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
/// <summary>
|
||||
/// 用户数据损坏异常
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Obsolete("Use HutaoException instead")]
|
||||
internal sealed class UserdataCorruptedException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造一个新的用户数据损坏异常
|
||||
/// </summary>
|
||||
/// <param name="message">消息</param>
|
||||
/// <param name="innerException">内部错误</param>
|
||||
public UserdataCorruptedException(string message, Exception? innerException)
|
||||
: base(SH.FormatCoreExceptionServiceUserdataCorruptedMessage($"{message}\n{innerException?.Message}"), innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ internal sealed class HttpShardCopyWorker<TStatus> : IDisposable
|
||||
using (HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, token).ConfigureAwait(false))
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
using (IMemoryOwner<byte> memoryOwner = MemoryPool<byte>.Shared.Rent())
|
||||
using (IMemoryOwner<byte> memoryOwner = MemoryPool<byte>.Shared.Rent(bufferSize))
|
||||
{
|
||||
Memory<byte> buffer = memoryOwner.Memory;
|
||||
using (Stream stream = await response.Content.ReadAsStreamAsync(token).ConfigureAwait(false))
|
||||
|
||||
@@ -27,6 +27,7 @@ internal sealed class StreamReaderWriter : IDisposable
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="StreamWriter.WriteAsync(string?)"/>
|
||||
[SuppressMessage("", "SH003")]
|
||||
public Task WriteAsync(string value)
|
||||
{
|
||||
return writer.WriteAsync(value);
|
||||
|
||||
@@ -22,7 +22,7 @@ internal sealed class SeparatorCommaInt32EnumerableConverter : JsonConverter<IEn
|
||||
return EnumerateNumbers(source);
|
||||
}
|
||||
|
||||
return Enumerable.Empty<int>();
|
||||
return [];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -83,9 +83,10 @@ internal static class LoggerExtension
|
||||
logger.LogColorized(logLevel, 0, exception, message, args);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "CA2254")]
|
||||
public static void LogColorized(this ILogger logger, LogLevel logLevel, EventId eventId, Exception? exception, LogMessage message, params LogArgument[] args)
|
||||
{
|
||||
string colorizedMessage = Colorize(message, args, out object?[] outArgs)!;
|
||||
string? colorizedMessage = Colorize(message, args, out object?[] outArgs);
|
||||
logger.Log(logLevel, eventId, exception, colorizedMessage, outArgs);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Snap.Hutao.Core.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// 封装验证方法,简化微软验证
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Obsolete("Use HutaoException instead")]
|
||||
internal static class Must
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> if a condition does not evaluate to true.
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to check.</param>
|
||||
/// <param name="message">message</param>
|
||||
/// <param name="parameterName">The name of the parameter to blame in the exception, if thrown.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Argument([DoesNotReturnIf(false)] bool condition, string? message, [CallerArgumentExpression(nameof(condition))] string? parameterName = null)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw new ArgumentException(message, parameterName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentOutOfRangeException"/> if a condition does not evaluate to true.
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to check.</param>
|
||||
/// <param name="message">message</param>
|
||||
/// <param name="parameterName">The name of the parameter to blame in the exception, if thrown.</param>
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static void Range([DoesNotReturnIf(false)] bool condition, string? message, [CallerArgumentExpression(nameof(condition))] string? parameterName = null)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(parameterName, message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unconditionally throws an <see cref="NotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">上下文</param>
|
||||
/// <returns>Nothing. This method always throws.</returns>
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
public static Exception NeverHappen(string? context = null)
|
||||
{
|
||||
throw new NotSupportedException(context);
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ internal sealed class HotKeyCombination : ObservableObject
|
||||
private VirtualKey key;
|
||||
private bool isEnabled;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public HotKeyCombination(IServiceProvider serviceProvider, HWND hwnd, string settingKey, int hotKeyId, HOT_KEY_MODIFIERS defaultModifiers, VirtualKey defaultKey)
|
||||
{
|
||||
infoBarService = serviceProvider.GetRequiredService<IInfoBarService>();
|
||||
|
||||
@@ -31,6 +31,7 @@ internal sealed class NotifyIconController : IDisposable
|
||||
id = Unsafe.As<byte, Guid>(ref MemoryMarshal.GetArrayDataReference(MD5.HashData(Encoding.UTF8.GetBytes(iconFile.Path))));
|
||||
|
||||
xamlHostWindow = new(serviceProvider);
|
||||
xamlHostWindow.MoveAndResize(default);
|
||||
|
||||
messageWindow = new()
|
||||
{
|
||||
@@ -39,7 +40,6 @@ internal sealed class NotifyIconController : IDisposable
|
||||
};
|
||||
|
||||
CreateNotifyIcon();
|
||||
xamlHostWindow.MoveAndResize(GetRect());
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -143,6 +143,7 @@ internal sealed class NotifyIconMessageWindow : IDisposable
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
[UnconditionalSuppressMessage("", "CS0649")]
|
||||
private readonly struct LPARAM2
|
||||
{
|
||||
public readonly uint Low;
|
||||
|
||||
@@ -12,6 +12,7 @@ internal sealed class XamlWindowNonRudeHWND : IDisposable
|
||||
private const string NonRudeHWND = "NonRudeHWND";
|
||||
private readonly HWND hwnd;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public XamlWindowNonRudeHWND(HWND hwnd)
|
||||
{
|
||||
this.hwnd = hwnd;
|
||||
|
||||
@@ -14,7 +14,6 @@ global using Snap.Hutao.Core.Annotation;
|
||||
global using Snap.Hutao.Core.DependencyInjection;
|
||||
global using Snap.Hutao.Core.DependencyInjection.Annotation;
|
||||
global using Snap.Hutao.Core.Threading;
|
||||
global using Snap.Hutao.Core.Validation;
|
||||
global using Snap.Hutao.Extension;
|
||||
global using Snap.Hutao.Resource.Localization;
|
||||
|
||||
|
||||
@@ -11,25 +11,25 @@ namespace Snap.Hutao.Model.Intrinsic.Frozen;
|
||||
[HighQuality]
|
||||
internal static class IntrinsicFrozen
|
||||
{
|
||||
public static FrozenSet<string> AssociationTypes { get; } = Enum.GetValues<AssociationType>().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType<string>().ToFrozenSet();
|
||||
public static FrozenSet<string> AssociationTypes { get; } = NamesFromEnum<AssociationType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<NameValue<AssociationType>> AssociationTypeNameValues { get; } = Enum.GetValues<AssociationType>().Select(e => new NameValue<AssociationType>(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
|
||||
public static FrozenSet<NameValue<AssociationType>> AssociationTypeNameValues { get; } = NameValuesFromEnum<AssociationType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<string> WeaponTypes { get; } = Enum.GetValues<WeaponType>().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType<string>().ToFrozenSet();
|
||||
public static FrozenSet<string> WeaponTypes { get; } = NamesFromEnum<WeaponType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<NameValue<WeaponType>> WeaponTypeNameValues { get; } = Enum.GetValues<WeaponType>().Select(e => new NameValue<WeaponType>(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
|
||||
public static FrozenSet<NameValue<WeaponType>> WeaponTypeNameValues { get; } = NameValuesFromEnum<WeaponType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<string> ItemQualities { get; } = Enum.GetValues<QualityType>().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType<string>().ToFrozenSet();
|
||||
public static FrozenSet<string> ItemQualities { get; } = NamesFromEnum<QualityType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<NameValue<QualityType>> ItemQualityNameValues { get; } = Enum.GetValues<QualityType>().Select(e => new NameValue<QualityType>(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
|
||||
public static FrozenSet<NameValue<QualityType>> ItemQualityNameValues { get; } = NameValuesFromEnum<QualityType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<string> BodyTypes { get; } = Enum.GetValues<BodyType>().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType<string>().ToFrozenSet();
|
||||
public static FrozenSet<string> BodyTypes { get; } = NamesFromEnum<BodyType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<NameValue<BodyType>> BodyTypeNameValues { get; } = Enum.GetValues<BodyType>().Select(e => new NameValue<BodyType>(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
|
||||
public static FrozenSet<NameValue<BodyType>> BodyTypeNameValues { get; } = NameValuesFromEnum<BodyType>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<string> FightProperties { get; } = Enum.GetValues<FightProperty>().Select(e => e.GetLocalizedDescriptionOrDefault()).OfType<string>().ToFrozenSet();
|
||||
public static FrozenSet<string> FightProperties { get; } = NamesFromEnum<FightProperty>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<NameValue<FightProperty>> FightPropertyNameValues { get; } = Enum.GetValues<FightProperty>().Select(e => new NameValue<FightProperty>(e.GetLocalizedDescriptionOrDefault()!, e)).Where(nv => !string.IsNullOrEmpty(nv.Name)).ToFrozenSet();
|
||||
public static FrozenSet<NameValue<FightProperty>> FightPropertyNameValues { get; } = NameValuesFromEnum<FightProperty>(e => e.GetLocalizedDescriptionOrDefault());
|
||||
|
||||
public static FrozenSet<string> ElementNames { get; } = FrozenSet.ToFrozenSet(
|
||||
[
|
||||
@@ -63,4 +63,50 @@ internal static class IntrinsicFrozen
|
||||
SH.ModelMetadataMaterialWeaponEnhancementMaterial,
|
||||
SH.ModelMetadataMaterialWeaponAscensionMaterial,
|
||||
]);
|
||||
|
||||
private static FrozenSet<string> NamesFromEnum<TEnum>(Func<TEnum, string?> selector)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
return NamesFromEnumValues(Enum.GetValues<TEnum>(), selector);
|
||||
}
|
||||
|
||||
private static FrozenSet<string> NamesFromEnumValues<TEnum>(TEnum[] values, Func<TEnum, string?> selector)
|
||||
{
|
||||
return NotNull(values, selector).ToFrozenSet();
|
||||
|
||||
static IEnumerable<string> NotNull(TEnum[] values, Func<TEnum, string?> selector)
|
||||
{
|
||||
foreach (TEnum value in values)
|
||||
{
|
||||
string? name = selector(value);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
yield return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static FrozenSet<NameValue<TEnum>> NameValuesFromEnum<TEnum>(Func<TEnum, string?> selector)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
return NameValuesFromEnumValues(Enum.GetValues<TEnum>(), selector);
|
||||
}
|
||||
|
||||
private static FrozenSet<NameValue<TEnum>> NameValuesFromEnumValues<TEnum>(TEnum[] values, Func<TEnum, string?> selector)
|
||||
{
|
||||
return NotNull(values, selector).ToFrozenSet();
|
||||
|
||||
static IEnumerable<NameValue<TEnum>> NotNull(TEnum[] values, Func<TEnum, string?> selector)
|
||||
{
|
||||
foreach (TEnum value in values)
|
||||
{
|
||||
string? name = selector(value);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
yield return new(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ internal sealed partial class AvatarInfoDbBulkOperation
|
||||
|
||||
public async ValueTask<List<EntityAvatarInfo>> UpdateDbAvatarInfosByShowcaseAsync(string uid, IEnumerable<EnkaAvatarInfo> webInfos, CancellationToken token)
|
||||
{
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary<AvatarId, EntityAvatarInfo> dbInfoMap);
|
||||
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
@@ -50,14 +50,14 @@ internal sealed partial class AvatarInfoDbBulkOperation
|
||||
AddOrUpdateAvatarInfo(entity, uid, appDbContext, webInfo);
|
||||
}
|
||||
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<List<EntityAvatarInfo>> UpdateDbAvatarInfosByGameRecordCharacterAsync(UserAndUid userAndUid, CancellationToken token)
|
||||
{
|
||||
string uid = userAndUid.Uid.Value;
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary<AvatarId, EntityAvatarInfo> dbInfoMap);
|
||||
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
@@ -103,14 +103,14 @@ internal sealed partial class AvatarInfoDbBulkOperation
|
||||
}
|
||||
|
||||
Return:
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async ValueTask<List<EntityAvatarInfo>> UpdateDbAvatarInfosByCalculateAvatarDetailAsync(UserAndUid userAndUid, CancellationToken token)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
string uid = userAndUid.Uid.Value;
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
List<EntityAvatarInfo> dbInfos = await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
EnsureItemsAvatarIdUnique(ref dbInfos, uid, out Dictionary<AvatarId, EntityAvatarInfo> dbInfoMap);
|
||||
|
||||
using (IServiceScope scope = serviceProvider.CreateScope())
|
||||
@@ -146,7 +146,7 @@ internal sealed partial class AvatarInfoDbBulkOperation
|
||||
}
|
||||
}
|
||||
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid).ConfigureAwait(false);
|
||||
return await avatarInfoDbService.GetAvatarInfoListByUidAsync(uid, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
@@ -32,6 +32,7 @@ internal static class AvatarViewBuilderExtension
|
||||
return builder;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static TBuilder SetCalculatorRefreshTimeFormat<TBuilder>(this TBuilder builder, DateTimeOffset refreshTime, Func<object?, string> format, string defaultValue)
|
||||
where TBuilder : IAvatarViewBuilder
|
||||
{
|
||||
@@ -116,6 +117,7 @@ internal static class AvatarViewBuilderExtension
|
||||
return builder.Configure(b => b.View.FetterLevel = level);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static TBuilder SetGameRecordRefreshTimeFormat<TBuilder>(this TBuilder builder, DateTimeOffset refreshTime, Func<object?, string> format, string defaultValue)
|
||||
where TBuilder : IAvatarViewBuilder
|
||||
{
|
||||
@@ -128,6 +130,7 @@ internal static class AvatarViewBuilderExtension
|
||||
return builder.Configure(b => b.View.GameRecordRefreshTimeFormat = gameRecordRefreshTimeFormat);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static TBuilder SetId<TBuilder>(this TBuilder builder, AvatarId id)
|
||||
where TBuilder : IAvatarViewBuilder
|
||||
{
|
||||
@@ -175,6 +178,7 @@ internal static class AvatarViewBuilderExtension
|
||||
return builder.Configure(b => b.View.Reliquaries = reliquaries);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static TBuilder SetShowcaseRefreshTimeFormat<TBuilder>(this TBuilder builder, DateTimeOffset refreshTime, Func<object?, string> format, string defaultValue)
|
||||
where TBuilder : IAvatarViewBuilder
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@ internal static class WeaponViewBuilderExtension
|
||||
return builder.SetIcon<TBuilder, WeaponView>(icon);
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static TBuilder SetId<TBuilder>(this TBuilder builder, WeaponId id)
|
||||
where TBuilder : IWeaponViewBuilder
|
||||
{
|
||||
|
||||
@@ -12,11 +12,13 @@ internal sealed class MaterialIdComparer : IComparer<MaterialId>
|
||||
|
||||
public static MaterialIdComparer Shared { get => LazyInitializer.EnsureInitialized(ref shared, ref syncRoot, () => new()); }
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public int Compare(MaterialId x, MaterialId y)
|
||||
{
|
||||
return Transform(x).CompareTo(Transform(y));
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private static uint Transform(MaterialId value)
|
||||
{
|
||||
return value.Value switch
|
||||
|
||||
@@ -18,6 +18,7 @@ internal sealed class NotifySuppressionContext : INotifySuppressionContext
|
||||
|
||||
public DailyNoteEntry Entry { get => entry; }
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public void Add(DailyNoteNotifyInfo info)
|
||||
{
|
||||
infos.Add(info);
|
||||
|
||||
@@ -70,7 +70,7 @@ internal static class RegistryInterop
|
||||
{
|
||||
SchemeType.ChineseOfficial => (ChineseKeyName, SdkChineseValueName),
|
||||
SchemeType.Oversea => (OverseaKeyName, SdkOverseaValueName),
|
||||
_ => throw ThrowHelper.NotSupported($"Invalid account SchemeType: {scheme}"),
|
||||
_ => throw HutaoException.NotSupported($"Invalid account SchemeType: {scheme}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ internal readonly struct GameScreenCaptureContext
|
||||
private readonly IDirect3DDevice direct3DDevice;
|
||||
private readonly HWND hwnd;
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public GameScreenCaptureContext(IDirect3DDevice direct3DDevice, HWND hwnd)
|
||||
{
|
||||
this.direct3DDevice = direct3DDevice;
|
||||
@@ -87,6 +88,7 @@ internal readonly struct GameScreenCaptureContext
|
||||
return clientBox.right <= width && clientBox.bottom <= height;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
private static DirectXPixelFormat DeterminePixelFormat(HWND hwnd)
|
||||
{
|
||||
HDC hdc = GetDC(hwnd);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Snap.Hutao.Service.Game.Automation.ScreenCapture;
|
||||
|
||||
internal sealed class GameScreenCaptureMemoryPool : MemoryPool<byte>
|
||||
{
|
||||
private static LazySlim<GameScreenCaptureMemoryPool> lazyShared = new(() => new());
|
||||
private static readonly LazySlim<GameScreenCaptureMemoryPool> LazyShared = new(() => new());
|
||||
|
||||
private readonly object syncRoot = new();
|
||||
private readonly LinkedList<GameScreenCaptureBuffer> unrentedBuffers = [];
|
||||
@@ -17,7 +17,7 @@ internal sealed class GameScreenCaptureMemoryPool : MemoryPool<byte>
|
||||
|
||||
private int bufferCount;
|
||||
|
||||
public new static GameScreenCaptureMemoryPool Shared { get => lazyShared.Value; }
|
||||
public static new GameScreenCaptureMemoryPool Shared { get => LazyShared.Value; }
|
||||
|
||||
public override int MaxBufferSize { get => Array.MaxLength; }
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi.Common;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using System.Buffers;
|
||||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Graphics;
|
||||
@@ -114,8 +113,9 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
{
|
||||
UnsafeProcessFrameSurface(frame.Surface);
|
||||
}
|
||||
catch (Exception ex) // TODO: test if it's device lost.
|
||||
catch (Exception ex)
|
||||
{
|
||||
// TODO: test if it's device lost.
|
||||
logger.LogError(ex, "Failed to process the frame surface.");
|
||||
needsReset = true;
|
||||
}
|
||||
@@ -209,8 +209,9 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
{
|
||||
subresource[row][..rowLength].CopyTo(buffer.Memory.Span.Slice(row * rowLength, rowLength));
|
||||
}
|
||||
|
||||
#pragma warning disable CA2000
|
||||
frameRawPixelDataTaskCompletionSource.SetResult(new(buffer, (int)textureWidth, (int)textureHeight));
|
||||
#pragma warning restore CA2000
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -235,8 +236,9 @@ internal sealed class GameScreenCaptureSession : IDisposable
|
||||
pixel.A = (byte)(float16Pixel.A * ByteMaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA2000
|
||||
frameRawPixelDataTaskCompletionSource.SetResult(new(buffer, (int)textureWidth, (int)textureHeight));
|
||||
#pragma warning restore CA2000
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Snap.Hutao.Service.Game.Package;
|
||||
/// 包转换异常
|
||||
/// </summary>
|
||||
[HighQuality]
|
||||
[Obsolete]
|
||||
internal sealed class PackageConvertException : Exception
|
||||
{
|
||||
/// <inheritdoc cref="Exception(string?, Exception?)"/>
|
||||
|
||||
@@ -180,7 +180,7 @@ internal sealed partial class PackageConverter
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw ThrowHelper.PackageConvert(SH.ServiceGamePackageRequestPackageVerionFailed, ex);
|
||||
throw HutaoException.Throw(SH.ServiceGamePackageRequestPackageVerionFailed, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,13 +252,13 @@ internal sealed partial class PackageConverter
|
||||
{
|
||||
// System.IO.IOException: The response ended prematurely.
|
||||
// System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
|
||||
ThrowHelper.PackageConvert(SH.FormatServiceGamePackageRequestScatteredFileFailed(remoteName), ex);
|
||||
HutaoException.Throw(SH.FormatServiceGamePackageRequestScatteredFileFailed(remoteName), ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.Equals(info.Remote.Md5, await MD5.HashFileAsync(cacheFile).ConfigureAwait(false), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ThrowHelper.PackageConvert(SH.FormatServiceGamePackageRequestScatteredFileFailed(remoteName));
|
||||
HutaoException.Throw(SH.FormatServiceGamePackageRequestScatteredFileFailed(remoteName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ internal sealed partial class PackageConverter
|
||||
{
|
||||
// Access to the path is denied.
|
||||
// When user install the game in special folder like 'Program Files'
|
||||
throw ThrowHelper.GameFileOperation(SH.ServiceGamePackageRenameDataFolderFailed, ex);
|
||||
throw HutaoException.Throw(SH.ServiceGamePackageRenameDataFolderFailed, ex);
|
||||
}
|
||||
|
||||
// 重新下载所有 *pkg_version 文件
|
||||
|
||||
@@ -27,7 +27,7 @@ internal sealed partial class HutaoAsAService : IHutaoAsAService
|
||||
{
|
||||
RelayCommand<HutaoAnnouncement> dismissCommand = new(DismissAnnouncement);
|
||||
|
||||
ApplicationDataCompositeValue excludedIds = LocalSetting.Get(SettingKeys.ExcludedAnnouncementIds, new ApplicationDataCompositeValue());
|
||||
ApplicationDataCompositeValue excludedIds = LocalSetting.Get(SettingKeys.ExcludedAnnouncementIds, []);
|
||||
List<long> data = excludedIds.Select(kvp => long.Parse(kvp.Key, CultureInfo.InvariantCulture)).ToList();
|
||||
|
||||
Response<List<HutaoAnnouncement>> response;
|
||||
@@ -56,7 +56,7 @@ internal sealed partial class HutaoAsAService : IHutaoAsAService
|
||||
{
|
||||
if (announcement is not null && announcements is not null)
|
||||
{
|
||||
ApplicationDataCompositeValue excludedIds = LocalSetting.Get(SettingKeys.ExcludedAnnouncementIds, new ApplicationDataCompositeValue());
|
||||
ApplicationDataCompositeValue excludedIds = LocalSetting.Get(SettingKeys.ExcludedAnnouncementIds, []);
|
||||
|
||||
foreach ((string key, object value) in excludedIds)
|
||||
{
|
||||
|
||||
@@ -59,14 +59,14 @@ internal sealed partial class HutaoSpiralAbyssStatisticsCache : IHutaoSpiralAbys
|
||||
if (await metadataService.InitializeAsync().ConfigureAwait(false))
|
||||
{
|
||||
Dictionary<AvatarId, Avatar> idAvatarMap = await GetIdAvatarMapExtendedAsync().ConfigureAwait(false);
|
||||
List<Task> tasks = new(5)
|
||||
{
|
||||
List<Task> tasks =
|
||||
[
|
||||
AvatarAppearanceRankAsync(idAvatarMap),
|
||||
AvatarUsageRanksAsync(idAvatarMap),
|
||||
AvatarConstellationInfosAsync(idAvatarMap),
|
||||
TeamAppearancesAsync(idAvatarMap),
|
||||
OverviewAsync(),
|
||||
};
|
||||
];
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ internal sealed partial class ObjectCacheDbService : IObjectCacheDbService
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
ThrowHelper.DatabaseCorrupted($"无法存储 Key:{key} 对应的值到数据库缓存", ex);
|
||||
HutaoException.Throw($"无法存储 Key:{key} 对应的值到数据库缓存", ex);
|
||||
}
|
||||
|
||||
return default!;
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Quartz;
|
||||
using Snap.Hutao.Service.DailyNote;
|
||||
|
||||
namespace Snap.Hutao.Service.Job;
|
||||
|
||||
internal static class JobIdentity
|
||||
|
||||
@@ -62,7 +62,7 @@ internal sealed partial class QuartzService : IQuartzService, IDisposable
|
||||
{
|
||||
DisposeAsync().GetAwaiter().GetResult();
|
||||
|
||||
async ValueTask DisposeAsync()
|
||||
async Task DisposeAsync()
|
||||
{
|
||||
if (scheduler is null)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace Snap.Hutao.Service.SpiralAbyss;
|
||||
[Injection(InjectAs.Scoped, typeof(ISpiralAbyssRecordService))]
|
||||
internal sealed partial class SpiralAbyssRecordService : ISpiralAbyssRecordService
|
||||
{
|
||||
//private readonly IOverseaSupportFactory<IGameRecordClient> gameRecordClientFactory;
|
||||
private readonly ISpiralAbyssRecordDbService spiralAbyssRecordDbService;
|
||||
private readonly IServiceScopeFactory serviceScopeFactory;
|
||||
private readonly IMetadataService metadataService;
|
||||
|
||||
@@ -22,6 +22,6 @@ internal sealed class Int32ToVisibilityConverter : IValueConverter
|
||||
/// <inheritdoc/>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw ThrowHelper.NotSupported();
|
||||
throw HutaoException.NotSupported();
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,6 @@ internal sealed class Int32ToVisibilityRevertConverter : IValueConverter
|
||||
/// <inheritdoc/>
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw ThrowHelper.NotSupported();
|
||||
throw HutaoException.NotSupported();
|
||||
}
|
||||
}
|
||||
@@ -98,13 +98,6 @@
|
||||
Style="{ThemeResource SettingButtonStyle}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
<cwc:SettingsCard Header="Test Windows.Graphics.Capture">
|
||||
<Button
|
||||
Command="{Binding TestWindowsGraphicsCaptureCommand}"
|
||||
Content="Test"
|
||||
Style="{ThemeResource SettingButtonStyle}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
<cwc:SettingsCard Header="Suppress Metadata Initialization">
|
||||
<ToggleSwitch IsOn="{Binding SuppressMetadataInitialization, Mode=TwoWay}"/>
|
||||
</cwc:SettingsCard>
|
||||
|
||||
@@ -179,7 +179,7 @@ internal sealed partial class AchievementViewModel : Abstraction.ViewModel, INav
|
||||
dependencies.InfoBarService.Warning(SH.FormatViewModelAchievementArchiveAlreadyExists(name));
|
||||
break;
|
||||
default:
|
||||
throw Must.NeverHappen();
|
||||
throw HutaoException.NotSupported();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Control.Media;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.IO.DataTransfer;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Message;
|
||||
@@ -310,7 +311,7 @@ internal sealed partial class AvatarPropertyViewModel : Abstraction.ViewModel, I
|
||||
return CultivateCoreResult.SaveConsumptionFailed;
|
||||
}
|
||||
}
|
||||
catch (Core.ExceptionService.UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex, SH.ViewModelCultivationAddWarning);
|
||||
}
|
||||
|
||||
@@ -15,11 +15,6 @@ namespace Snap.Hutao.ViewModel.Complex;
|
||||
[HighQuality]
|
||||
internal sealed class Team : List<AvatarView>
|
||||
{
|
||||
/// <summary>
|
||||
/// 构造一个新的队伍
|
||||
/// </summary>
|
||||
/// <param name="team">队伍</param>
|
||||
/// <param name="idAvatarMap">映射</param>
|
||||
public Team(ItemRate<string, int> team, Dictionary<AvatarId, Avatar> idAvatarMap, int rank)
|
||||
: base(4)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
@@ -99,7 +100,7 @@ internal sealed partial class CultivationViewModel : Abstraction.ViewModel
|
||||
infoBarService.Information(SH.ViewModelCultivationProjectAlreadyExists);
|
||||
break;
|
||||
default:
|
||||
throw Must.NeverHappen();
|
||||
throw HutaoException.NotSupported();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service;
|
||||
@@ -69,7 +69,7 @@ internal sealed partial class DailyNoteViewModel : Abstraction.ViewModel
|
||||
DailyNoteEntries = entries;
|
||||
return true;
|
||||
}
|
||||
catch (Core.ExceptionService.UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Service.DailyNote;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
@@ -48,7 +49,7 @@ internal sealed partial class DailyNoteViewModelSlim : Abstraction.ViewModelSlim
|
||||
DailyNoteEntries = entryList;
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch (Core.ExceptionService.UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
return;
|
||||
|
||||
@@ -179,7 +179,7 @@ internal sealed partial class GachaLogViewModel : Abstraction.ViewModel
|
||||
{
|
||||
authkeyValid = await gachaLogService.RefreshGachaLogAsync(query, strategy, progress, CancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
authkeyValid = false;
|
||||
infoBarService.Error(ex);
|
||||
@@ -349,7 +349,7 @@ internal sealed partial class GachaLogViewModel : Abstraction.ViewModel
|
||||
Statistics = statistics;
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch (UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
|
||||
|
||||
private readonly LaunchStatusOptions launchStatusOptions;
|
||||
private readonly IGameLocatorFactory gameLocatorFactory;
|
||||
private readonly ILogger<LaunchGameViewModel> logger;
|
||||
private readonly LaunchGameShared launchGameShared;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly ResourceClient resourceClient;
|
||||
@@ -117,7 +116,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
}
|
||||
@@ -182,7 +181,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
|
||||
[Command("IdentifyMonitorsCommand")]
|
||||
private static async Task IdentifyMonitorsAsync()
|
||||
{
|
||||
await IdentifyMonitorWindow.IdentifyAllMonitorsAsync(3);
|
||||
await IdentifyMonitorWindow.IdentifyAllMonitorsAsync(3).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Command("SetGamePathCommand")]
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Snap.Hutao.ViewModel.Guide;
|
||||
|
||||
internal sealed class DownloadSummary : ObservableObject
|
||||
{
|
||||
private static readonly FrozenSet<string?> AllowedMediaTypes = FrozenSet.ToFrozenSet(
|
||||
private static readonly FrozenSet<string?> AllowedMediaTypes = FrozenSet.ToFrozenSet<string?>(
|
||||
[
|
||||
"application/octet-stream",
|
||||
"application/zip",
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Snap.Hutao.ViewModel.Guide;
|
||||
/// <summary>
|
||||
/// 指引视图模型
|
||||
/// </summary>
|
||||
[SuppressMessage("", "SA1124")]
|
||||
[ConstructorGenerated]
|
||||
[Injection(InjectAs.Singleton)]
|
||||
internal sealed partial class GuideViewModel : Abstraction.ViewModel
|
||||
|
||||
@@ -79,7 +79,7 @@ internal sealed partial class NotifyIconViewModel : ObservableObject
|
||||
{
|
||||
if (serviceProvider.GetRequiredService<IAppActivation>() is IAppActivationActionHandlersAccess access)
|
||||
{
|
||||
await access.HandleLaunchGameActionAsync();
|
||||
await access.HandleLaunchGameActionAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
ShowWindow();
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Caching;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
@@ -11,29 +10,6 @@ using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Service.Notification;
|
||||
using Snap.Hutao.ViewModel.Guide;
|
||||
using Snap.Hutao.Web.Hutao.HutaoAsAService;
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
using Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
using Snap.Hutao.Win32.Graphics.Dwm;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
using Snap.Hutao.Win32.Graphics.Dxgi.Common;
|
||||
using Snap.Hutao.Win32.System.Com;
|
||||
using Snap.Hutao.Win32.System.WinRT;
|
||||
using Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Foundation;
|
||||
using Windows.Graphics.Capture;
|
||||
using Windows.Graphics.DirectX;
|
||||
using Windows.Graphics.DirectX.Direct3D11;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Storage.Streams;
|
||||
using WinRT;
|
||||
using static Snap.Hutao.Win32.ConstValues;
|
||||
using static Snap.Hutao.Win32.D3D11;
|
||||
using static Snap.Hutao.Win32.DwmApi;
|
||||
using static Snap.Hutao.Win32.Macros;
|
||||
using static Snap.Hutao.Win32.User32;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
@@ -46,8 +22,8 @@ namespace Snap.Hutao.ViewModel;
|
||||
internal sealed partial class TestViewModel : Abstraction.ViewModel
|
||||
{
|
||||
private readonly HutaoAsAServiceClient homaAsAServiceClient;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly ICurrentXamlWindowReference currentXamlWindowReference;
|
||||
private readonly ILogger<TestViewModel> logger;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
private readonly ITaskContext taskContext;
|
||||
@@ -127,7 +103,7 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel
|
||||
[Command("ResetMainWindowSizeCommand")]
|
||||
private void ResetMainWindowSize()
|
||||
{
|
||||
if (serviceProvider.GetRequiredService<ICurrentXamlWindowReference>().Window is MainWindow mainWindow)
|
||||
if (currentXamlWindowReference.Window is MainWindow mainWindow)
|
||||
{
|
||||
double scale = mainWindow.GetRasterizationScale();
|
||||
mainWindow.AppWindow.Resize(new Windows.Graphics.SizeInt32(1372, 772).Scale(scale));
|
||||
@@ -166,208 +142,4 @@ internal sealed partial class TestViewModel : Abstraction.ViewModel
|
||||
logger.LogInformation("Failed ImageCache download tasks: [{Tasks}]", set?.ToString(','));
|
||||
}
|
||||
}
|
||||
|
||||
[Command("TestWindowsGraphicsCaptureCommand")]
|
||||
private unsafe void TestWindowsGraphicsCapture()
|
||||
{
|
||||
// https://github.com/obsproject/obs-studio/blob/master/libobs-winrt/winrt-capture.cpp
|
||||
if (!Core.UniversalApiContract.IsPresent(WindowsVersion.Windows10Version1903))
|
||||
{
|
||||
logger.LogWarning("Windows 10 Version 1903 or later is required for Windows.Graphics.Capture API.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GraphicsCaptureSession.IsSupported())
|
||||
{
|
||||
logger.LogWarning("GraphicsCaptureSession is not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
D3D11_CREATE_DEVICE_FLAG flag = D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG;
|
||||
|
||||
if (SUCCEEDED(D3D11CreateDevice(default, D3D_DRIVER_TYPE.D3D_DRIVER_TYPE_HARDWARE, default, flag, [], D3D11_SDK_VERSION, out ID3D11Device* pD3D11Device, out _, out _)))
|
||||
{
|
||||
if (SUCCEEDED(IUnknownMarshal.QueryInterface(pD3D11Device, in IDXGIDevice.IID, out IDXGIDevice* pDXGIDevice)))
|
||||
{
|
||||
if (SUCCEEDED(CreateDirect3D11DeviceFromDXGIDevice(pDXGIDevice, out Win32.System.WinRT.IInspectable* inspectable)))
|
||||
{
|
||||
IDirect3DDevice direct3DDevice = WinRT.IInspectable.FromAbi((nint)inspectable).ObjRef.AsInterface<IDirect3DDevice>();
|
||||
|
||||
HWND hwnd = serviceProvider.GetRequiredService<ICurrentXamlWindowReference>().GetWindowHandle();
|
||||
GraphicsCaptureItem.As<IGraphicsCaptureItemInterop>().CreateForWindow(hwnd, out GraphicsCaptureItem item);
|
||||
|
||||
using (Direct3D11CaptureFramePool framePool = Direct3D11CaptureFramePool.CreateFreeThreaded(direct3DDevice, DirectXPixelFormat.B8G8R8A8UIntNormalized, 2, item.Size))
|
||||
{
|
||||
framePool.FrameArrived += (pool, _) =>
|
||||
{
|
||||
using (Direct3D11CaptureFrame frame = pool.TryGetNextFrame())
|
||||
{
|
||||
if (frame is not null)
|
||||
{
|
||||
logger.LogInformation("Content Size: {Width} x {Height}", frame.ContentSize.Width, frame.ContentSize.Height);
|
||||
|
||||
IDirect3DDxgiInterfaceAccess access = frame.Surface.As<IDirect3DDxgiInterfaceAccess>();
|
||||
if (FAILED(access.GetInterface(in IDXGISurface.IID, out IDXGISurface* pDXGISurface)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(pDXGISurface->GetDesc(out DXGI_SURFACE_DESC surfaceDesc)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool boxAvailable = TryGetClientBox(hwnd, surfaceDesc.Width, surfaceDesc.Height, out D3D11_BOX clientBox);
|
||||
(uint textureWidth, uint textureHeight) = boxAvailable
|
||||
? (clientBox.right - clientBox.left, clientBox.bottom - clientBox.top)
|
||||
: (surfaceDesc.Width, surfaceDesc.Height);
|
||||
|
||||
D3D11_TEXTURE2D_DESC texture2DDesc = default;
|
||||
texture2DDesc.Width = textureWidth;
|
||||
texture2DDesc.Height = textureHeight;
|
||||
texture2DDesc.ArraySize = 1;
|
||||
texture2DDesc.CPUAccessFlags = D3D11_CPU_ACCESS_FLAG.D3D11_CPU_ACCESS_READ;
|
||||
texture2DDesc.Format = DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
texture2DDesc.MipLevels = 1;
|
||||
texture2DDesc.SampleDesc.Count = 1;
|
||||
texture2DDesc.Usage = D3D11_USAGE.D3D11_USAGE_STAGING;
|
||||
|
||||
if (FAILED(pDXGISurface->GetDevice(in ID3D11Device.IID, out ID3D11Device* pD3D11Device)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(pD3D11Device->CreateTexture2D(ref texture2DDesc, ref Unsafe.NullRef<D3D11_SUBRESOURCE_DATA>(), out ID3D11Texture2D* pTexture2D)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FAILED(access.GetInterface(in ID3D11Resource.IID, out ID3D11Resource* pD3D11Resource)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pD3D11Device->GetImmediateContext(out ID3D11DeviceContext* pDeviceContext);
|
||||
|
||||
if (boxAvailable)
|
||||
{
|
||||
pDeviceContext->CopySubresourceRegion((ID3D11Resource*)pTexture2D, 0, 0, 0, 0, pD3D11Resource, 0, in clientBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("Box not available");
|
||||
pDeviceContext->CopyResource((ID3D11Resource*)pTexture2D, pD3D11Resource);
|
||||
}
|
||||
|
||||
if (FAILED(pDeviceContext->Map((ID3D11Resource*)pTexture2D, 0, D3D11_MAP.D3D11_MAP_READ, 0, out D3D11_MAPPED_SUBRESOURCE mappedSubresource)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SoftwareBitmap softwareBitmap = new(BitmapPixelFormat.Bgra8, (int)texture2DDesc.Width, (int)texture2DDesc.Height, BitmapAlphaMode.Premultiplied);
|
||||
using (BitmapBuffer bitmapBuffer = softwareBitmap.LockBuffer(BitmapBufferAccessMode.Write))
|
||||
{
|
||||
using (IMemoryBufferReference reference = bitmapBuffer.CreateReference())
|
||||
{
|
||||
reference.As<IMemoryBufferByteAccess>().GetBuffer(out Span<byte> bufferSpan);
|
||||
fixed (byte* p = bufferSpan)
|
||||
{
|
||||
for (uint i = 0; i < texture2DDesc.Height; i++)
|
||||
{
|
||||
System.Buffer.MemoryCopy(((byte*)mappedSubresource.pData) + (i * mappedSubresource.RowPitch), p + (i * texture2DDesc.Width * 4), texture2DDesc.Width * 4, texture2DDesc.Width * 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (InMemoryRandomAccessStream stream = new())
|
||||
{
|
||||
BitmapEncoder encoder = BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream).AsTask().Result;
|
||||
encoder.SetSoftwareBitmap(softwareBitmap);
|
||||
encoder.FlushAsync().AsTask().Wait();
|
||||
|
||||
using (FileStream fileStream = new("D:\\test.png", FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
|
||||
{
|
||||
stream.AsStream().CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
_ = 1;
|
||||
|
||||
pDeviceContext->Unmap((ID3D11Resource*)pTexture2D, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogInformation("Null Frame");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using (GraphicsCaptureSession captureSession = framePool.CreateCaptureSession(item))
|
||||
{
|
||||
captureSession.IsCursorCaptureEnabled = false;
|
||||
captureSession.IsBorderRequired = false;
|
||||
captureSession.StartCapture();
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("CreateDirect3D11DeviceFromDXGIDevice failed");
|
||||
}
|
||||
|
||||
IUnknownMarshal.Release(pDXGIDevice);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("ID3D11Device As IDXGIDevice failed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogWarning("D3D11CreateDevice failed");
|
||||
}
|
||||
|
||||
static bool TryGetClientBox(HWND hwnd, uint width, uint height, out D3D11_BOX clientBox)
|
||||
{
|
||||
clientBox = default;
|
||||
return false;
|
||||
|
||||
// Ensure the window is not minimized
|
||||
if (IsIconic(hwnd))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure the window is at least partially in the screen
|
||||
if (!(GetClientRect(hwnd, out RECT clientRect) && (clientRect.right > 0) && (clientRect.bottom > 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure we get the window chrome rect
|
||||
if (DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out RECT windowRect) != HRESULT.S_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Provide a client side (0, 0) and translate to screen coordinates
|
||||
POINT clientPoint = default;
|
||||
if (!ClientToScreen(hwnd, ref clientPoint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint left = clientBox.left = clientPoint.x > windowRect.left ? (uint)(clientPoint.x - windowRect.left) : 0U;
|
||||
uint top = clientBox.top = clientPoint.y > windowRect.top ? (uint)(clientPoint.y - windowRect.top) : 0U;
|
||||
clientBox.right = left + (width > left ? (uint)Math.Min(width - left, clientRect.right) : 1U);
|
||||
clientBox.bottom = top + (height > top ? (uint)Math.Min(height - top, clientRect.bottom) : 1U);
|
||||
clientBox.front = 0U;
|
||||
clientBox.back = 1U;
|
||||
|
||||
return clientBox.right <= width && clientBox.bottom <= height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ internal sealed partial class UserViewModel : ObservableObject
|
||||
infoBarService.Success(SH.FormatViewModelUserUpdated(uid));
|
||||
break;
|
||||
default:
|
||||
throw Must.NeverHappen();
|
||||
throw HutaoException.NotSupported();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ internal sealed partial class UserViewModel : ObservableObject
|
||||
Users = await userService.GetUserCollectionAsync().ConfigureAwait(true);
|
||||
SelectedUser = userService.Current;
|
||||
}
|
||||
catch (UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ internal sealed partial class UserViewModel : ObservableObject
|
||||
await userService.RemoveUserAsync(user).ConfigureAwait(false);
|
||||
infoBarService.Success(SH.FormatViewModelUserRemoved(user.UserInfo?.Nickname));
|
||||
}
|
||||
catch (UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Control.AutoSuggestBox;
|
||||
using Snap.Hutao.Control.Collection.AdvancedCollectionView;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Entity.Primitive;
|
||||
@@ -204,7 +205,7 @@ internal sealed partial class WikiAvatarViewModel : Abstraction.ViewModel
|
||||
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
|
||||
}
|
||||
}
|
||||
catch (Core.ExceptionService.UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex, SH.ViewModelCultivationAddWarning);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Control.AutoSuggestBox;
|
||||
using Snap.Hutao.Control.Collection.AdvancedCollectionView;
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
using Snap.Hutao.Factory.ContentDialog;
|
||||
using Snap.Hutao.Model.Calculable;
|
||||
using Snap.Hutao.Model.Entity.Primitive;
|
||||
@@ -194,7 +195,7 @@ internal sealed partial class WikiWeaponViewModel : Abstraction.ViewModel
|
||||
infoBarService.Warning(SH.ViewModelCultivationEntryAddWarning);
|
||||
}
|
||||
}
|
||||
catch (Core.ExceptionService.UserdataCorruptedException ex)
|
||||
catch (HutaoException ex)
|
||||
{
|
||||
infoBarService.Error(ex, SH.ViewModelCultivationAddWarning);
|
||||
}
|
||||
|
||||
@@ -184,13 +184,14 @@ internal class MiHoYoJSBridge
|
||||
protected virtual JsResult<Dictionary<string, string>> GetCurrentLocale(JsParam<PushPagePayload> param)
|
||||
{
|
||||
CultureOptions cultureOptions = serviceProvider.GetRequiredService<CultureOptions>();
|
||||
TimeSpan offset = TimeZoneInfo.Local.GetUtcOffset(DateTimeOffset.Now);
|
||||
|
||||
return new()
|
||||
{
|
||||
Data = new()
|
||||
{
|
||||
["language"] = cultureOptions.LanguageCode,
|
||||
["timeZone"] = "GMT+8",
|
||||
["timeZone"] = $"GMT{(offset.Hours >= 0 ? "+" : " - ")}{offset.Hours:D1}",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ internal static class CookieExtension
|
||||
|
||||
private static bool TryGetValuesToCookie(this Cookie source, in ReadOnlySpan<string> keys, [NotNullWhen(true)] out Cookie? cookie)
|
||||
{
|
||||
Must.Range(keys.Length > 0, "Empty keys is not supported");
|
||||
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(keys.Length, 0, "Empty keys is not supported");
|
||||
SortedDictionary<string, string> cookieMap = [];
|
||||
|
||||
foreach (ref readonly string key in keys)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
/// <summary>
|
||||
@@ -26,7 +28,7 @@ internal readonly partial struct PlayerUid
|
||||
/// <param name="region">服务器,当提供该参数时会无条件信任</param>
|
||||
public PlayerUid(string value, in Region? region = default)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.UidRegex().IsMatch(value), SH.WebHoyolabInvalidUid);
|
||||
HutaoException.ThrowIfNot(HoyolabRegex.UidRegex().IsMatch(value), SH.WebHoyolabInvalidUid);
|
||||
Value = value;
|
||||
Region = region ?? Region.UnsafeFromUidString(value);
|
||||
}
|
||||
@@ -43,9 +45,7 @@ internal readonly partial struct PlayerUid
|
||||
|
||||
public static bool IsOversea(string uid)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
|
||||
|
||||
ReadOnlySpan<char> uidSpan = uid.AsSpan();
|
||||
HutaoException.ThrowIfNot(HoyolabRegex.UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
|
||||
|
||||
return uid.AsSpan()[^9] switch
|
||||
{
|
||||
@@ -56,7 +56,7 @@ internal readonly partial struct PlayerUid
|
||||
|
||||
public static TimeSpan GetRegionTimeZoneUtcOffsetForUid(string uid)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
|
||||
HutaoException.ThrowIfNot(HoyolabRegex.UidRegex().IsMatch(uid), SH.WebHoyolabInvalidUid);
|
||||
|
||||
// 美服 UTC-05
|
||||
// 欧服 UTC+01
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Core.ExceptionService;
|
||||
|
||||
namespace Snap.Hutao.Web.Hoyolab;
|
||||
|
||||
[JsonConverter(typeof(RegionConverter))]
|
||||
@@ -17,7 +19,7 @@ internal readonly struct Region
|
||||
|
||||
public Region(string value)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.RegionRegex().IsMatch(value), SH.WebHoyolabInvalidRegion);
|
||||
HutaoException.ThrowIfNot(HoyolabRegex.RegionRegex().IsMatch(value), SH.WebHoyolabInvalidRegion);
|
||||
Value = value;
|
||||
}
|
||||
|
||||
@@ -44,13 +46,13 @@ internal readonly struct Region
|
||||
'7' => new("os_euro"), // 欧服
|
||||
'8' => new("os_asia"), // 亚服
|
||||
'9' => new("os_cht"), // 台服
|
||||
_ => throw Must.NeverHappen(),
|
||||
_ => throw HutaoException.NotSupported(),
|
||||
};
|
||||
}
|
||||
|
||||
public static bool IsOversea(string value)
|
||||
{
|
||||
Must.Argument(HoyolabRegex.RegionRegex().IsMatch(value), SH.WebHoyolabInvalidRegion);
|
||||
HutaoException.ThrowIfNot(HoyolabRegex.RegionRegex().IsMatch(value), SH.WebHoyolabInvalidRegion);
|
||||
return value.AsSpan()[..2] switch
|
||||
{
|
||||
"os" => true,
|
||||
|
||||
@@ -22,8 +22,8 @@ internal static class AvatarPromotionDeltaExtension
|
||||
return false;
|
||||
}
|
||||
|
||||
copy.SkillList = new(3)
|
||||
{
|
||||
copy.SkillList =
|
||||
[
|
||||
new()
|
||||
{
|
||||
Id = skillViewA.GroupId,
|
||||
@@ -42,7 +42,7 @@ internal static class AvatarPromotionDeltaExtension
|
||||
LevelCurrent = Math.Min(skillViewQ.LevelNumber, deltaQ.LevelTarget),
|
||||
LevelTarget = deltaQ.LevelTarget,
|
||||
},
|
||||
};
|
||||
];
|
||||
|
||||
if (avatar.Weapon is not WeaponView weaponView || source.Weapon is not { } deltaWeapon)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ internal abstract class HttpContentSerializer : IHttpContentSerializer, IHttpCon
|
||||
The content to be serialized does not match the specified type.
|
||||
Expected an instance of the class "{contentType.FullName}", but got "{actualContentType.FullName}".
|
||||
""";
|
||||
ThrowHelper.Argument(message, nameof(contentType));
|
||||
HutaoException.Argument(message, nameof(contentType));
|
||||
}
|
||||
|
||||
// The contentType is optional. In that case, try to get the type on our own.
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Snap.Hutao.Web.Request.Builder;
|
||||
|
||||
internal static class HttpRequestMessageBuilderExtension
|
||||
{
|
||||
private const string RequestErrorMessage = "请求异常已忽略: {0}";
|
||||
private const string RequestErrorMessage = "请求异常已忽略: {Uri}";
|
||||
|
||||
internal static async ValueTask<TResult?> TryCatchSendAsync<TResult>(this HttpRequestMessageBuilder builder, HttpClient httpClient, ILogger logger, CancellationToken token)
|
||||
where TResult : class
|
||||
|
||||
@@ -30,6 +30,7 @@ internal static class D3D11
|
||||
[DllImport("d3d11.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
|
||||
public static unsafe extern HRESULT D3D11CreateDevice([AllowNull] IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, D3D11_CREATE_DEVICE_FLAG Flags, [AllowNull] D3D_FEATURE_LEVEL* pFeatureLevels, uint FeatureLevels, uint SDKVersion, [MaybeNull] ID3D11Device** ppDevice, [MaybeNull] D3D_FEATURE_LEVEL* pFeatureLevel, [MaybeNull] ID3D11DeviceContext** ppImmediateContext);
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe HRESULT D3D11CreateDevice([AllowNull] IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, D3D11_CREATE_DEVICE_FLAG Flags, [AllowNull] ReadOnlySpan<D3D_FEATURE_LEVEL> featureLevels, uint SDKVersion, out ID3D11Device* pDevice, out D3D_FEATURE_LEVEL featureLevel, out ID3D11DeviceContext* pImmediateContext)
|
||||
{
|
||||
fixed (ID3D11Device** ppDevice = &pDevice)
|
||||
|
||||
@@ -14,6 +14,7 @@ internal struct DECIMAL
|
||||
|
||||
public byte sign;
|
||||
|
||||
[SuppressMessage("", "IDE1006")]
|
||||
public unsafe ushort signscale
|
||||
{
|
||||
get
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
|
||||
[SuppressMessage("", "CA1069")]
|
||||
internal enum D3D_PRIMITIVE_TOPOLOGY
|
||||
{
|
||||
D3D_PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.Graphics.Direct3D;
|
||||
|
||||
[SuppressMessage("", "CA1069")]
|
||||
internal enum D3D_SRV_DIMENSION
|
||||
{
|
||||
D3D_SRV_DIMENSION_UNKNOWN = 0,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
|
||||
public struct D3D11_BOX
|
||||
[SuppressMessage("", "SA1307")]
|
||||
internal struct D3D11_BOX
|
||||
{
|
||||
public uint left;
|
||||
public uint top;
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
|
||||
internal enum D3D11_COUNTER
|
||||
{
|
||||
D3D11_COUNTER_DEVICE_DEPENDENT_0 = 0x40000000
|
||||
D3D11_COUNTER_DEVICE_DEPENDENT_0 = 0x40000000,
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
|
||||
[Flags]
|
||||
public enum D3D11_CREATE_DEVICE_FLAG : uint
|
||||
internal enum D3D11_CREATE_DEVICE_FLAG : uint
|
||||
{
|
||||
D3D11_CREATE_DEVICE_SINGLETHREADED = 0x1U,
|
||||
D3D11_CREATE_DEVICE_DEBUG = 0x2U,
|
||||
|
||||
@@ -14,7 +14,7 @@ internal struct D3D11_DEPTH_STENCIL_VIEW_DESC
|
||||
public Union Anonymous;
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Union
|
||||
internal struct Union
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public D3D11_TEX1D_DSV Texture1D;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.Graphics.Direct3D11;
|
||||
|
||||
public struct D3D11_TEX3D_UAV
|
||||
internal struct D3D11_TEX3D_UAV
|
||||
{
|
||||
public uint MipSlice;
|
||||
public uint FirstWSlice;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.Graphics.Dxgi;
|
||||
|
||||
[SuppressMessage("", "SA1307")]
|
||||
internal struct DXGI_MAPPED_RECT
|
||||
{
|
||||
public int Pitch;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
namespace Snap.Hutao.Win32.Graphics.Gdi;
|
||||
|
||||
// InvalidHandleValue: -1, 0
|
||||
#pragma warning disable CS0660, CS0661
|
||||
internal readonly struct HDC
|
||||
{
|
||||
public static readonly HDC NULL = 0;
|
||||
@@ -15,4 +16,5 @@ internal readonly struct HDC
|
||||
public static unsafe bool operator ==(HDC left, HDC right) => *(nint*)&left == *(nint*)&right;
|
||||
|
||||
public static unsafe bool operator !=(HDC left, HDC right) => *(nint*)&left != *(nint*)&right;
|
||||
}
|
||||
}
|
||||
#pragma warning restore CS0660, CS0661
|
||||
@@ -18,6 +18,7 @@ internal static class Ole32
|
||||
public static unsafe extern HRESULT CoCreateInstance(Guid* rclsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, Guid* riid, void** ppv);
|
||||
|
||||
[DebuggerStepThrough]
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe HRESULT CoCreateInstance<T>(ref readonly Guid clsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, ref readonly Guid iid, out T* pv)
|
||||
where T : unmanaged
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
namespace Snap.Hutao.Win32.System.Variant;
|
||||
|
||||
[SuppressMessage("", "CA1069")]
|
||||
internal enum VARENUM : ushort
|
||||
{
|
||||
VT_EMPTY = 0,
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
|
||||
namespace Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
|
||||
[ComImport]
|
||||
[SuppressMessage("", "SYSLIB1096")]
|
||||
[Guid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IDirect3DDxgiInterfaceAccess
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Snap.Hutao.Win32.System.WinRT.Graphics.Capture;
|
||||
|
||||
internal static class IGraphicsCaptureItemInteropExtension
|
||||
{
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe HRESULT CreateForWindow(this IGraphicsCaptureItemInterop interop, HWND window, out GraphicsCaptureItem result)
|
||||
{
|
||||
void* resultPtr = default;
|
||||
@@ -22,6 +23,7 @@ internal static class IGraphicsCaptureItemInteropExtension
|
||||
return retVal;
|
||||
}
|
||||
|
||||
[SuppressMessage("", "SH002")]
|
||||
public static unsafe HRESULT CreateForMonitor(this IGraphicsCaptureItemInterop interop, HMONITOR monitor, out GraphicsCaptureItem result)
|
||||
{
|
||||
void* resultPtr = default;
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Win32.System.WinRT;
|
||||
|
||||
internal unsafe struct IInspectable
|
||||
internal unsafe readonly struct IInspectable
|
||||
{
|
||||
public readonly Vftbl* ThisPtr;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Runtime.Versioning;
|
||||
namespace Snap.Hutao.Win32.UI.Shell;
|
||||
|
||||
[SupportedOSPlatform("windows6.0.6000")]
|
||||
internal unsafe struct IShellItemFilter
|
||||
internal unsafe readonly struct IShellItemFilter
|
||||
{
|
||||
public readonly Vftbl* ThisPtr;
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Win32.UI.Shell;
|
||||
|
||||
internal unsafe readonly struct SUBCLASSPROC
|
||||
{
|
||||
[SuppressMessage("", "IDE0052")]
|
||||
private readonly delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, nuint, nuint, LRESULT> value;
|
||||
|
||||
public SUBCLASSPROC(delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, nuint, nuint, LRESULT> method)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Win32.Foundation;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Snap.Hutao.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
internal unsafe readonly struct WNDPROC
|
||||
{
|
||||
[SuppressMessage("", "IDE0052")]
|
||||
private readonly delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, LRESULT> value;
|
||||
|
||||
public WNDPROC(delegate* unmanaged[Stdcall]<HWND, uint, WPARAM, LPARAM, LRESULT> method)
|
||||
|
||||
Reference in New Issue
Block a user