code style

This commit is contained in:
Lightczx
2024-06-20 10:11:19 +08:00
parent f490805875
commit 70f4dcb2c9
6 changed files with 12 additions and 68 deletions

View File

@@ -26,7 +26,7 @@ internal sealed class XamlWindowSubclass : IDisposable
// We have to explicitly hold a reference to SUBCLASSPROC
private SUBCLASSPROC windowProc = default!;
private UnmanagedAccess<XamlWindowSubclass> unmanagedAccess = default!;
private GCHandle unmanagedAccess = default!;
public XamlWindowSubclass(Window window)
{
@@ -37,22 +37,22 @@ internal sealed class XamlWindowSubclass : IDisposable
public unsafe bool Initialize()
{
windowProc = SUBCLASSPROC.Create(&OnSubclassProcedure);
unmanagedAccess = UnmanagedAccess.Create(this);
return SetWindowSubclass(hwnd, windowProc, WindowSubclassId, unmanagedAccess);
unmanagedAccess = GCHandle.Alloc(this);
return SetWindowSubclass(hwnd, windowProc, WindowSubclassId, (nuint)GCHandle.ToIntPtr(unmanagedAccess));
}
public void Dispose()
{
RemoveWindowSubclass(hwnd, windowProc, WindowSubclassId);
windowProc = default!;
unmanagedAccess.Dispose();
unmanagedAccess.Free();
}
[SuppressMessage("", "SH002")]
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe LRESULT OnSubclassProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam, nuint uIdSubclass, nuint dwRefData)
{
XamlWindowSubclass? state = UnmanagedAccess.Get<XamlWindowSubclass>(dwRefData);
XamlWindowSubclass? state = GCHandle.FromIntPtr((nint)dwRefData).Target as XamlWindowSubclass;
ArgumentNullException.ThrowIfNull(state);
switch (uMsg)

View File

@@ -103,7 +103,7 @@ internal sealed partial class PackageConverter
}
else
{
// backup
// Backup
FileOperation.Move(sdkDll, sdkDllBackup, true);
FileOperation.Move(sdkVersion, sdkVersionBackup, true);
}

View File

@@ -407,9 +407,6 @@ internal static class ApiEndpoints
private const string PublicOperationHk4e = "https://public-operation-hk4e.mihoyo.com";
private const string PublicOperationHk4eGachaInfoApi = $"{PublicOperationHk4e}/gacha_info/api";
private const string SdkStatic = "https://sdk-static.mihoyo.com";
private const string SdkStaticLauncherApi = $"{SdkStatic}/hk4e_cn/mdk/launcher/api";
/// <summary>
/// Referer: https://webstatic.mihoyo.com
/// </summary>

View File

@@ -300,17 +300,17 @@ internal static class ApiOsEndpoints
#region SgHoyoPlayApi
public static string SgHoyoPlayConnectGamePackages(LaunchScheme scheme)
public static string HoyoPlayConnectGamePackages(LaunchScheme scheme)
{
return $"{SgHoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}";
}
public static string SgHoyoPlayConnectGameChannelSDKs(LaunchScheme scheme)
public static string HoyoPlayConnectGameChannelSDKs(LaunchScheme scheme)
{
return $"{SgHoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}&sub_channel={scheme.SubChannel:D}";
}
public static string SgHoyoPlayConnectDeprecatedFileConfigs(LaunchScheme scheme)
public static string HoyoPlayConnectDeprecatedFileConfigs(LaunchScheme scheme)
{
return $"{SgHoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}&sub_channel={scheme.SubChannel:D}";
}

View File

@@ -24,7 +24,7 @@ internal sealed partial class HoyoPlayClient
public async ValueTask<Response<GamePackagesWrapper>> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default)
{
string url = scheme.IsOversea
? ApiOsEndpoints.SgHoyoPlayConnectGamePackages(scheme)
? ApiOsEndpoints.HoyoPlayConnectGamePackages(scheme)
: ApiEndpoints.HoyoPlayConnectGamePackages(scheme);
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -41,7 +41,7 @@ internal sealed partial class HoyoPlayClient
public async ValueTask<Response<GameChannelSDKsWrapper>> GetChannelSDKAsync(LaunchScheme scheme, CancellationToken token = default)
{
string url = scheme.IsOversea
? ApiOsEndpoints.SgHoyoPlayConnectGameChannelSDKs(scheme)
? ApiOsEndpoints.HoyoPlayConnectGameChannelSDKs(scheme)
: ApiEndpoints.HoyoPlayConnectGameChannelSDKs(scheme);
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()
@@ -58,7 +58,7 @@ internal sealed partial class HoyoPlayClient
public async ValueTask<Response<DeprecatedFileConfigurationsWrapper>> GetDeprecatedFileConfigurationsAsync(LaunchScheme scheme, CancellationToken token = default)
{
string url = scheme.IsOversea
? ApiOsEndpoints.SgHoyoPlayConnectDeprecatedFileConfigs(scheme)
? ApiOsEndpoints.HoyoPlayConnectDeprecatedFileConfigs(scheme)
: ApiEndpoints.HoyoPlayConnectDeprecatedFileConfigs(scheme);
HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create()

View File

@@ -1,53 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using System.Runtime.InteropServices;
namespace Snap.Hutao.Win32;
internal readonly struct UnmanagedAccess<T> : IDisposable
where T : class
{
private readonly nint handle;
public UnmanagedAccess(T value)
{
handle = GCHandle.ToIntPtr(GCHandle.Alloc(value));
}
public static implicit operator nint(UnmanagedAccess<T> access)
{
return access.handle;
}
public static implicit operator nuint(UnmanagedAccess<T> access)
{
return (nuint)access.handle;
}
public void Dispose()
{
GCHandle.FromIntPtr(handle).Free();
}
}
internal static class UnmanagedAccess
{
public static UnmanagedAccess<T> Create<T>(T value)
where T : class
{
return new UnmanagedAccess<T>(value);
}
public static T? Get<T>(nint handle)
where T : class
{
return GCHandle.FromIntPtr(handle).Target as T;
}
public static T? Get<T>(nuint handle)
where T : class
{
return GCHandle.FromIntPtr((nint)handle).Target as T;
}
}