From 492e8673913d8d2d0a393aacaeba16b8d0215e9b Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Fri, 24 May 2024 17:16:33 +0800 Subject: [PATCH] exception refine --- .../Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs | 2 +- .../Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs | 2 +- .../Automation/ScreenCapture/GameScreenCaptureMemoryPool.cs | 2 +- src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs index b58517d5..c5ab5581 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/HotKey/HotKeyMessageWindow.cs @@ -33,7 +33,7 @@ internal sealed class HotKeyMessageWindow : IDisposable atom = RegisterClassW(&wc); } - ArgumentOutOfRangeException.ThrowIfEqual(atom, 0); + ArgumentOutOfRangeException.ThrowIfZero(atom); HWND = CreateWindowExW(0, WindowClassName, WindowClassName, 0, 0, 0, 0, 0, default, default, default, default); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs index 645ae0f2..506e118a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconMessageWindow.cs @@ -38,7 +38,7 @@ internal sealed class NotifyIconMessageWindow : IDisposable atom = RegisterClassW(&wc); } - ArgumentOutOfRangeException.ThrowIfEqual(atom, 0); + ArgumentOutOfRangeException.ThrowIfZero(atom); // https://learn.microsoft.com/zh,cn/windows/win32/shell/taskbar#taskbar,creation,notification WM_TASKBARCREATED = RegisterWindowMessageW("TaskbarCreated"); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Automation/ScreenCapture/GameScreenCaptureMemoryPool.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Automation/ScreenCapture/GameScreenCaptureMemoryPool.cs index d382030b..cbe4dacd 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Automation/ScreenCapture/GameScreenCaptureMemoryPool.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Automation/ScreenCapture/GameScreenCaptureMemoryPool.cs @@ -25,7 +25,7 @@ internal sealed class GameScreenCaptureMemoryPool : MemoryPool public override IMemoryOwner Rent(int minBufferSize = -1) { - ArgumentOutOfRangeException.ThrowIfLessThan(minBufferSize, 0); + ArgumentOutOfRangeException.ThrowIfNegative(minBufferSize); lock (syncRoot) { diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs index 85ab7b52..c582bb04 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/CookieExtension.cs @@ -46,7 +46,7 @@ internal static class CookieExtension private static bool TryGetValuesToCookie(this Cookie source, in ReadOnlySpan keys, [NotNullWhen(true)] out Cookie? cookie) { - ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(keys.Length, 0, "Empty keys is not supported"); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(keys.Length); SortedDictionary cookieMap = []; foreach (ref readonly string key in keys)