From c342147809315fb0672915e3ebd3317cc5895df8 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 17 Jun 2024 12:55:17 +0800 Subject: [PATCH 1/6] Add HoyoPlay API --- .../Service/Game/Scheme/LaunchScheme.cs | 4 + .../Game/Scheme/LaunchSchemeBilibili.cs | 4 + .../Game/Scheme/LaunchSchemeChinese.cs | 4 + .../Game/Scheme/LaunchSchemeOversea.cs | 4 + src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs | 22 ++++++ .../Snap.Hutao/Web/ApiOsEndpoints.cs | 22 ++++++ .../HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs | 19 +++++ .../Connect/ChannelSDK/ChannelSDKs.cs | 10 +++ .../Connect/DeprecatedFile/DeprecatedFile.cs | 10 +++ .../DeprecatedFile/DeprecatedFileConfig.cs | 13 ++++ .../DeprecatedFile/DeprecatedFileConfigs.cs | 10 +++ .../HoyoPlay/Connect/GameIdentifier.cs | 13 ++++ .../HoyoPlay/Connect/HoyoPlayClient.cs | 74 +++++++++++++++++++ .../Connect/Package/AudioPackageSegment.cs | 10 +++ .../Hoyolab/HoyoPlay/Connect/Package/Game.cs | 13 ++++ .../HoyoPlay/Connect/Package/GamePackage.cs | 16 ++++ .../HoyoPlay/Connect/Package/Package.cs | 19 +++++ .../HoyoPlay/Connect/PackageSegment.cs | 19 +++++ 18 files changed, 286 insertions(+) create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFile.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/AudioPackageSegment.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs index 30857085..0c98a2fe 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs @@ -45,6 +45,10 @@ internal class LaunchScheme : IEquatable /// public int LauncherId { get; private protected set; } + public string HoyoPlayLauncherId { get; private protected set; } + + public string HoyoPlayGameId { get; private protected set; } + /// /// API Key /// diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs index 1d96e21d..9819b3e5 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs @@ -9,11 +9,15 @@ internal sealed class LaunchSchemeBilibili : LaunchScheme { private const int SdkStaticLauncherBilibiliId = 17; private const string SdkStaticLauncherBilibiliKey = "KAtdSsoQ"; + private const string HoyoPlayLauncherBilibiliId = "umfgRO5gh5"; + private const string HoyoPlayGameBilibiliId = "T2S0Gz4Dr2"; public LaunchSchemeBilibili(SubChannelType subChannel, bool isNotCompatOnly = true) { LauncherId = SdkStaticLauncherBilibiliId; Key = SdkStaticLauncherBilibiliKey; + HoyoPlayLauncherId = HoyoPlayLauncherBilibiliId; + HoyoPlayGameId = HoyoPlayGameBilibiliId; Channel = ChannelType.Bili; SubChannel = subChannel; IsOversea = false; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs index e9d27c6d..6c5dd21d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs @@ -9,11 +9,15 @@ internal sealed class LaunchSchemeChinese : LaunchScheme { private const int SdkStaticLauncherChineseId = 18; private const string SdkStaticLauncherChineseKey = "eYd89JmJ"; + private const string HoyoPlayLauncherChineseId = "jGHBHlcOq1"; + private const string HoyoPlayGameChineseId = "1Z8W5NHUQb"; public LaunchSchemeChinese(ChannelType channel, SubChannelType subChannel, bool isNotCompatOnly = true) { LauncherId = SdkStaticLauncherChineseId; Key = SdkStaticLauncherChineseKey; + HoyoPlayLauncherId = HoyoPlayLauncherChineseId; + HoyoPlayGameId = HoyoPlayGameChineseId; Channel = channel; SubChannel = subChannel; IsOversea = false; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs index 08b6799a..f39a4be9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs @@ -9,11 +9,15 @@ internal sealed class LaunchSchemeOversea : LaunchScheme { private const int SdkStaticLauncherOverseaId = 10; private const string SdkStaticLauncherOverseaKey = "gcStgarh"; + private const string HoyoPlayLauncherOverseaId = "VYTpXlbWo8"; + private const string HoyoPlayGameOverseaId = "gopR6Cufr3"; public LaunchSchemeOversea(ChannelType channel, SubChannelType subChannel, bool isNotCompatOnly = true) { LauncherId = SdkStaticLauncherOverseaId; Key = SdkStaticLauncherOverseaKey; + HoyoPlayLauncherId = HoyoPlayLauncherOverseaId; + HoyoPlayGameId = HoyoPlayGameOverseaId; Channel = channel; SubChannel = subChannel; IsOversea = true; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs index fa053f12..5381aaed 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs @@ -284,6 +284,25 @@ internal static class ApiEndpoints #endregion + #region HoyoPlayApi + + public static string HoyoPlayConnectGamePackages(LaunchScheme scheme) + { + return $"{HoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}"; + } + + public static string HoyoPlayConnectGameChannelSDKs(LaunchScheme scheme) + { + return $"{HoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + } + + public static string HoyoPlayConnectDeprecatedFileConfigs(LaunchScheme scheme) + { + return $"{HoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + } + + #endregion + #region PassportApi | PassportApiV4 /// @@ -395,6 +414,9 @@ internal static class ApiEndpoints private const string Hk4eSdk = "https://hk4e-sdk.mihoyo.com"; + private const string HoyoPlayApi = "https://hyp-api.mihoyo.com"; + private const string HoyoPlayApiConnectApi = $"{HoyoPlayApi}/hyp/hyp-connect/api"; + private const string PassportApi = "https://passport-api.mihoyo.com"; private const string PassportApiAuthApi = $"{PassportApi}/account/auth/api"; private const string PassportApiV4 = "https://passport-api-v4.mihoyo.com"; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs index a9a8ffd7..efc5b4da 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs @@ -298,6 +298,25 @@ internal static class ApiOsEndpoints } #endregion + #region SgHoyoPlayApi + + public static string SgHoyoPlayConnectGamePackages(LaunchScheme scheme) + { + return $"{SgHoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}"; + } + + public static string SgHoyoPlayConnectGameChannelSDKs(LaunchScheme scheme) + { + return $"{SgHoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + } + + public static string SgHoyoPlayConnectDeprecatedFileConfigs(LaunchScheme scheme) + { + return $"{SgHoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + } + + #endregion + #region SdkOsStaticLauncherApi public static string SdkOsStaticLauncherResource(LaunchScheme scheme) @@ -344,6 +363,9 @@ internal static class ApiOsEndpoints private const string SgPublicApi = "https://sg-public-api.hoyoverse.com"; private const string SgHk4eApi = "https://sg-hk4e-api.hoyoverse.com"; + private const string SgHoyoPlayApi = "https://sg-hyp-api.hoyoverse.com"; + private const string SgHoyoPlayApiConnectApi = $"{SgHoyoPlayApi}/hyp/hyp-connect/api"; + private const string WebApiOs = "https://webapi-os.account.hoyoverse.com"; private const string WebApiOsAccountApi = $"{WebApiOs}/Api"; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs new file mode 100644 index 00000000..3586926c --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs @@ -0,0 +1,19 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; + +internal sealed class ChannelSDK +{ + [JsonPropertyName("channel_sdk_pkg")] + public PackageSegment ChannelSdkPackage { get; set; } = default!; + + [JsonPropertyName("game")] + public GameIdentifier Game { get; set; } = default!; + + [JsonPropertyName("pkg_version_file_name")] + public string PackageVersionFileName { get; set; } = default!; + + [JsonPropertyName("version")] + public string Version { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs new file mode 100644 index 00000000..9d74ca48 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; + +internal sealed class ChannelSDKs +{ + [JsonPropertyName("game_channel_sdks")] + public List GameChannelSDKs { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFile.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFile.cs new file mode 100644 index 00000000..e42f15df --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFile.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; + +internal sealed class DeprecatedFile +{ + [JsonPropertyName("name")] + public string Name { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs new file mode 100644 index 00000000..49d3dbae --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; + +internal sealed class DeprecatedFileConfig +{ + [JsonPropertyName("deprecated_files")] + public List DeprecatedFiles { get; set; } = default!; + + [JsonPropertyName("game")] + public GameIdentifier Game { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs new file mode 100644 index 00000000..b63bd23c --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; + +internal sealed class DeprecatedFileConfigs +{ + [JsonPropertyName("deprecated_file_configs")] + public List Configs { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs new file mode 100644 index 00000000..0ddbb308 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; + +internal sealed class GameIdentifier +{ + [JsonPropertyName("id")] + public string Id { get; set; } = default!; + + [JsonPropertyName("biz")] + public string Biz { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs new file mode 100644 index 00000000..cd9738e5 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs @@ -0,0 +1,74 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient; +using Snap.Hutao.Service.Game.Scheme; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; +using Snap.Hutao.Web.Request.Builder; +using Snap.Hutao.Web.Request.Builder.Abstraction; +using Snap.Hutao.Web.Response; +using System.Net.Http; + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; + +[ConstructorGenerated(ResolveHttpClient = true)] +[HttpClient(HttpClientConfiguration.Default)] +internal sealed partial class HoyoPlayClient +{ + private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory; + private readonly HttpClient httpClient; + private readonly ILogger logger; + + public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) + { + string url = scheme.IsOversea + ? ApiOsEndpoints.SgHoyoPlayConnectGamePackages(scheme) + : ApiEndpoints.HoyoPlayConnectGamePackages(scheme); + + HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() + .SetRequestUri(url) + .Get(); + + Response? resp = await builder + .SendAsync>(httpClient, logger, token) + .ConfigureAwait(false); + + return Response.Response.DefaultIfNull(resp); + } + + public async ValueTask> GetChannelSDKAsync(LaunchScheme scheme, CancellationToken token = default) + { + string url = scheme.IsOversea + ? ApiOsEndpoints.SgHoyoPlayConnectGameChannelSDKs(scheme) + : ApiEndpoints.HoyoPlayConnectGameChannelSDKs(scheme); + + HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() + .SetRequestUri(url) + .Get(); + + Response? resp = await builder + .SendAsync>(httpClient, logger, token) + .ConfigureAwait(false); + + return Response.Response.DefaultIfNull(resp); + } + + public async ValueTask> GetDeprecatedFilesAsync(LaunchScheme scheme, CancellationToken token = default) + { + string url = scheme.IsOversea + ? ApiOsEndpoints.SgHoyoPlayConnectDeprecatedFileConfigs(scheme) + : ApiEndpoints.HoyoPlayConnectDeprecatedFileConfigs(scheme); + + HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() + .SetRequestUri(url) + .Get(); + + Response? resp = await builder + .SendAsync>(httpClient, logger, token) + .ConfigureAwait(false); + + return Response.Response.DefaultIfNull(resp); + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/AudioPackageSegment.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/AudioPackageSegment.cs new file mode 100644 index 00000000..451a7dcd --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/AudioPackageSegment.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; + +internal sealed class AudioPackageSegment : PackageSegment +{ + [JsonPropertyName("language")] + public string Language { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs new file mode 100644 index 00000000..b23bd126 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; + +internal sealed class Game +{ + [JsonPropertyName("major")] + public Package? Major { get; set; } + + [JsonPropertyName("patches")] + public List Patches { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs new file mode 100644 index 00000000..6ecea371 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs @@ -0,0 +1,16 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; + +internal sealed class GamePackage +{ + [JsonPropertyName("game")] + public GameIdentifier Game { get; set; } = default!; + + [JsonPropertyName("main")] + public Game Main { get; set; } = default!; + + [JsonPropertyName("pre_download")] + public Game PreDownload { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs new file mode 100644 index 00000000..6cf3592c --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs @@ -0,0 +1,19 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; + +internal sealed class Package +{ + [JsonPropertyName("version")] + public string Version { get; set; } = default!; + + [JsonPropertyName("game_pkgs")] + public List GamePackages { get; set; } = default!; + + [JsonPropertyName("audio_pkgs")] + public List AudioPackages { get; set; } = default!; + + [JsonPropertyName("res_list_url")] + public string ResListUrl { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs new file mode 100644 index 00000000..42a828c6 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs @@ -0,0 +1,19 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; + +internal class PackageSegment +{ + [JsonPropertyName("url")] + public string Url { get; set; } = default!; + + [JsonPropertyName("md5")] + public string Md5 { get; set; } = default!; + + [JsonPropertyName("size")] + public string Size { get; set; } = default!; + + [JsonPropertyName("decompressed_size")] + public string DecompressedSize { get; set; } = default!; +} From 9d364a291cd4c89c59afcf3da2bdd296af79938c Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 17 Jun 2024 13:14:03 +0800 Subject: [PATCH 2/6] minor change --- .../Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs | 5 +---- .../Connect/DeprecatedFile/DeprecatedFileConfig.cs | 5 +---- .../HoyoPlay/Connect/{GameIdentifier.cs => Game.cs} | 2 +- .../Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs | 10 ++++++++++ .../Connect/Package/{Game.cs => GameBranch.cs} | 2 +- .../Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs | 9 +++------ 6 files changed, 17 insertions(+), 16 deletions(-) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/{GameIdentifier.cs => Game.cs} (89%) create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/{Game.cs => GameBranch.cs} (90%) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs index 3586926c..18d048d7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs @@ -3,14 +3,11 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; -internal sealed class ChannelSDK +internal sealed class ChannelSDK : GameSpecified { [JsonPropertyName("channel_sdk_pkg")] public PackageSegment ChannelSdkPackage { get; set; } = default!; - [JsonPropertyName("game")] - public GameIdentifier Game { get; set; } = default!; - [JsonPropertyName("pkg_version_file_name")] public string PackageVersionFileName { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs index 49d3dbae..7266f897 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs @@ -3,11 +3,8 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; -internal sealed class DeprecatedFileConfig +internal sealed class DeprecatedFileConfig : GameSpecified { [JsonPropertyName("deprecated_files")] public List DeprecatedFiles { get; set; } = default!; - - [JsonPropertyName("game")] - public GameIdentifier Game { get; set; } = default!; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Game.cs similarity index 89% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Game.cs index 0ddbb308..44f50099 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIdentifier.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Game.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; -internal sealed class GameIdentifier +internal sealed class Game { [JsonPropertyName("id")] public string Id { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs new file mode 100644 index 00000000..58acd2ec --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; + +internal class GameSpecified +{ + [JsonPropertyName("game")] + public Game Game { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs similarity index 90% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs index b23bd126..d3088ecc 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Game.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; -internal sealed class Game +internal sealed class GameBranch { [JsonPropertyName("major")] public Package? Major { get; set; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs index 6ecea371..56af36d4 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs @@ -3,14 +3,11 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; -internal sealed class GamePackage +internal sealed class GamePackage : GameSpecified { - [JsonPropertyName("game")] - public GameIdentifier Game { get; set; } = default!; - [JsonPropertyName("main")] - public Game Main { get; set; } = default!; + public GameBranch Main { get; set; } = default!; [JsonPropertyName("pre_download")] - public Game PreDownload { get; set; } = default!; + public GameBranch PreDownload { get; set; } = default!; } From 0497d89559188f3872598ff0cf1b5e7ed7404b47 Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 17 Jun 2024 15:01:36 +0800 Subject: [PATCH 3/6] refactor launchgame resources --- .../Service/Game/Scheme/LaunchScheme.cs | 4 +- .../Control/LaunchGameResourceExpander.xaml | 54 +++---------------- .../Snap.Hutao/View/Page/LaunchGamePage.xaml | 12 ++--- .../ViewModel/Game/LaunchGameViewModel.cs | 22 ++++---- .../HoyoPlay/Connect/HoyoPlayClient.cs | 6 +-- .../HoyoPlay/Connect/Package/GamePackages.cs | 10 ++++ .../HoyoPlay/Connect/Package/Package.cs | 6 +++ .../HoyoPlay/Connect/PackageSegment.cs | 20 +++++-- 8 files changed, 62 insertions(+), 72 deletions(-) create mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs index 0c98a2fe..1e96ccb9 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs @@ -45,9 +45,9 @@ internal class LaunchScheme : IEquatable /// public int LauncherId { get; private protected set; } - public string HoyoPlayLauncherId { get; private protected set; } + public string HoyoPlayLauncherId { get; private protected set; } = default!; - public string HoyoPlayGameId { get; private protected set; } + public string HoyoPlayGameId { get; private protected set; } = default!; /// /// API Key diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml index b937a820..01c448f7 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml @@ -6,12 +6,13 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:shcm="using:Snap.Hutao.Control.Markup" - xmlns:shwhshlr="using:Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource" + xmlns:shwhhpc="using:Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect" + xmlns:shwhhpcp="using:Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" - d:DataContext="{d:DesignInstance shwhshlr:Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource.Package}" + d:DataContext="{d:DesignInstance shwhhpcp:Package}" IsExpanded="True" - ItemsSource="{Binding VoicePacks}" + ItemsSource="{Binding AllPackages}" mc:Ignorable="d"> @@ -24,7 +25,7 @@ - + + Text="{Binding Size, Converter={StaticResource FileSizeToFriendlyStringConverter}}"/> + Text="{Binding DecompressedSize, Converter={StaticResource FileSizeToFriendlyStringConverter}}"/> - - - - - - - - - - - - - - - - diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml index ac7d718c..307c3cac 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/LaunchGamePage.xaml @@ -366,13 +366,13 @@ - + @@ -382,22 +382,22 @@ + ItemsSource="{Binding GamePackage.PreDownload.Patches, Mode=OneWay}"/> + ItemsSource="{Binding GamePackage.Main.Patches, Mode=OneWay}"/> - + diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs index 79af1cd2..745a2202 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs @@ -15,8 +15,8 @@ using Snap.Hutao.Service.Game.PathAbstraction; using Snap.Hutao.Service.Game.Scheme; using Snap.Hutao.Service.Notification; using Snap.Hutao.Service.User; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; using System.Collections.Immutable; using System.IO; @@ -39,7 +39,6 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView private readonly IGameLocatorFactory gameLocatorFactory; private readonly LaunchGameShared launchGameShared; private readonly IInfoBarService infoBarService; - private readonly ResourceClient resourceClient; private readonly RuntimeOptions runtimeOptions; private readonly LaunchOptions launchOptions; private readonly IUserService userService; @@ -47,11 +46,12 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView private readonly IGameServiceFacade gameService; private readonly IMemoryCache memoryCache; private readonly AppOptions appOptions; + private readonly HoyoPlayClient hoyoPlayClient; private LaunchScheme? selectedScheme; private AdvancedCollectionView? gameAccountsView; private GameAccount? selectedGameAccount; - private GameResource? gameResource; + private GamePackage? gamePackage; private bool gamePathSelectedAndValid; private ImmutableList gamePathEntries; private GamePathEntry? selectedGamePathEntry; @@ -69,7 +69,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView public List KnownSchemes { get; } = KnownLaunchSchemes.Get(); - [AlsoAsyncSets(nameof(GameResource), nameof(GameAccountsView))] + [AlsoAsyncSets(nameof(GameAccountsView), nameof(GamePackage))] public LaunchScheme? SelectedScheme { get => selectedScheme; @@ -80,7 +80,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView public GameAccount? SelectedGameAccount { get => selectedGameAccount; set => SetProperty(ref selectedGameAccount, value); } - public GameResource? GameResource { get => gameResource; set => SetProperty(ref gameResource, value); } + public GamePackage? GamePackage { get => gamePackage; set => SetProperty(ref gamePackage, value); } public bool GamePathSelectedAndValid { @@ -301,10 +301,10 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView SelectedGameAccount = default; await UpdateGameAccountsViewAsync().ConfigureAwait(false); - UpdateGameResourceAsync(value).SafeForget(); + UpdateGamePackageAsync(value).SafeForget(); } - async ValueTask UpdateGameResourceAsync(LaunchScheme? scheme) + async ValueTask UpdateGamePackageAsync(LaunchScheme? scheme) { if (scheme is null) { @@ -312,14 +312,14 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView } await taskContext.SwitchToBackgroundAsync(); - Web.Response.Response response = await resourceClient - .GetResourceAsync(scheme) + Web.Response.Response response = await hoyoPlayClient + .GetPackagesAsync(scheme) .ConfigureAwait(false); if (response.IsOk()) { await taskContext.SwitchToMainThreadAsync(); - GameResource = response.Data; + GamePackage = response.Data.Packages.Single(); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs index cd9738e5..18f31518 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs @@ -21,7 +21,7 @@ internal sealed partial class HoyoPlayClient private readonly HttpClient httpClient; private readonly ILogger logger; - public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) + public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) { string url = scheme.IsOversea ? ApiOsEndpoints.SgHoyoPlayConnectGamePackages(scheme) @@ -31,8 +31,8 @@ internal sealed partial class HoyoPlayClient .SetRequestUri(url) .Get(); - Response? resp = await builder - .SendAsync>(httpClient, logger, token) + Response? resp = await builder + .SendAsync>(httpClient, logger, token) .ConfigureAwait(false); return Response.Response.DefaultIfNull(resp); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs new file mode 100644 index 00000000..1fa71867 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs @@ -0,0 +1,10 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; + +internal sealed class GamePackages +{ + [JsonPropertyName("game_packages")] + public List Packages { get; set; } = default!; +} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs index 6cf3592c..e70dac60 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs @@ -16,4 +16,10 @@ internal sealed class Package [JsonPropertyName("res_list_url")] public string ResListUrl { get; set; } = default!; + + [JsonIgnore] + public List AllPackages + { + get => [.. GamePackages, .. AudioPackages]; + } } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs index 42a828c6..5bc6be1f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs @@ -1,9 +1,12 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Snap.Hutao.Core.IO.DataTransfer; +using Snap.Hutao.Service.Notification; + namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; -internal class PackageSegment +internal partial class PackageSegment { [JsonPropertyName("url")] public string Url { get; set; } = default!; @@ -12,8 +15,19 @@ internal class PackageSegment public string Md5 { get; set; } = default!; [JsonPropertyName("size")] - public string Size { get; set; } = default!; + public long Size { get; set; } = default!; [JsonPropertyName("decompressed_size")] - public string DecompressedSize { get; set; } = default!; + public long DecompressedSize { get; set; } = default!; + + [JsonIgnore] + public string DisplayName { get => System.IO.Path.GetFileName(Url); } + + [Command("CopyPathCommand")] + private void CopyPathToClipboard() + { + IServiceProvider serviceProvider = Ioc.Default; + serviceProvider.GetRequiredService().SetText(Url); + serviceProvider.GetRequiredService().Success(SH.WebGameResourcePathCopySucceed); + } } From 046823245cc738772171b74118c8e111946c159b Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 17 Jun 2024 15:52:43 +0800 Subject: [PATCH 4/6] refactor package converter --- ...aunchExecutionEnsureGameResourceHandler.cs | 34 ++++++++++++++----- .../Service/Game/Package/PackageConverter.cs | 18 +++++----- .../HoyoPlay/Connect/Package/GameBranch.cs | 2 +- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs index dd717a98..60461a74 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs @@ -10,8 +10,10 @@ using Snap.Hutao.Model.Intrinsic; using Snap.Hutao.Service.Game.Configuration; using Snap.Hutao.Service.Game.Package; using Snap.Hutao.View.Dialog; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; using Snap.Hutao.Web.Response; using System.IO; @@ -96,13 +98,29 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio progress.Report(new(SH.ServiceGameEnsureGameResourceQueryResourceInformation)); - ResourceClient resourceClient = context.ServiceProvider.GetRequiredService(); - Response response = await resourceClient.GetResourceAsync(context.Scheme).ConfigureAwait(false); + HoyoPlayClient hoyoPlayClient = context.ServiceProvider.GetRequiredService(); - if (!response.TryGetDataWithoutUINotification(out GameResource? resource)) + Response packagesResp = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false); + if (!packagesResp.TryGetDataWithoutUINotification(out GamePackages? gamePackages)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; - context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(response); + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(packagesResp); + return false; + } + + Response sdkResp = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false); + if (!sdkResp.TryGetDataWithoutUINotification(out ChannelSDKs? channelSDKs)) + { + context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(sdkResp); + return false; + } + + Response deprecatedResp = await hoyoPlayClient.GetDeprecatedFilesAsync(context.Scheme).ConfigureAwait(false); + if (!deprecatedResp.TryGetDataWithoutUINotification(out DeprecatedFileConfigs? deprecatedFileConfigs)) + { + context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(deprecatedResp); return false; } @@ -110,7 +128,7 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio if (!context.Scheme.ExecutableMatches(gameFileName)) { - if (!await packageConverter.EnsureGameResourceAsync(context.Scheme, resource, gameFolder, progress).ConfigureAwait(false)) + if (!await packageConverter.EnsureGameResourceAsync(context.Scheme, gamePackages.Packages.Single(), gameFolder, progress).ConfigureAwait(false)) { context.Result.Kind = LaunchExecutionResultKind.GameResourcePackageConvertInternalError; context.Result.ErrorMessage = SH.ViewModelLaunchGameEnsureGameResourceFail; @@ -124,7 +142,7 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio context.Options.UpdateGamePathAndRefreshEntries(Path.Combine(gameFolder, executableName)); } - await packageConverter.EnsureDeprecatedFilesAndSdkAsync(resource, gameFolder).ConfigureAwait(false); + await packageConverter.EnsureDeprecatedFilesAndSdkAsync(channelSDKs.GameChannelSDKs.SingleOrDefault(), deprecatedFileConfigs.Configs.SingleOrDefault(), gameFolder).ConfigureAwait(false); return true; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs index ae992c04..4caca328 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs @@ -8,7 +8,9 @@ using Snap.Hutao.Core.IO; using Snap.Hutao.Core.IO.Hashing; using Snap.Hutao.Core.IO.Http.Sharding; using Snap.Hutao.Service.Game.Scheme; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; +using Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; using System.Globalization; using System.IO; using System.IO.Compression; @@ -34,7 +36,7 @@ internal sealed partial class PackageConverter private readonly HttpClient httpClient; private readonly ILogger logger; - public async ValueTask EnsureGameResourceAsync(LaunchScheme targetScheme, GameResource gameResource, string gameFolder, IProgress progress) + public async ValueTask EnsureGameResourceAsync(LaunchScheme targetScheme, GamePackage gamePackage, string gameFolder, IProgress progress) { // 以 国服 => 国际 为例 // 1. 下载国际服的 pkg_version 文件,转换为索引字典 @@ -56,7 +58,7 @@ internal sealed partial class PackageConverter // 替换操作等于 先备份国服文件,随后新增国际服文件 // 准备下载链接 - string scatteredFilesUrl = gameResource.Game.Latest.DecompressedPath; + string scatteredFilesUrl = gamePackage.Main.Major.ResListUrl; string pkgVersionUrl = $"{scatteredFilesUrl}/{PackageVersion}"; PackageConverterFileSystemContext context = new(targetScheme.IsOversea, runtimeOptions.GetDataFolderServerCacheFolder(), gameFolder, scatteredFilesUrl); @@ -77,7 +79,7 @@ internal sealed partial class PackageConverter return await ReplaceGameResourceAsync(diffOperations, context, progress).ConfigureAwait(false); } - public async ValueTask EnsureDeprecatedFilesAndSdkAsync(GameResource resource, string gameFolder) + public async ValueTask EnsureDeprecatedFilesAndSdkAsync(ChannelSDK? channelSDK, DeprecatedFileConfig? deprecatedFileConfig, string gameFolder) { string sdkDllBackup = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll.backup"); string sdkDll = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll"); @@ -86,9 +88,9 @@ internal sealed partial class PackageConverter string sdkVersion = Path.Combine(gameFolder, "sdk_pkg_version"); // Only bilibili's sdk is not null - if (resource.Sdk is not null) + if (channelSDK is not null) { - using (Stream sdkWebStream = await httpClient.GetStreamAsync(resource.Sdk.Path).ConfigureAwait(false)) + using (Stream sdkWebStream = await httpClient.GetStreamAsync(channelSDK.ChannelSdkPackage.Url).ConfigureAwait(false)) { ZipFile.ExtractToDirectory(sdkWebStream, gameFolder, true); } @@ -106,9 +108,9 @@ internal sealed partial class PackageConverter FileOperation.Move(sdkVersion, sdkVersionBackup, true); } - if (resource.DeprecatedFiles is not null) + if (deprecatedFileConfig is not null) { - foreach (NameMd5 file in resource.DeprecatedFiles) + foreach (DeprecatedFile file in deprecatedFileConfig.DeprecatedFiles) { string filePath = Path.Combine(gameFolder, file.Name); FileOperation.Move(filePath, $"{filePath}.backup", true); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs index d3088ecc..0e20f404 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GameBranch.cs @@ -6,7 +6,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; internal sealed class GameBranch { [JsonPropertyName("major")] - public Package? Major { get; set; } + public Package Major { get; set; } = default!; [JsonPropertyName("patches")] public List Patches { get; set; } = default!; From 5dfb7fbb63988744a14784edbaa243457120cf7f Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Mon, 17 Jun 2024 18:40:52 +0800 Subject: [PATCH 5/6] rename --- ...LaunchExecutionEnsureGameResourceHandler.cs | 16 ++++++++-------- .../Service/Game/Package/PackageConverter.cs | 4 ++-- .../ViewModel/Game/LaunchGameViewModel.cs | 6 +++--- .../{ChannelSDK.cs => GameChannelSDK.cs} | 2 +- ...hannelSDKs.cs => GameChannelSDKsWrapper.cs} | 4 ++-- ... => DeprecatedFileConfigurationsWrapper.cs} | 4 ++-- ...FileConfig.cs => DeprecatedFilesWrapper.cs} | 2 +- .../{GameSpecified.cs => GameIndexedObject.cs} | 2 +- .../Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs | 18 +++++++++--------- .../HoyoPlay/Connect/Package/GamePackage.cs | 2 +- ...{GamePackages.cs => GamePackagesWrapper.cs} | 4 ++-- .../HoyoPlay/Connect/Package/Package.cs | 2 +- .../SdkStatic/Hk4e/Launcher/ResourceClient.cs | 1 + 13 files changed, 34 insertions(+), 33 deletions(-) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/{ChannelSDK.cs => GameChannelSDK.cs} (89%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/{ChannelSDKs.cs => GameChannelSDKsWrapper.cs} (62%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/{DeprecatedFileConfigs.cs => DeprecatedFileConfigurationsWrapper.cs} (57%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/{DeprecatedFileConfig.cs => DeprecatedFilesWrapper.cs} (80%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/{GameSpecified.cs => GameIndexedObject.cs} (87%) rename src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/{GamePackages.cs => GamePackagesWrapper.cs} (63%) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs index 60461a74..59b635ad 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs @@ -100,24 +100,24 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio HoyoPlayClient hoyoPlayClient = context.ServiceProvider.GetRequiredService(); - Response packagesResp = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false); - if (!packagesResp.TryGetDataWithoutUINotification(out GamePackages? gamePackages)) + Response packagesResp = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false); + if (!packagesResp.TryGetDataWithoutUINotification(out GamePackagesWrapper? gamePackages)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(packagesResp); return false; } - Response sdkResp = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false); - if (!sdkResp.TryGetDataWithoutUINotification(out ChannelSDKs? channelSDKs)) + Response sdkResp = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false); + if (!sdkResp.TryGetDataWithoutUINotification(out GameChannelSDKsWrapper? channelSDKs)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(sdkResp); return false; } - Response deprecatedResp = await hoyoPlayClient.GetDeprecatedFilesAsync(context.Scheme).ConfigureAwait(false); - if (!deprecatedResp.TryGetDataWithoutUINotification(out DeprecatedFileConfigs? deprecatedFileConfigs)) + Response deprecatedResp = await hoyoPlayClient.GetDeprecatedFilesAsync(context.Scheme).ConfigureAwait(false); + if (!deprecatedResp.TryGetDataWithoutUINotification(out DeprecatedFileConfigurationsWrapper? deprecatedFileConfigs)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(deprecatedResp); @@ -128,7 +128,7 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio if (!context.Scheme.ExecutableMatches(gameFileName)) { - if (!await packageConverter.EnsureGameResourceAsync(context.Scheme, gamePackages.Packages.Single(), gameFolder, progress).ConfigureAwait(false)) + if (!await packageConverter.EnsureGameResourceAsync(context.Scheme, gamePackages.GamePackages.Single(), gameFolder, progress).ConfigureAwait(false)) { context.Result.Kind = LaunchExecutionResultKind.GameResourcePackageConvertInternalError; context.Result.ErrorMessage = SH.ViewModelLaunchGameEnsureGameResourceFail; @@ -142,7 +142,7 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio context.Options.UpdateGamePathAndRefreshEntries(Path.Combine(gameFolder, executableName)); } - await packageConverter.EnsureDeprecatedFilesAndSdkAsync(channelSDKs.GameChannelSDKs.SingleOrDefault(), deprecatedFileConfigs.Configs.SingleOrDefault(), gameFolder).ConfigureAwait(false); + await packageConverter.EnsureDeprecatedFilesAndSdkAsync(channelSDKs.GameChannelSDKs.SingleOrDefault(), deprecatedFileConfigs.DeprecatedFileConfigurations.SingleOrDefault(), gameFolder).ConfigureAwait(false); return true; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs index 4caca328..0b626723 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs @@ -58,7 +58,7 @@ internal sealed partial class PackageConverter // 替换操作等于 先备份国服文件,随后新增国际服文件 // 准备下载链接 - string scatteredFilesUrl = gamePackage.Main.Major.ResListUrl; + string scatteredFilesUrl = gamePackage.Main.Major.ResourceListUrl; string pkgVersionUrl = $"{scatteredFilesUrl}/{PackageVersion}"; PackageConverterFileSystemContext context = new(targetScheme.IsOversea, runtimeOptions.GetDataFolderServerCacheFolder(), gameFolder, scatteredFilesUrl); @@ -79,7 +79,7 @@ internal sealed partial class PackageConverter return await ReplaceGameResourceAsync(diffOperations, context, progress).ConfigureAwait(false); } - public async ValueTask EnsureDeprecatedFilesAndSdkAsync(ChannelSDK? channelSDK, DeprecatedFileConfig? deprecatedFileConfig, string gameFolder) + public async ValueTask EnsureDeprecatedFilesAndSdkAsync(GameChannelSDK? channelSDK, DeprecatedFilesWrapper? deprecatedFileConfig, string gameFolder) { string sdkDllBackup = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll.backup"); string sdkDll = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll"); diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs index 745a2202..ff951b52 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs @@ -69,7 +69,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView public List KnownSchemes { get; } = KnownLaunchSchemes.Get(); - [AlsoAsyncSets(nameof(GameAccountsView), nameof(GamePackage))] + [AlsoAsyncSets(nameof(GamePackage), nameof(GameAccountsView))] public LaunchScheme? SelectedScheme { get => selectedScheme; @@ -312,14 +312,14 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView } await taskContext.SwitchToBackgroundAsync(); - Web.Response.Response response = await hoyoPlayClient + Web.Response.Response response = await hoyoPlayClient .GetPackagesAsync(scheme) .ConfigureAwait(false); if (response.IsOk()) { await taskContext.SwitchToMainThreadAsync(); - GamePackage = response.Data.Packages.Single(); + GamePackage = response.Data.GamePackages.Single(); } } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDK.cs similarity index 89% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDK.cs index 18d048d7..f7105a42 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDK.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDK.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; -internal sealed class ChannelSDK : GameSpecified +internal sealed class GameChannelSDK : GameIndexedObject { [JsonPropertyName("channel_sdk_pkg")] public PackageSegment ChannelSdkPackage { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDKsWrapper.cs similarity index 62% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDKsWrapper.cs index 9d74ca48..38aec5eb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/ChannelSDKs.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/ChannelSDK/GameChannelSDKsWrapper.cs @@ -3,8 +3,8 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.ChannelSDK; -internal sealed class ChannelSDKs +internal sealed class GameChannelSDKsWrapper { [JsonPropertyName("game_channel_sdks")] - public List GameChannelSDKs { get; set; } = default!; + public List GameChannelSDKs { get; set; } = default!; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigurationsWrapper.cs similarity index 57% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigurationsWrapper.cs index b63bd23c..06c33b07 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigs.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfigurationsWrapper.cs @@ -3,8 +3,8 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; -internal sealed class DeprecatedFileConfigs +internal sealed class DeprecatedFileConfigurationsWrapper { [JsonPropertyName("deprecated_file_configs")] - public List Configs { get; set; } = default!; + public List DeprecatedFileConfigurations { get; set; } = default!; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFilesWrapper.cs similarity index 80% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFilesWrapper.cs index 7266f897..733001a1 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFileConfig.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/DeprecatedFile/DeprecatedFilesWrapper.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.DeprecatedFile; -internal sealed class DeprecatedFileConfig : GameSpecified +internal sealed class DeprecatedFilesWrapper : GameIndexedObject { [JsonPropertyName("deprecated_files")] public List DeprecatedFiles { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs similarity index 87% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs index 58acd2ec..8534c2e5 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameSpecified.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; -internal class GameSpecified +internal class GameIndexedObject { [JsonPropertyName("game")] public Game Game { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs index 18f31518..0843377e 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs @@ -21,7 +21,7 @@ internal sealed partial class HoyoPlayClient private readonly HttpClient httpClient; private readonly ILogger logger; - public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) + public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) { string url = scheme.IsOversea ? ApiOsEndpoints.SgHoyoPlayConnectGamePackages(scheme) @@ -31,14 +31,14 @@ internal sealed partial class HoyoPlayClient .SetRequestUri(url) .Get(); - Response? resp = await builder - .SendAsync>(httpClient, logger, token) + Response? resp = await builder + .SendAsync>(httpClient, logger, token) .ConfigureAwait(false); return Response.Response.DefaultIfNull(resp); } - public async ValueTask> GetChannelSDKAsync(LaunchScheme scheme, CancellationToken token = default) + public async ValueTask> GetChannelSDKAsync(LaunchScheme scheme, CancellationToken token = default) { string url = scheme.IsOversea ? ApiOsEndpoints.SgHoyoPlayConnectGameChannelSDKs(scheme) @@ -48,14 +48,14 @@ internal sealed partial class HoyoPlayClient .SetRequestUri(url) .Get(); - Response? resp = await builder - .SendAsync>(httpClient, logger, token) + Response? resp = await builder + .SendAsync>(httpClient, logger, token) .ConfigureAwait(false); return Response.Response.DefaultIfNull(resp); } - public async ValueTask> GetDeprecatedFilesAsync(LaunchScheme scheme, CancellationToken token = default) + public async ValueTask> GetDeprecatedFilesAsync(LaunchScheme scheme, CancellationToken token = default) { string url = scheme.IsOversea ? ApiOsEndpoints.SgHoyoPlayConnectDeprecatedFileConfigs(scheme) @@ -65,8 +65,8 @@ internal sealed partial class HoyoPlayClient .SetRequestUri(url) .Get(); - Response? resp = await builder - .SendAsync>(httpClient, logger, token) + Response? resp = await builder + .SendAsync>(httpClient, logger, token) .ConfigureAwait(false); return Response.Response.DefaultIfNull(resp); diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs index 56af36d4..b93ff9e3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackage.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; -internal sealed class GamePackage : GameSpecified +internal sealed class GamePackage : GameIndexedObject { [JsonPropertyName("main")] public GameBranch Main { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackagesWrapper.cs similarity index 63% rename from src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs rename to src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackagesWrapper.cs index 1fa71867..ae74e060 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackages.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/GamePackagesWrapper.cs @@ -3,8 +3,8 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect.Package; -internal sealed class GamePackages +internal sealed class GamePackagesWrapper { [JsonPropertyName("game_packages")] - public List Packages { get; set; } = default!; + public List GamePackages { get; set; } = default!; } diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs index e70dac60..7556587f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/Package/Package.cs @@ -15,7 +15,7 @@ internal sealed class Package public List AudioPackages { get; set; } = default!; [JsonPropertyName("res_list_url")] - public string ResListUrl { get; set; } = default!; + public string ResourceListUrl { get; set; } = default!; [JsonIgnore] public List AllPackages diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs index d2001da0..1dfdc369 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs @@ -18,6 +18,7 @@ namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher; [HighQuality] [ConstructorGenerated(ResolveHttpClient = true)] [HttpClient(HttpClientConfiguration.Default)] +[Obsolete("Use HoyoPlayClient instead.")] internal sealed partial class ResourceClient { private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory; From 57b51ed5ee380a5e531f5502d6d3e9c51bb5a8a8 Mon Sep 17 00:00:00 2001 From: DismissedLight <1686188646@qq.com> Date: Mon, 17 Jun 2024 21:32:51 +0800 Subject: [PATCH 6/6] code style --- ...aunchExecutionEnsureGameResourceHandler.cs | 21 ++--- ...LaunchExecutionSetChannelOptionsHandler.cs | 2 +- .../Service/Game/Package/PackageConverter.cs | 8 +- .../Service/Game/Scheme/LaunchScheme.cs | 20 +---- .../Game/Scheme/LaunchSchemeBilibili.cs | 8 +- .../Game/Scheme/LaunchSchemeChinese.cs | 8 +- .../Game/Scheme/LaunchSchemeOversea.cs | 8 +- .../Snap.Hutao/View/Card/AchievementCard.xaml | 1 + .../Snap.Hutao/View/Card/DailyNoteCard.xaml | 1 + .../View/Card/GachaStatisticsCard.xaml | 1 + .../Snap.Hutao/View/Card/LaunchGameCard.xaml | 1 + .../Control/LaunchGameResourceExpander.xaml | 10 +-- .../Game/LaunchGameLaunchExecution.cs | 32 ++++---- .../ViewModel/Game/LaunchGameViewModel.cs | 4 +- src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs | 26 +----- .../Snap.Hutao/Web/ApiOsEndpoints.cs | 21 +---- .../HoyoPlay/Connect/GameIndexedObject.cs | 2 +- .../HoyoPlay/Connect/HoyoPlayClient.cs | 4 +- .../HoyoPlay/Connect/PackageSegment.cs | 2 +- .../Hk4e/Launcher/Content/Advertisement.cs | 22 ------ .../SdkStatic/Hk4e/Launcher/Content/Banner.cs | 22 ------ .../Hk4e/Launcher/Content/GameContent.cs | 28 ------- .../SdkStatic/Hk4e/Launcher/Content/Icon.cs | 43 ---------- .../Hk4e/Launcher/Content/IconLink.cs | 13 --- .../SdkStatic/Hk4e/Launcher/Content/Link.cs | 13 --- .../SdkStatic/Hk4e/Launcher/Content/More.cs | 28 ------- .../SdkStatic/Hk4e/Launcher/Content/Post.cs | 31 -------- .../SdkStatic/Hk4e/Launcher/Content/QQ.cs | 19 ----- .../Hk4e/Launcher/Resource/DiffPackage.cs | 17 ---- .../SdkStatic/Hk4e/Launcher/Resource/Game.cs | 23 ------ .../Hk4e/Launcher/Resource/GameResource.cs | 59 -------------- .../Hk4e/Launcher/Resource/LatestPackage.cs | 12 --- .../Resource/LatestPackageExtension.cs | 22 ------ .../Hk4e/Launcher/Resource/NameMd5.cs | 24 ------ .../Hk4e/Launcher/Resource/Package.cs | 53 ------------- .../Hk4e/Launcher/Resource/PackageSegment.cs | 11 --- .../Hk4e/Launcher/Resource/PathMd5.cs | 39 --------- .../Hk4e/Launcher/Resource/Plugin.cs | 23 ------ .../Hk4e/Launcher/Resource/PluginItem.cs | 35 -------- .../SdkStatic/Hk4e/Launcher/Resource/Sdk.cs | 29 ------- .../Hk4e/Launcher/Resource/VoicePackage.cs | 35 -------- .../SdkStatic/Hk4e/Launcher/ResourceClient.cs | 79 ------------------- 42 files changed, 60 insertions(+), 800 deletions(-) delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Advertisement.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Banner.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/GameContent.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Icon.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/IconLink.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Link.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/More.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Post.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/QQ.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/DiffPackage.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Game.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/GameResource.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackage.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackageExtension.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/NameMd5.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Package.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PackageSegment.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PathMd5.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Plugin.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PluginItem.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Sdk.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/VoicePackage.cs delete mode 100644 src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs index 59b635ad..9047e496 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionEnsureGameResourceHandler.cs @@ -45,7 +45,7 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio return; } - // Backup config file, in order to prevent a incompatible launcher to delete it. + // Backup config file, recover when a incompatible launcher deleted it. context.ServiceProvider.GetRequiredService().Backup(gameFileSystem.GameConfigFilePath); await context.TaskContext.SwitchToMainThreadAsync(); @@ -100,27 +100,28 @@ internal sealed class LaunchExecutionEnsureGameResourceHandler : ILaunchExecutio HoyoPlayClient hoyoPlayClient = context.ServiceProvider.GetRequiredService(); - Response packagesResp = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false); - if (!packagesResp.TryGetDataWithoutUINotification(out GamePackagesWrapper? gamePackages)) + // We perform these requests before package conversion to ensure resources index is intact. + Response packagesResponse = await hoyoPlayClient.GetPackagesAsync(context.Scheme).ConfigureAwait(false); + if (!packagesResponse.TryGetDataWithoutUINotification(out GamePackagesWrapper? gamePackages)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; - context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(packagesResp); + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(packagesResponse); return false; } - Response sdkResp = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false); - if (!sdkResp.TryGetDataWithoutUINotification(out GameChannelSDKsWrapper? channelSDKs)) + Response sdkResponse = await hoyoPlayClient.GetChannelSDKAsync(context.Scheme).ConfigureAwait(false); + if (!sdkResponse.TryGetDataWithoutUINotification(out GameChannelSDKsWrapper? channelSDKs)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; - context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(sdkResp); + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(sdkResponse); return false; } - Response deprecatedResp = await hoyoPlayClient.GetDeprecatedFilesAsync(context.Scheme).ConfigureAwait(false); - if (!deprecatedResp.TryGetDataWithoutUINotification(out DeprecatedFileConfigurationsWrapper? deprecatedFileConfigs)) + Response deprecatedFileResponse = await hoyoPlayClient.GetDeprecatedFileConfigurationsAsync(context.Scheme).ConfigureAwait(false); + if (!deprecatedFileResponse.TryGetDataWithoutUINotification(out DeprecatedFileConfigurationsWrapper? deprecatedFileConfigs)) { context.Result.Kind = LaunchExecutionResultKind.GameResourceIndexQueryInvalidResponse; - context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(deprecatedResp); + context.Result.ErrorMessage = SH.FormatServiceGameLaunchExecutionGameResourceQueryIndexFailed(deprecatedFileResponse); return false; } diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionSetChannelOptionsHandler.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionSetChannelOptionsHandler.cs index 7247b4ae..031c3b95 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionSetChannelOptionsHandler.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Launching/Handler/LaunchExecutionSetChannelOptionsHandler.cs @@ -20,7 +20,7 @@ internal sealed class LaunchExecutionSetChannelOptionsHandler : ILaunchExecution string configPath = gameFileSystem.GameConfigFilePath; context.Logger.LogInformation("Game config file path: {ConfigPath}", configPath); - List elements = default!; + List elements; try { elements = [.. IniSerializer.DeserializeFromFile(configPath)]; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs index 0b626723..c29862d6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Package/PackageConverter.cs @@ -38,7 +38,7 @@ internal sealed partial class PackageConverter public async ValueTask EnsureGameResourceAsync(LaunchScheme targetScheme, GamePackage gamePackage, string gameFolder, IProgress progress) { - // 以 国服 => 国际 为例 + // 以 国服 -> 国际服 为例 // 1. 下载国际服的 pkg_version 文件,转换为索引字典 // 获取本地对应 pkg_version 文件,转换为索引字典 // @@ -79,7 +79,7 @@ internal sealed partial class PackageConverter return await ReplaceGameResourceAsync(diffOperations, context, progress).ConfigureAwait(false); } - public async ValueTask EnsureDeprecatedFilesAndSdkAsync(GameChannelSDK? channelSDK, DeprecatedFilesWrapper? deprecatedFileConfig, string gameFolder) + public async ValueTask EnsureDeprecatedFilesAndSdkAsync(GameChannelSDK? channelSDK, DeprecatedFilesWrapper? deprecatedFiles, string gameFolder) { string sdkDllBackup = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll.backup"); string sdkDll = Path.Combine(gameFolder, YuanShenData, "Plugins\\PCGameSDK.dll"); @@ -108,9 +108,9 @@ internal sealed partial class PackageConverter FileOperation.Move(sdkVersion, sdkVersionBackup, true); } - if (deprecatedFileConfig is not null) + if (deprecatedFiles is not null) { - foreach (DeprecatedFile file in deprecatedFileConfig.DeprecatedFiles) + foreach (DeprecatedFile file in deprecatedFiles.DeprecatedFiles) { string filePath = Path.Combine(gameFolder, file.Name); FileOperation.Move(filePath, $"{filePath}.backup", true); diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs index 1e96ccb9..e7947cc3 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchScheme.cs @@ -30,29 +30,13 @@ internal class LaunchScheme : IEquatable } } - /// - /// 通道 - /// public ChannelType Channel { get; private protected set; } - /// - /// 子通道 - /// public SubChannelType SubChannel { get; private protected set; } - /// - /// 启动器 Id - /// - public int LauncherId { get; private protected set; } + public string LauncherId { get; private protected set; } = default!; - public string HoyoPlayLauncherId { get; private protected set; } = default!; - - public string HoyoPlayGameId { get; private protected set; } = default!; - - /// - /// API Key - /// - public string Key { get; private protected set; } = default!; + public string GameId { get; private protected set; } = default!; /// /// 是否为海外 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs index 9819b3e5..39af831f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeBilibili.cs @@ -7,17 +7,13 @@ namespace Snap.Hutao.Service.Game.Scheme; internal sealed class LaunchSchemeBilibili : LaunchScheme { - private const int SdkStaticLauncherBilibiliId = 17; - private const string SdkStaticLauncherBilibiliKey = "KAtdSsoQ"; private const string HoyoPlayLauncherBilibiliId = "umfgRO5gh5"; private const string HoyoPlayGameBilibiliId = "T2S0Gz4Dr2"; public LaunchSchemeBilibili(SubChannelType subChannel, bool isNotCompatOnly = true) { - LauncherId = SdkStaticLauncherBilibiliId; - Key = SdkStaticLauncherBilibiliKey; - HoyoPlayLauncherId = HoyoPlayLauncherBilibiliId; - HoyoPlayGameId = HoyoPlayGameBilibiliId; + LauncherId = HoyoPlayLauncherBilibiliId; + GameId = HoyoPlayGameBilibiliId; Channel = ChannelType.Bili; SubChannel = subChannel; IsOversea = false; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs index 6c5dd21d..e20fb922 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeChinese.cs @@ -7,17 +7,13 @@ namespace Snap.Hutao.Service.Game.Scheme; internal sealed class LaunchSchemeChinese : LaunchScheme { - private const int SdkStaticLauncherChineseId = 18; - private const string SdkStaticLauncherChineseKey = "eYd89JmJ"; private const string HoyoPlayLauncherChineseId = "jGHBHlcOq1"; private const string HoyoPlayGameChineseId = "1Z8W5NHUQb"; public LaunchSchemeChinese(ChannelType channel, SubChannelType subChannel, bool isNotCompatOnly = true) { - LauncherId = SdkStaticLauncherChineseId; - Key = SdkStaticLauncherChineseKey; - HoyoPlayLauncherId = HoyoPlayLauncherChineseId; - HoyoPlayGameId = HoyoPlayGameChineseId; + LauncherId = HoyoPlayLauncherChineseId; + GameId = HoyoPlayGameChineseId; Channel = channel; SubChannel = subChannel; IsOversea = false; diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs index f39a4be9..45df3e74 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Game/Scheme/LaunchSchemeOversea.cs @@ -7,17 +7,13 @@ namespace Snap.Hutao.Service.Game.Scheme; internal sealed class LaunchSchemeOversea : LaunchScheme { - private const int SdkStaticLauncherOverseaId = 10; - private const string SdkStaticLauncherOverseaKey = "gcStgarh"; private const string HoyoPlayLauncherOverseaId = "VYTpXlbWo8"; private const string HoyoPlayGameOverseaId = "gopR6Cufr3"; public LaunchSchemeOversea(ChannelType channel, SubChannelType subChannel, bool isNotCompatOnly = true) { - LauncherId = SdkStaticLauncherOverseaId; - Key = SdkStaticLauncherOverseaKey; - HoyoPlayLauncherId = HoyoPlayLauncherOverseaId; - HoyoPlayGameId = HoyoPlayGameOverseaId; + LauncherId = HoyoPlayLauncherOverseaId; + GameId = HoyoPlayGameOverseaId; Channel = channel; SubChannel = subChannel; IsOversea = true; diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml index 2a696ffa..5329fc04 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/AchievementCard.xaml @@ -16,6 +16,7 @@ d:DataContext="{d:DesignInstance shva:AchievementViewModelSlim}" Background="Transparent" BorderBrush="{x:Null}" + BorderThickness="0" Command="{Binding NavigateCommand}" Style="{ThemeResource DefaultButtonStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml index 49cccddf..4e447c2b 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/DailyNoteCard.xaml @@ -18,6 +18,7 @@ d:DataContext="{d:DesignInstance shvd:DailyNoteViewModelSlim}" Background="Transparent" BorderBrush="{x:Null}" + BorderThickness="0" Command="{Binding NavigateCommand}" Style="{ThemeResource DefaultButtonStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml index a773211b..aad73941 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/GachaStatisticsCard.xaml @@ -17,6 +17,7 @@ d:DataContext="{d:DesignInstance shvg:GachaLogViewModelSlim}" Background="Transparent" BorderBrush="{x:Null}" + BorderThickness="0" Command="{Binding NavigateCommand}" Style="{ThemeResource DefaultButtonStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Card/LaunchGameCard.xaml b/src/Snap.Hutao/Snap.Hutao/View/Card/LaunchGameCard.xaml index 9a0ecbc9..c1b6ca0f 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Card/LaunchGameCard.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Card/LaunchGameCard.xaml @@ -18,6 +18,7 @@ d:DataContext="{d:DesignInstance shvg:LaunchGameViewModelSlim}" Background="Transparent" BorderBrush="{x:Null}" + BorderThickness="0" Command="{Binding LaunchCommand}" Style="{ThemeResource DefaultButtonStyle}" mc:Ignorable="d"> diff --git a/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml b/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml index 01c448f7..b1e964fe 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Control/LaunchGameResourceExpander.xaml @@ -11,6 +11,7 @@ HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" d:DataContext="{d:DesignInstance shwhhpcp:Package}" + BorderThickness="0" IsExpanded="True" ItemsSource="{Binding AllPackages}" mc:Ignorable="d"> @@ -36,26 +37,23 @@ + Orientation="Horizontal" + Spacing="8"> + Text="{Binding MD5}"/> diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameLaunchExecution.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameLaunchExecution.cs index 0c0752a3..1a088757 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameLaunchExecution.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameLaunchExecution.cs @@ -11,26 +11,26 @@ internal static class LaunchGameLaunchExecution { public static async ValueTask LaunchExecutionAsync(this IViewModelSupportLaunchExecution launchExecution, LaunchScheme? targetScheme) { - IServiceProvider root = Ioc.Default; - IInfoBarService infoBarService = root.GetRequiredService(); - ILogger logger = root.GetRequiredService>(); - - // LaunchScheme? scheme = launchExecution.Shared.GetCurrentLaunchSchemeFromConfigFile(); - try + using (IServiceScope scope = Ioc.Default.CreateScope()) { - // Root service provider is required. - LaunchExecutionContext context = new(root, launchExecution, targetScheme, launchExecution.SelectedGameAccount); - LaunchExecutionResult result = await new LaunchExecutionInvoker().InvokeAsync(context).ConfigureAwait(false); + IInfoBarService infoBarService = scope.ServiceProvider.GetRequiredService(); + ILogger logger = scope.ServiceProvider.GetRequiredService>(); - if (result.Kind is not LaunchExecutionResultKind.Ok) + try { - infoBarService.Warning(result.ErrorMessage); + LaunchExecutionContext context = new(scope.ServiceProvider, launchExecution, targetScheme, launchExecution.SelectedGameAccount); + LaunchExecutionResult result = await new LaunchExecutionInvoker().InvokeAsync(context).ConfigureAwait(false); + + if (result.Kind is not LaunchExecutionResultKind.Ok) + { + infoBarService.Warning(result.ErrorMessage); + } + } + catch (Exception ex) + { + logger.LogCritical(ex, "Launch failed"); + infoBarService.Error(ex); } - } - catch (Exception ex) - { - logger.LogCritical(ex, "Launch failed"); - infoBarService.Error(ex); } } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs index ff951b52..1a5984c4 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs @@ -39,14 +39,14 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView private readonly IGameLocatorFactory gameLocatorFactory; private readonly LaunchGameShared launchGameShared; private readonly IInfoBarService infoBarService; + private readonly IGameServiceFacade gameService; private readonly RuntimeOptions runtimeOptions; + private readonly HoyoPlayClient hoyoPlayClient; private readonly LaunchOptions launchOptions; private readonly IUserService userService; private readonly ITaskContext taskContext; - private readonly IGameServiceFacade gameService; private readonly IMemoryCache memoryCache; private readonly AppOptions appOptions; - private readonly HoyoPlayClient hoyoPlayClient; private LaunchScheme? selectedScheme; private AdvancedCollectionView? gameAccountsView; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs index 5381aaed..ce9fb1e6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiEndpoints.cs @@ -288,17 +288,17 @@ internal static class ApiEndpoints public static string HoyoPlayConnectGamePackages(LaunchScheme scheme) { - return $"{HoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}"; + return $"{HoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}"; } public static string HoyoPlayConnectGameChannelSDKs(LaunchScheme scheme) { - return $"{HoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + return $"{HoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}&sub_channel={scheme.SubChannel:D}"; } public static string HoyoPlayConnectDeprecatedFileConfigs(LaunchScheme scheme) { - return $"{HoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + return $"{HoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}&sub_channel={scheme.SubChannel:D}"; } #endregion @@ -367,26 +367,6 @@ internal static class ApiEndpoints } #endregion - #region SdkStaticLauncherApi - - /// - /// 启动器资源 - /// - /// 启动方案 - /// 启动器资源字符串 - public static string SdkStaticLauncherResource(LaunchScheme scheme) - { - return $"{SdkStaticLauncherApi}/resource?key={scheme.Key}&launcher_id={scheme.LauncherId}&channel_id={scheme.Channel:D}&sub_channel_id={scheme.SubChannel:D}"; - } - - public static string SdkStaticLauncherContent(LaunchScheme scheme, string languageCode, bool advOnly = true) - { - return advOnly - ? $"{SdkStaticLauncherApi}/content?filter_adv=true&key={scheme.Key}&launcher_id={scheme.LauncherId}&language={languageCode}" - : $"{SdkStaticLauncherApi}/content?key={scheme.Key}&launcher_id={scheme.LauncherId}&language={languageCode}"; - } - #endregion - #region Hosts | Queries private const string ApiTakumi = "https://api-takumi.mihoyo.com"; private const string ApiTakumiAuthApi = $"{ApiTakumi}/auth/api"; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs index efc5b4da..41a50529 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/ApiOsEndpoints.cs @@ -302,36 +302,21 @@ internal static class ApiOsEndpoints public static string SgHoyoPlayConnectGamePackages(LaunchScheme scheme) { - return $"{SgHoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}"; + return $"{SgHoyoPlayApiConnectApi}/getGamePackages?game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}"; } public static string SgHoyoPlayConnectGameChannelSDKs(LaunchScheme scheme) { - return $"{SgHoyoPlayApiConnectApi}/getGameChannelSDKs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + 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) { - return $"{SgHoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.HoyoPlayGameId}&launcher_id={scheme.HoyoPlayLauncherId}&sub_channel={scheme.SubChannel:D}"; + return $"{SgHoyoPlayApiConnectApi}/getGameDeprecatedFileConfigs?channel={scheme.Channel:D}&game_ids[]={scheme.GameId}&launcher_id={scheme.LauncherId}&sub_channel={scheme.SubChannel:D}"; } #endregion - #region SdkOsStaticLauncherApi - - public static string SdkOsStaticLauncherResource(LaunchScheme scheme) - { - return $"{SdkOsStaticLauncherApi}/resource?key={scheme.Key}&launcher_id={scheme.LauncherId}&channel_id={scheme.Channel:D}&sub_channel_id={scheme.SubChannel:D}"; - } - - public static string SdkOsStaticLauncherContent(LaunchScheme scheme, string languageCode, bool advOnly = true) - { - return advOnly - ? $"{SdkOsStaticLauncherApi}/content?filter_adv=true&key={scheme.Key}&launcher_id={scheme.LauncherId}&language={languageCode}" - : $"{SdkOsStaticLauncherApi}/content?key={scheme.Key}&launcher_id={scheme.LauncherId}&language={languageCode}"; - } - #endregion - #region WebApiOsAccountApi /// diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs index 8534c2e5..9a2688fa 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/GameIndexedObject.cs @@ -3,7 +3,7 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; -internal class GameIndexedObject +internal abstract class GameIndexedObject { [JsonPropertyName("game")] public Game Game { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs index 0843377e..1d55037d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/HoyoPlayClient.cs @@ -18,8 +18,8 @@ namespace Snap.Hutao.Web.Hoyolab.HoyoPlay.Connect; internal sealed partial class HoyoPlayClient { private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory; - private readonly HttpClient httpClient; private readonly ILogger logger; + private readonly HttpClient httpClient; public async ValueTask> GetPackagesAsync(LaunchScheme scheme, CancellationToken token = default) { @@ -55,7 +55,7 @@ internal sealed partial class HoyoPlayClient return Response.Response.DefaultIfNull(resp); } - public async ValueTask> GetDeprecatedFilesAsync(LaunchScheme scheme, CancellationToken token = default) + public async ValueTask> GetDeprecatedFileConfigurationsAsync(LaunchScheme scheme, CancellationToken token = default) { string url = scheme.IsOversea ? ApiOsEndpoints.SgHoyoPlayConnectDeprecatedFileConfigs(scheme) diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs index 5bc6be1f..c9499532 100644 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs +++ b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/HoyoPlay/Connect/PackageSegment.cs @@ -12,7 +12,7 @@ internal partial class PackageSegment public string Url { get; set; } = default!; [JsonPropertyName("md5")] - public string Md5 { get; set; } = default!; + public string MD5 { get; set; } = default!; [JsonPropertyName("size")] public long Size { get; set; } = default!; diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Advertisement.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Advertisement.cs deleted file mode 100644 index e71f6d41..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Advertisement.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class Advertisement -{ - [JsonPropertyName("background")] - public string Background { get; set; } = default!; - - [JsonPropertyName("icon")] - public string Icon { get; set; } = default!; - - [JsonPropertyName("url")] - public string Url { get; set; } = default!; - - [JsonPropertyName("version")] - public string Version { get; set; } = default!; - - [JsonPropertyName("bg_checksum")] - public string BackgroundChecksum { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Banner.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Banner.cs deleted file mode 100644 index 08fc5bd8..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Banner.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class Banner -{ - [JsonPropertyName("banner_id")] - public string BannerId { get; set; } = default!; - - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - [JsonPropertyName("img")] - public string Image { get; set; } = default!; - - [JsonPropertyName("url")] - public string Url { get; set; } = default!; - - [JsonPropertyName("order")] - public string Order { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/GameContent.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/GameContent.cs deleted file mode 100644 index 5138eb54..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/GameContent.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class GameContent -{ - [JsonPropertyName("adv")] - public Advertisement? Advertisement { get; set; } = default!; - - [JsonPropertyName("banner")] - public List Banners { get; set; } = default!; - - [JsonPropertyName("icon")] - public List Icons { get; set; } = default!; - - [JsonPropertyName("post")] - public List Posts { get; set; } = default!; - - [JsonPropertyName("qq")] - public List QQs { get; set; } = default!; - - [JsonPropertyName("more")] - public More More { get; set; } = default!; - - [JsonPropertyName("links")] - public Link Links { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Icon.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Icon.cs deleted file mode 100644 index 6d3378c5..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Icon.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class Icon -{ - [JsonPropertyName("icon_id")] - public string IconId { get; set; } = default!; - - [JsonPropertyName("img")] - public string Image { get; set; } = default!; - - [JsonPropertyName("url")] - public string Url { get; set; } = default!; - - [JsonPropertyName("qr_img")] - public string QrImage { get; set; } = default!; - - [JsonPropertyName("qr_desc")] - public string QrDescription { get; set; } = default!; - - [JsonPropertyName("img_hover")] - public string ImageHover { get; set; } = default!; - - [JsonPropertyName("other_links")] - public List OtherLinks { get; set; } = default!; - - [JsonPropertyName("title")] - public string Title { get; set; } = default!; - - [JsonPropertyName("icon_link")] - public string IconLink { get; set; } = default!; - - [JsonPropertyName("links")] - public List Links { get; set; } = default!; - - [JsonPropertyName("enable_red_dot")] - public bool EnableRedDot { get; set; } - - [JsonPropertyName("red_dot_content")] - public string RedDotContent { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/IconLink.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/IconLink.cs deleted file mode 100644 index 3541817d..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/IconLink.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher; - -internal sealed class IconLink -{ - [JsonPropertyName("title")] - public string Title { get; set; } = default!; - - [JsonPropertyName("url")] - public string Url { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Link.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Link.cs deleted file mode 100644 index f2569131..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Link.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class Link -{ - [JsonPropertyName("faq")] - public string FAQ { get; set; } = default!; - - [JsonPropertyName("version")] - public string Version { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/More.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/More.cs deleted file mode 100644 index 89c60cda..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/More.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class More -{ - [JsonPropertyName("activity_link")] - public string ActivityLink { get; set; } = default!; - - [JsonPropertyName("announce_link")] - public string AnnounceLink { get; set; } = default!; - - [JsonPropertyName("info_link")] - public string InfoLink { get; set; } = default!; - - [JsonPropertyName("news_link")] - public string NewsLink { get; set; } = default!; - - [JsonPropertyName("trends_link")] - public string TrendsLink { get; set; } = default!; - - [JsonPropertyName("supply_link")] - public string SupplyLink { get; set; } = default!; - - [JsonPropertyName("tools_link")] - public string ToolsLink { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Post.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Post.cs deleted file mode 100644 index b3de80e6..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/Post.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class Post -{ - [JsonPropertyName("post_id")] - public string PostId { get; set; } = default!; - - /// - /// POST_TYPE_ACTIVITY|POST_TYPE_ANNOUNCE|POST_TYPE_INFO - /// - [JsonPropertyName("type")] - public string Type { get; set; } = default!; - - [JsonPropertyName("url")] - public string Url { get; set; } = default!; - - /// - /// MM/dd format - /// - [JsonPropertyName("show_time")] - public string ShowTime { get; set; } = default!; - - [JsonPropertyName("order")] - public string Order { get; set; } = default!; - - [JsonPropertyName("title")] - public string Title { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/QQ.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/QQ.cs deleted file mode 100644 index 61af5e28..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Content/QQ.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; - -internal sealed class QQ -{ - [JsonPropertyName("qq_id")] - public string QQId { get; set; } = default!; - - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - [JsonPropertyName("number")] - public string Number { get; set; } = default!; - - [JsonPropertyName("code")] - public string Code { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/DiffPackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/DiffPackage.cs deleted file mode 100644 index 7e1e5624..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/DiffPackage.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 差异文件 -/// -[HighQuality] -internal sealed class DiffPackage : Package -{ - /// - /// 是否为推荐更新 - /// - [JsonPropertyName("is_recommended_update")] - public bool IsRecommendedUpdate { get; set; } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Game.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Game.cs deleted file mode 100644 index 678cf2c8..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Game.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 游戏 -/// -[HighQuality] -internal sealed class Game -{ - /// - /// 最新客户端 - /// - [JsonPropertyName("latest")] - public LatestPackage Latest { get; set; } = default!; - - /// - /// 相对于当前版本的之前版本的差异文件(非预下载) - /// - [JsonPropertyName("diffs")] - public List Diffs { get; set; } = default!; -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/GameResource.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/GameResource.cs deleted file mode 100644 index 36bcae0f..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/GameResource.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 游戏资源 -/// -[HighQuality] -internal sealed class GameResource -{ - /// - /// 本体 - /// - [JsonPropertyName("game")] - public Game Game { get; set; } = default!; - - /// - /// 插件 - /// - [JsonPropertyName("plugin")] - public Plugin Plugin { get; set; } = default!; - - /// - /// 官网地址 https://ys.mihoyo.com/launcher - /// - [JsonPropertyName("web_url")] - public Uri WebUrl { get; set; } = default!; - - /// - /// 强制更新文件 null - /// - [JsonPropertyName("force_update")] - public object? ForceUpdate { get; set; } - - /// - /// 预下载 - /// - [JsonPropertyName("pre_download_game")] - public Game? PreDownloadGame { get; set; } - - /// - /// 过期更新包 - /// - [JsonPropertyName("deprecated_packages")] - public List DeprecatedPackages { get; set; } = default!; - - /// - /// 渠道服 sdk - /// - [JsonPropertyName("sdk")] - public Sdk? Sdk { get; set; } - - /// - /// 过期的单个文件 - /// - [JsonPropertyName("deprecated_files")] - public List? DeprecatedFiles { get; set; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackage.cs deleted file mode 100644 index f07250ff..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackage.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -internal sealed class LatestPackage : Package -{ - [JsonPropertyName("segments")] - public List Segments { get; set; } = default!; - - public new string DisplayName { get => Name; } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackageExtension.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackageExtension.cs deleted file mode 100644 index e28ba674..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/LatestPackageExtension.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using System.IO; -using System.Text; - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -internal static class LatestPackageExtension -{ - public static void Patch(this LatestPackage latest) - { - StringBuilder pathBuilder = new(); - foreach (PackageSegment segment in latest.Segments) - { - pathBuilder.AppendLine(segment.Path); - } - - latest.Path = pathBuilder.ToStringTrimEndReturn(); - latest.Name = Path.GetFileName(latest.Segments[0].Path[..^4]); // .00X - } -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/NameMd5.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/NameMd5.cs deleted file mode 100644 index e31202c0..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/NameMd5.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 资源文件 -/// -[HighQuality] -internal class NameMd5 -{ - /// - /// 文件名称 - /// 相对于 EXE 的路径,如 YuanShen_Data/Plugins/PCGameSDK.dll - /// - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - /// - /// Md5 校验值 - /// - [JsonPropertyName("md5")] - public string Md5 { get; set; } = default!; -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Package.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Package.cs deleted file mode 100644 index 722f9c05..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Package.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 最新客户端 -/// -[HighQuality] -internal class Package : PathMd5 -{ - /// - /// 名称 空 - /// - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - /// - /// 版本 - /// - [JsonPropertyName("version")] - public string Version { get; set; } = default!; - - /// - /// 尺寸 - /// - [JsonPropertyName("size")] - public long Size { get; set; } = default!; - - /// - /// 主程序相对路径 YuanShen.exe - /// - public string Entry { get; set; } = default!; - - /// - /// 语音包 - /// - [JsonPropertyName("voice_packs")] - public List VoicePacks { get; set; } = default!; - - /// - /// 松散文件 - /// 用于校验完整性 - /// - [JsonPropertyName("decompressed_path")] - public string DecompressedPath { get; set; } = default!; - - /// - /// 包大小 bytes - /// - [JsonPropertyName("package_size")] - public long PackageSize { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PackageSegment.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PackageSegment.cs deleted file mode 100644 index 9b8a59fc..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PackageSegment.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -internal sealed class PackageSegment : PathMd5 -{ - [JsonPropertyName("package_size")] - [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] - public long PackageSize { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PathMd5.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PathMd5.cs deleted file mode 100644 index 1c355f28..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PathMd5.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.IO.DataTransfer; -using Snap.Hutao.Service.Notification; - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 下载的文件 -/// -[HighQuality] -internal partial class PathMd5 -{ - /// - /// 下载地址 - /// - [JsonPropertyName("path")] - public string Path { get; set; } = default!; - - /// - /// MD5校验 - /// - [JsonPropertyName("md5")] - public string Md5 { get; set; } = default!; - - /// - /// 显示名称 - /// - public string DisplayName { get => System.IO.Path.GetFileName(Path); } - - [Command("CopyPathCommand")] - private void CopyPathToClipboard() - { - IServiceProvider serviceProvider = Ioc.Default; - serviceProvider.GetRequiredService().SetText(Path); - serviceProvider.GetRequiredService().Success(SH.WebGameResourcePathCopySucceed); - } -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Plugin.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Plugin.cs deleted file mode 100644 index b55f3741..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Plugin.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 插件 -/// -[HighQuality] -internal sealed class Plugin -{ - /// - /// 插件列表 - /// - [JsonPropertyName("plugins")] - public List Plugins { get; set; } = default!; - - /// - /// 一般为 1 - /// - [JsonPropertyName("version")] - public string Version { get; set; } = default!; -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PluginItem.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PluginItem.cs deleted file mode 100644 index 2f757786..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/PluginItem.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 插件项 -/// -[HighQuality] -internal sealed class PluginItem : NameMd5 -{ - /// - /// 版本 一般为空 - /// - [JsonPropertyName("version")] - public string Version { get; set; } = default!; - - /// - /// 下载地址 - /// - [JsonPropertyName("path")] - public Uri Path { get; set; } = default!; - - /// - /// 尺寸 - /// - [JsonPropertyName("size")] - public long Size { get; set; } = default!; - - /// - /// 一般为空 - /// - [JsonPropertyName("entry")] - public string Entry { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Sdk.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Sdk.cs deleted file mode 100644 index 447dd279..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/Sdk.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// Sdk -/// -[HighQuality] -internal sealed class Sdk : PathMd5 -{ - /// - /// 版本 - /// - [JsonPropertyName("version")] - public string Version { get; set; } = default!; - - /// - /// 常量 sdk_pkg_version - /// - [JsonPropertyName("pkg_version")] - public string PackageVersion { get; set; } = default!; - - /// - /// 描述 - /// - [JsonPropertyName("desc")] - public string Description { get; set; } = default!; -} \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/VoicePackage.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/VoicePackage.cs deleted file mode 100644 index 7a71c6e8..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/Resource/VoicePackage.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; - -/// -/// 语音包 -/// -[HighQuality] -internal sealed class VoicePackage : PathMd5 -{ - /// - /// 语音 - /// - [JsonPropertyName("language")] - public string Language { get; set; } = default!; - - /// - /// 名称 一般为空 - /// - [JsonPropertyName("name")] - public string Name { get; set; } = default!; - - /// - /// 解压尺寸 - /// - [JsonPropertyName("size")] - public long Size { get; set; } - - /// - /// 包尺寸 - /// - [JsonPropertyName("package_size")] - public long PackageSize { get; set; } = default!; -} diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs b/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs deleted file mode 100644 index 1dfdc369..00000000 --- a/src/Snap.Hutao/Snap.Hutao/Web/Hoyolab/SdkStatic/Hk4e/Launcher/ResourceClient.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) DGP Studio. All rights reserved. -// Licensed under the MIT license. - -using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient; -using Snap.Hutao.Service.Game.Scheme; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Content; -using Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher.Resource; -using Snap.Hutao.Web.Request.Builder; -using Snap.Hutao.Web.Request.Builder.Abstraction; -using Snap.Hutao.Web.Response; -using System.Net.Http; - -namespace Snap.Hutao.Web.Hoyolab.SdkStatic.Hk4e.Launcher; - -/// -/// 游戏资源客户端 -/// -[HighQuality] -[ConstructorGenerated(ResolveHttpClient = true)] -[HttpClient(HttpClientConfiguration.Default)] -[Obsolete("Use HoyoPlayClient instead.")] -internal sealed partial class ResourceClient -{ - private readonly IHttpRequestMessageBuilderFactory httpRequestMessageBuilderFactory; - private readonly HttpClient httpClient; - private readonly ILogger logger; - - /// - /// 异步获取游戏资源 - /// - /// 方案 - /// 取消令牌 - /// 游戏资源 - public async ValueTask> GetResourceAsync(LaunchScheme scheme, CancellationToken token = default) - { - string url = scheme.IsOversea - ? ApiOsEndpoints.SdkOsStaticLauncherResource(scheme) - : ApiEndpoints.SdkStaticLauncherResource(scheme); - - HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() - .SetRequestUri(url) - .Get(); - - Response? resp = await builder - .SendAsync>(httpClient, logger, token) - .ConfigureAwait(false); - - // 最新版完整包 - if (resp is { Data.Game.Latest: LatestPackage latest }) - { - latest.Patch(); - } - - // 预下载完整包 - if (resp is { Data.PreDownloadGame.Latest: LatestPackage preDownloadLatest }) - { - preDownloadLatest.Patch(); - } - - return Response.Response.DefaultIfNull(resp); - } - - public async ValueTask> GetContentAsync(LaunchScheme scheme, string languageCode, bool advOnly = true, CancellationToken token = default) - { - string url = scheme.IsOversea - ? ApiOsEndpoints.SdkOsStaticLauncherContent(scheme, languageCode, advOnly) - : ApiEndpoints.SdkStaticLauncherContent(scheme, languageCode, advOnly); - - HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory.Create() - .SetRequestUri(url) - .Get(); - - Response? resp = await builder - .SendAsync>(httpClient, logger, token) - .ConfigureAwait(false); - - return Response.Response.DefaultIfNull(resp); - } -} \ No newline at end of file