diff --git a/src/Starward.Core/EnumExtension.cs b/src/Starward.Core/EnumExtension.cs index 63a8caa92..28fc14172 100644 --- a/src/Starward.Core/EnumExtension.cs +++ b/src/Starward.Core/EnumExtension.cs @@ -25,58 +25,58 @@ public static string ToDescription(this Enum @enum) } - public static GameBiz ToGame(this GameBiz biz) + public static GameBizEnum ToGame(this GameBizEnum biz) { return (int)biz switch { - 11 or 12 or 13 or 14 => GameBiz.GenshinImpact, - 21 or 22 or 24 => GameBiz.StarRail, - >= 31 and <= 37 => GameBiz.Honkai3rd, - 41 or 42 or 44 => GameBiz.ZZZ, - _ => GameBiz.None, + 11 or 12 or 13 or 14 => GameBizEnum.GenshinImpact, + 21 or 22 or 24 => GameBizEnum.StarRail, + >= 31 and <= 37 => GameBizEnum.Honkai3rd, + 41 or 42 or 44 => GameBizEnum.ZZZ, + _ => GameBizEnum.None, }; } - public static string ToGameName(this GameBiz biz) + public static string ToGameName(this GameBizEnum biz) { return biz.ToGame() switch { - GameBiz.GenshinImpact => CoreLang.Game_GenshinImpact, - GameBiz.StarRail => CoreLang.Game_HonkaiStarRail, - GameBiz.Honkai3rd => CoreLang.Game_HonkaiImpact3rd, - GameBiz.ZZZ => CoreLang.Game_ZZZ, + GameBizEnum.GenshinImpact => CoreLang.Game_GenshinImpact, + GameBizEnum.StarRail => CoreLang.Game_HonkaiStarRail, + GameBizEnum.Honkai3rd => CoreLang.Game_HonkaiImpact3rd, + GameBizEnum.ZZZ => CoreLang.Game_ZZZ, _ => "", }; } - public static string ToGameServer(this GameBiz biz) + public static string ToGameServer(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_cn => CoreLang.GameServer_ChinaOfficial, - GameBiz.hk4e_global => CoreLang.GameServer_GlobalOfficial, - GameBiz.hk4e_cloud => CoreLang.GameServer_ChinaCloud, - GameBiz.hk4e_bilibili => CoreLang.GameServer_Bilibili, - GameBiz.hkrpg_cn => CoreLang.GameServer_ChinaOfficial, - GameBiz.hkrpg_global => CoreLang.GameServer_GlobalOfficial, - GameBiz.hkrpg_bilibili => CoreLang.GameServer_Bilibili, - GameBiz.bh3_cn => CoreLang.GameServer_ChinaOfficial, - GameBiz.bh3_global => CoreLang.GameServer_EuropeAmericas, - GameBiz.bh3_jp => CoreLang.GameServer_Japan, - GameBiz.bh3_kr => CoreLang.GameServer_Korea, - GameBiz.bh3_overseas => CoreLang.GameServer_SoutheastAsia, - GameBiz.bh3_tw => CoreLang.GameServer_TraditionalChinese, - GameBiz.nap_cn => CoreLang.GameServer_ChinaOfficial, - GameBiz.nap_global => CoreLang.GameServer_GlobalOfficial, - GameBiz.nap_bilibili => CoreLang.GameServer_Bilibili, + GameBizEnum.hk4e_cn => CoreLang.GameServer_ChinaOfficial, + GameBizEnum.hk4e_global => CoreLang.GameServer_GlobalOfficial, + GameBizEnum.hk4e_cloud => CoreLang.GameServer_ChinaCloud, + GameBizEnum.hk4e_bilibili => CoreLang.GameServer_Bilibili, + GameBizEnum.hkrpg_cn => CoreLang.GameServer_ChinaOfficial, + GameBizEnum.hkrpg_global => CoreLang.GameServer_GlobalOfficial, + GameBizEnum.hkrpg_bilibili => CoreLang.GameServer_Bilibili, + GameBizEnum.bh3_cn => CoreLang.GameServer_ChinaOfficial, + GameBizEnum.bh3_global => CoreLang.GameServer_EuropeAmericas, + GameBizEnum.bh3_jp => CoreLang.GameServer_Japan, + GameBizEnum.bh3_kr => CoreLang.GameServer_Korea, + GameBizEnum.bh3_overseas => CoreLang.GameServer_SoutheastAsia, + GameBizEnum.bh3_tw => CoreLang.GameServer_TraditionalChinese, + GameBizEnum.nap_cn => CoreLang.GameServer_ChinaOfficial, + GameBizEnum.nap_global => CoreLang.GameServer_GlobalOfficial, + GameBizEnum.nap_bilibili => CoreLang.GameServer_Bilibili, _ => "", }; } - public static bool IsChinaServer(this GameBiz biz) + public static bool IsChinaServer(this GameBizEnum biz) { return (int)biz switch { @@ -86,7 +86,7 @@ public static bool IsChinaServer(this GameBiz biz) } - public static bool IsGlobalServer(this GameBiz biz) + public static bool IsGlobalServer(this GameBizEnum biz) { return (int)biz switch { @@ -96,7 +96,7 @@ 12 or 22 or (>= 32 and <= 36) or 42 => true, } - public static bool IsBilibiliServer(this GameBiz biz) + public static bool IsBilibiliServer(this GameBizEnum biz) { return (int)biz switch { @@ -107,42 +107,42 @@ public static bool IsBilibiliServer(this GameBiz biz) - public static bool IsChinaOfficial(this GameBiz biz) + public static bool IsChinaOfficial(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => true, + GameBizEnum.hk4e_cn or GameBizEnum.hkrpg_cn or GameBizEnum.bh3_cn or GameBizEnum.nap_cn => true, _ => false, }; } - public static bool IsGlobalOfficial(this GameBiz biz) + public static bool IsGlobalOfficial(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.bh3_global or GameBiz.nap_global => true, - GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_overseas or GameBiz.bh3_tw => true, + GameBizEnum.hk4e_global or GameBizEnum.hkrpg_global or GameBizEnum.bh3_global or GameBizEnum.nap_global => true, + GameBizEnum.bh3_jp or GameBizEnum.bh3_kr or GameBizEnum.bh3_overseas or GameBizEnum.bh3_tw => true, _ => false, }; } - public static bool IsBilibili(this GameBiz biz) + public static bool IsBilibili(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_bilibili or GameBiz.hkrpg_bilibili or GameBiz.nap_bilibili => true, + GameBizEnum.hk4e_bilibili or GameBizEnum.hkrpg_bilibili or GameBizEnum.nap_bilibili => true, _ => false, }; } - public static bool IsChinaCloud(this GameBiz biz) + public static bool IsChinaCloud(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_cloud => true, + GameBizEnum.hk4e_cloud => true, _ => false, }; } @@ -150,46 +150,46 @@ public static bool IsChinaCloud(this GameBiz biz) - public static string GetLauncherRegistryKey(this GameBiz biz) + public static string GetLauncherRegistryKey(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => GameRegistry.LauncherPath_hk4e_cn, - GameBiz.hk4e_global => GameRegistry.LauncherPath_hk4e_global, - GameBiz.hk4e_cloud => GameRegistry.LauncherPath_hk4e_cloud, - GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => GameRegistry.LauncherPath_hkrpg_cn, - GameBiz.hkrpg_global => GameRegistry.LauncherPath_hkrpg_global, - GameBiz.bh3_cn => GameRegistry.LauncherPath_bh3_cn, - GameBiz.bh3_global => GameRegistry.LauncherPath_bh3_global, - GameBiz.bh3_jp => GameRegistry.LauncherPath_bh3_jp, - GameBiz.bh3_kr => GameRegistry.LauncherPath_bh3_kr, - GameBiz.bh3_overseas => GameRegistry.LauncherPath_bh3_overseas, - GameBiz.bh3_tw => GameRegistry.LauncherPath_bh3_tw, - GameBiz.nap_cn or GameBiz.nap_bilibili => GameRegistry.LauncherPath_HYP_cn, - GameBiz.nap_global => GameRegistry.LauncherPath_HYP_os, + GameBizEnum.hk4e_cn or GameBizEnum.hk4e_bilibili => GameRegistry.LauncherPath_hk4e_cn, + GameBizEnum.hk4e_global => GameRegistry.LauncherPath_hk4e_global, + GameBizEnum.hk4e_cloud => GameRegistry.LauncherPath_hk4e_cloud, + GameBizEnum.hkrpg_cn or GameBizEnum.hkrpg_bilibili => GameRegistry.LauncherPath_hkrpg_cn, + GameBizEnum.hkrpg_global => GameRegistry.LauncherPath_hkrpg_global, + GameBizEnum.bh3_cn => GameRegistry.LauncherPath_bh3_cn, + GameBizEnum.bh3_global => GameRegistry.LauncherPath_bh3_global, + GameBizEnum.bh3_jp => GameRegistry.LauncherPath_bh3_jp, + GameBizEnum.bh3_kr => GameRegistry.LauncherPath_bh3_kr, + GameBizEnum.bh3_overseas => GameRegistry.LauncherPath_bh3_overseas, + GameBizEnum.bh3_tw => GameRegistry.LauncherPath_bh3_tw, + GameBizEnum.nap_cn or GameBizEnum.nap_bilibili => GameRegistry.LauncherPath_HYP_cn, + GameBizEnum.nap_global => GameRegistry.LauncherPath_HYP_os, _ => "HKEY_LOCAL_MACHINE", }; } - public static string GetGameRegistryKey(this GameBiz biz) + public static string GetGameRegistryKey(this GameBizEnum biz) { return biz switch { - GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => GameRegistry.GamePath_hk4e_cn, - GameBiz.hk4e_global => GameRegistry.GamePath_hk4e_global, - GameBiz.hk4e_cloud => GameRegistry.GamePath_hk4e_cloud, - GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => GameRegistry.GamePath_hkrpg_cn, - GameBiz.hkrpg_global => GameRegistry.GamePath_hkrpg_global, - GameBiz.bh3_cn => GameRegistry.GamePath_bh3_cn, - GameBiz.bh3_global => GameRegistry.GamePath_bh3_global, - GameBiz.bh3_jp => GameRegistry.GamePath_bh3_jp, - GameBiz.bh3_kr => GameRegistry.GamePath_bh3_kr, - GameBiz.bh3_overseas => GameRegistry.GamePath_bh3_overseas, - GameBiz.bh3_tw => GameRegistry.GamePath_bh3_tw, - GameBiz.nap_cn or GameBiz.nap_bilibili => GameRegistry.GamePath_nap_cn, - GameBiz.nap_global => GameRegistry.GamePath_nap_global, + GameBizEnum.hk4e_cn or GameBizEnum.hk4e_bilibili => GameRegistry.GamePath_hk4e_cn, + GameBizEnum.hk4e_global => GameRegistry.GamePath_hk4e_global, + GameBizEnum.hk4e_cloud => GameRegistry.GamePath_hk4e_cloud, + GameBizEnum.hkrpg_cn or GameBizEnum.hkrpg_bilibili => GameRegistry.GamePath_hkrpg_cn, + GameBizEnum.hkrpg_global => GameRegistry.GamePath_hkrpg_global, + GameBizEnum.bh3_cn => GameRegistry.GamePath_bh3_cn, + GameBizEnum.bh3_global => GameRegistry.GamePath_bh3_global, + GameBizEnum.bh3_jp => GameRegistry.GamePath_bh3_jp, + GameBizEnum.bh3_kr => GameRegistry.GamePath_bh3_kr, + GameBizEnum.bh3_overseas => GameRegistry.GamePath_bh3_overseas, + GameBizEnum.bh3_tw => GameRegistry.GamePath_bh3_tw, + GameBizEnum.nap_cn or GameBizEnum.nap_bilibili => GameRegistry.GamePath_nap_cn, + GameBizEnum.nap_global => GameRegistry.GamePath_nap_global, _ => "HKEY_CURRENT_USER", }; } diff --git a/src/Starward.Core/Gacha/GachaLogClient.cs b/src/Starward.Core/Gacha/GachaLogClient.cs index 9b24c17ab..09dcacd53 100644 --- a/src/Starward.Core/Gacha/GachaLogClient.cs +++ b/src/Starward.Core/Gacha/GachaLogClient.cs @@ -116,17 +116,17 @@ public async Task GetUidByGachaUrlAsync(string gachaUrl) [SupportedOSPlatform("windows")] public static string? GetGameInstallPathFromRegistry(GameBiz biz) { - if (biz is GameBiz.hk4e_cloud) + if (biz == GameBiz.clgm_cn) { return Registry.GetValue(REG_KEY_YS_CLOUD, "InstallPath", null) as string; } - else if (biz is GameBiz.nap_cn) + else if (biz == GameBiz.nap_cn) { return Registry.GetValue(@"HKEY_CURRENT_USER\Software\miHoYo\HYP\standalone\1_1\nap_cn\nap_cn", "GameInstallPath", null) as string; } else { - var key = biz switch + var key = biz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => REG_KEY_YS_CN, GameBiz.hk4e_global => REG_KEY_YS_OS, @@ -134,8 +134,8 @@ public async Task GetUidByGachaUrlAsync(string gachaUrl) GameBiz.hkrpg_global => REG_KEY_SR_OS, GameBiz.bh3_cn => REG_KEY_BH3_CN, GameBiz.bh3_global => REG_KEY_BH3_GL, - GameBiz.bh3_overseas => REG_KEY_BH3_OS, - GameBiz.bh3_tw => REG_KEY_BH3_TW, + GameBiz.bh3_os => REG_KEY_BH3_OS, + GameBiz.bh3_asia => REG_KEY_BH3_TW, GameBiz.bh3_kr => REG_KEY_BH3_KR, GameBiz.bh3_jp => REG_KEY_BH3_JP, _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), @@ -159,11 +159,11 @@ public async Task GetUidByGachaUrlAsync(string gachaUrl) public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath) { - if (gameBiz is GameBiz.hk4e_cloud) + if (gameBiz == GameBiz.clgm_cn) { return Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"GenshinImpactCloudGame\config\logs\MiHoYoSDK.log"); } - string file = gameBiz switch + string file = gameBiz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => Path.Join(installPath, WEB_CACHE_PATH_YS_CN), GameBiz.hk4e_global => Path.Join(installPath, WEB_CACHE_PATH_YS_OS), @@ -176,7 +176,7 @@ public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath) { lastWriteTime = File.GetLastWriteTime(file); } - string prefix = gameBiz switch + string prefix = gameBiz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => @"YuanShen_Data\webCaches", GameBiz.hk4e_global => @"GenshinImpact_Data\webCaches", @@ -203,9 +203,9 @@ public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath) private static ReadOnlySpan GetGachaUrlPattern(GameBiz gameBiz) { - return gameBiz switch + return gameBiz.Value switch { - GameBiz.hk4e_cn or GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => SPAN_WEB_PREFIX_YS_CN, + GameBiz.hk4e_cn or GameBiz.clgm_cn or GameBiz.hk4e_bilibili => SPAN_WEB_PREFIX_YS_CN, GameBiz.hk4e_global => SPAN_WEB_PREFIX_YS_OS, GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => SPAN_WEB_PREFIX_SR_CN, GameBiz.hkrpg_global => SPAN_WEB_PREFIX_SR_OS, @@ -362,7 +362,7 @@ public async Task GetGenshinGachaInfoAsync(GameBiz gameBiz, st { lang = LanguageUtil.FilterLanguage(lang); GenshinGachaWiki wiki; - if (gameBiz.IsChinaServer() && lang is "zh-cn") + if (gameBiz.IsChinaOfficial() && lang is "zh-cn") { const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e"; wiki = await CommonGetAsync(url, cancellationToken); @@ -381,7 +381,7 @@ public async Task GetStarRailGachaInfoAsync(GameBiz gameBiz, { lang = LanguageUtil.FilterLanguage(lang); StarRailGachaWiki wiki; - if (gameBiz.IsChinaServer() && lang is "zh-cn") + if (gameBiz.IsChinaOfficial() && lang is "zh-cn") { const string url = "https://api-takumi.mihoyo.com/event/rpgsimulator/config?game=hkrpg"; wiki = await CommonGetAsync(url, cancellationToken); @@ -417,11 +417,12 @@ public async Task GetStarRailGachaInfoAsync(GameBiz gameBiz, // todo + [Obsolete("Not finished", true)] public async Task GetZZZGachaInfoAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default) { lang = LanguageUtil.FilterLanguage(lang); GenshinGachaWiki wiki; - if (gameBiz.IsChinaServer() && lang is "zh-cn") + if (gameBiz.IsChinaOfficial() && lang is "zh-cn") { const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e"; wiki = await CommonGetAsync(url, cancellationToken); diff --git a/src/Starward.Core/GameBiz.cs b/src/Starward.Core/GameBiz.cs index 112455790..fdf616617 100644 --- a/src/Starward.Core/GameBiz.cs +++ b/src/Starward.Core/GameBiz.cs @@ -1,119 +1,210 @@ -namespace Starward.Core; +using System.Collections.ObjectModel; -public enum GameBiz +namespace Starward.Core; + +public record GameBiz { - None = 0, - All = 1, + public string Value { get; init; } + + public GameBiz(string? value) + { + Value = value ?? ""; + } - /// - /// Genshin Impact - /// - GenshinImpact = 10, - /// - /// Genshin Impact China - /// - hk4e_cn = 11, + public const string bh3 = "bh3"; + public const string bh3_cn = "bh3_cn"; + public const string bh3_global = "bh3_global"; - /// - /// Genshin Impact Global - /// - hk4e_global = 12, + public const string bh3_os = "bh3_os"; // 东南亚 + public const string bh3_jp = "bh3_jp"; + public const string bh3_kr = "bh3_kr"; + public const string bh3_usa = "bh3_usa"; + public const string bh3_asia = "bh3_asia"; // 繁中 + public const string bh3_eur = "bh3_eur"; - /// - /// Genshin Impact Cloud - /// - hk4e_cloud = 13, - /// - /// Genshin Impact Bilibili - /// - hk4e_bilibili = 14, + public const string hk4e = "hk4e"; + public const string hk4e_cn = "hk4e_cn"; + public const string hk4e_global = "hk4e_global"; + public const string hk4e_bilibili = "hk4e_bilibili"; + public const string clgm_cn = "clgm_cn"; + public const string clgm_global = "clgm_global"; - /// - /// Star Rail - /// - StarRail = 20, - /// - /// Star Rail China - /// - hkrpg_cn = 21, + public const string hkrpg = "hkrpg"; + public const string hkrpg_cn = "hkrpg_cn"; + public const string hkrpg_global = "hkrpg_global"; + public const string hkrpg_bilibili = "hkrpg_bilibili"; - /// - /// Star Rail Global - /// - hkrpg_global = 22, - /// - /// Star Rail Cloud - /// - //hkrpg_cloud = 23, + public const string nap = "nap"; + public const string nap_cn = "nap_cn"; + public const string nap_global = "nap_global"; + public const string nap_bilibili = "nap_bilibili"; - /// - /// Star Rail Bilibili - /// - hkrpg_bilibili = 24, + public const string None = ""; - /// - /// Honkai Impact 3rd - /// - Honkai3rd = 30, - /// - /// Honkai Impact 3rd China - /// - bh3_cn = 31, - /// - /// Honkai Impact 3rd Global - /// - bh3_global = 32, + public static ReadOnlyCollection AllGameBizs { get; private set; } = new List + { + bh3_cn, + //bh3_global, + bh3_os, + bh3_jp, + bh3_kr, + bh3_usa, + bh3_asia, + bh3_eur, + hk4e_cn, + hk4e_global, + hk4e_bilibili, + clgm_cn, + //clgm_global, + hkrpg_cn, + hkrpg_global, + hkrpg_bilibili, + nap_cn, + nap_global, + nap_bilibili, + }.AsReadOnly(); - /// - /// Honkai Impact 3rd Japan - /// - bh3_jp = 33, - /// - /// Honkai Impact 3rd Korea - /// - bh3_kr = 34, - /// - /// Honkai Impact 3rd Southeast Asia - /// - bh3_overseas = 35, - /// - /// Honkai Impact 3rd Traditional Chinese - /// - bh3_tw = 36, + public static bool TryParse(string? value, out GameBiz gameBiz) + { + gameBiz = new(value); + return gameBiz.IsKnown(); + } - /// - /// Zenless Zone Zero - /// - ZZZ = 40, - /// - /// Zenless Zone Zero China - /// - nap_cn = 41, - - /// - /// Zenless Zone Zero Global - /// - nap_global = 42, - - /// - /// Zenless Zone Zero Bilibili - /// - nap_bilibili = 44, + public override string ToString() => Value; + public static implicit operator GameBiz(string? value) => new(value); + public static implicit operator string(GameBiz value) => value.Value; } + + + +public static class GameBizExtension +{ + + + public static bool IsKnown(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.bh3_cn or GameBiz.bh3_global => true, + GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_bilibili => true, + GameBiz.clgm_cn or GameBiz.clgm_global => true, + GameBiz.hkrpg_cn or GameBiz.hkrpg_global or GameBiz.hkrpg_bilibili => true, + GameBiz.nap_cn or GameBiz.nap_global or GameBiz.nap_bilibili => true, + _ => false, + }; + + + public static bool IsChinaOfficial(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.bh3_cn => true, + GameBiz.hk4e_cn => true, + GameBiz.hkrpg_cn => true, + GameBiz.nap_cn => true, + _ => false, + }; + + + public static bool IsGlobalOfficial(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.bh3_global => true, + GameBiz.hk4e_global => true, + GameBiz.hkrpg_global => true, + GameBiz.nap_global => true, + _ => false, + }; + + + public static bool IsBilibili(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.hk4e_bilibili => true, + GameBiz.hkrpg_bilibili => true, + GameBiz.nap_bilibili => true, + _ => false, + }; + + + public static bool IsChinaCloud(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.clgm_cn => true, + _ => false, + }; + + + + public static GameBiz ToGame(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.bh3_cn or GameBiz.bh3_global => GameBiz.bh3, + GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_bilibili or GameBiz.clgm_cn or GameBiz.clgm_global => GameBiz.hk4e, + GameBiz.hkrpg_cn or GameBiz.hkrpg_global or GameBiz.hkrpg_bilibili => GameBiz.hkrpg, + GameBiz.nap_cn or GameBiz.nap_global or GameBiz.nap_bilibili => GameBiz.nap, + _ => GameBiz.None, + }; + + + public static string ToGameName(this GameBiz? gameBiz) => gameBiz?.ToGame().Value switch + { + GameBiz.bh3 => CoreLang.Game_HonkaiImpact3rd, + GameBiz.hk4e => CoreLang.Game_GenshinImpact, + GameBiz.hkrpg => CoreLang.Game_HonkaiStarRail, + GameBiz.nap => CoreLang.Game_ZZZ, + _ => "", + }; + + + public static string ToGameServerName(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.hk4e_cn => CoreLang.GameServer_ChinaOfficial, + GameBiz.hk4e_global => CoreLang.GameServer_GlobalOfficial, + GameBiz.clgm_cn => CoreLang.GameServer_ChinaCloud, + GameBiz.hk4e_bilibili => CoreLang.GameServer_Bilibili, + GameBiz.hkrpg_cn => CoreLang.GameServer_ChinaOfficial, + GameBiz.hkrpg_global => CoreLang.GameServer_GlobalOfficial, + GameBiz.hkrpg_bilibili => CoreLang.GameServer_Bilibili, + GameBiz.bh3_cn => CoreLang.GameServer_ChinaOfficial, + GameBiz.bh3_global => CoreLang.GameServer_EuropeAmericas, + GameBiz.bh3_jp => CoreLang.GameServer_Japan, + GameBiz.bh3_kr => CoreLang.GameServer_Korea, + GameBiz.bh3_os => CoreLang.GameServer_SoutheastAsia, + GameBiz.bh3_asia => CoreLang.GameServer_TraditionalChinese, + GameBiz.nap_cn => CoreLang.GameServer_ChinaOfficial, + GameBiz.nap_global => CoreLang.GameServer_GlobalOfficial, + GameBiz.nap_bilibili => CoreLang.GameServer_Bilibili, + _ => "", + }; + + + public static string GetGameRegistryKey(this GameBiz? gameBiz) => gameBiz?.Value switch + { + GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => GameRegistry.GamePath_hk4e_cn, + GameBiz.hk4e_global => GameRegistry.GamePath_hk4e_global, + GameBiz.clgm_cn => GameRegistry.GamePath_hk4e_cloud, + GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => GameRegistry.GamePath_hkrpg_cn, + GameBiz.hkrpg_global => GameRegistry.GamePath_hkrpg_global, + GameBiz.bh3_cn => GameRegistry.GamePath_bh3_cn, + GameBiz.bh3_global => GameRegistry.GamePath_bh3_global, + GameBiz.bh3_jp => GameRegistry.GamePath_bh3_jp, + GameBiz.bh3_kr => GameRegistry.GamePath_bh3_kr, + GameBiz.bh3_os => GameRegistry.GamePath_bh3_overseas, + GameBiz.bh3_asia => GameRegistry.GamePath_bh3_tw, + GameBiz.nap_cn or GameBiz.nap_bilibili => GameRegistry.GamePath_nap_cn, + GameBiz.nap_global => GameRegistry.GamePath_nap_global, + _ => "HKEY_CURRENT_USER", + }; + + +} \ No newline at end of file diff --git a/src/Starward.Core/GameBizEnum.cs b/src/Starward.Core/GameBizEnum.cs new file mode 100644 index 000000000..490bce34c --- /dev/null +++ b/src/Starward.Core/GameBizEnum.cs @@ -0,0 +1,120 @@ +namespace Starward.Core; + +[Obsolete("GameBizEnum")] +public enum GameBizEnum +{ + + None = 0, + + All = 1, + + + /// + /// Genshin Impact + /// + GenshinImpact = 10, + + /// + /// Genshin Impact China + /// + hk4e_cn = 11, + + /// + /// Genshin Impact Global + /// + hk4e_global = 12, + + /// + /// Genshin Impact Cloud + /// + hk4e_cloud = 13, + + /// + /// Genshin Impact Bilibili + /// + hk4e_bilibili = 14, + + + /// + /// Star Rail + /// + StarRail = 20, + + /// + /// Star Rail China + /// + hkrpg_cn = 21, + + /// + /// Star Rail Global + /// + hkrpg_global = 22, + + /// + /// Star Rail Cloud + /// + //hkrpg_cloud = 23, + + /// + /// Star Rail Bilibili + /// + hkrpg_bilibili = 24, + + + /// + /// Honkai Impact 3rd + /// + Honkai3rd = 30, + + /// + /// Honkai Impact 3rd China + /// + bh3_cn = 31, + + /// + /// Honkai Impact 3rd Global + /// + bh3_global = 32, + + /// + /// Honkai Impact 3rd Japan + /// + bh3_jp = 33, + + /// + /// Honkai Impact 3rd Korea + /// + bh3_kr = 34, + + /// + /// Honkai Impact 3rd Southeast Asia + /// + bh3_overseas = 35, + + /// + /// Honkai Impact 3rd Traditional Chinese + /// + bh3_tw = 36, + + + /// + /// Zenless Zone Zero + /// + ZZZ = 40, + + /// + /// Zenless Zone Zero China + /// + nap_cn = 41, + + /// + /// Zenless Zone Zero Global + /// + nap_global = 42, + + /// + /// Zenless Zone Zero Bilibili + /// + nap_bilibili = 44, + +} diff --git a/src/Starward.Core/HoYoPlay/GameId.cs b/src/Starward.Core/HoYoPlay/GameId.cs index 01d040a0b..469b9fff4 100644 --- a/src/Starward.Core/HoYoPlay/GameId.cs +++ b/src/Starward.Core/HoYoPlay/GameId.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using Starward.Core.JsonConverter; +using System.Text.Json.Serialization; namespace Starward.Core.HoYoPlay; @@ -13,37 +14,25 @@ public class GameId : IEquatable [JsonPropertyName("biz")] - public string Biz { get; set; } - - - public GameBiz ToGameBiz() - { - if (Enum.TryParse(Biz, out var biz) && biz.ToGame() is not GameBiz.None) - { - return biz; - } - else - { - return GameBiz.None; - } - } + [JsonConverter(typeof(GameBizJsonConverter))] + public GameBiz GameBiz { get; set; } public static GameId? FromGameBiz(GameBiz gameBiz) { - return gameBiz switch + return gameBiz.Value switch { - GameBiz.bh3_cn => new GameId { Id = "osvnlOc0S8", Biz = "bh3_cn" }, - GameBiz.bh3_global => new GameId { Id = "5TIVvvcwtM", Biz = "bh3_global" }, - GameBiz.hk4e_cn => new GameId { Id = "1Z8W5NHUQb", Biz = "hk4e_cn" }, - GameBiz.hk4e_global => new GameId { Id = "gopR6Cufr3", Biz = "hk4e_global" }, - GameBiz.hk4e_bilibili => new GameId { Id = "T2S0Gz4Dr2", Biz = "hk4e_cn" }, - GameBiz.hkrpg_cn => new GameId { Id = "64kMb5iAWu", Biz = "hkrpg_cn" }, - GameBiz.hkrpg_global => new GameId { Id = "4ziysqXOQ8", Biz = "hkrpg_global" }, - GameBiz.hkrpg_bilibili => new GameId { Id = "EdtUqXfCHh", Biz = "hkrpg_cn" }, - GameBiz.nap_cn => new GameId { Id = "x6znKlJ0xK", Biz = "nap_cn" }, - GameBiz.nap_global => new GameId { Id = "U5hbdsT9W7", Biz = "nap_global" }, - GameBiz.nap_bilibili => new GameId { Id = "HXAFlmYa17", Biz = "nap_bilibili" }, + GameBiz.bh3_cn => new GameId { Id = "osvnlOc0S8", GameBiz = "bh3_cn" }, + GameBiz.bh3_global => new GameId { Id = "5TIVvvcwtM", GameBiz = "bh3_global" }, + GameBiz.hk4e_cn => new GameId { Id = "1Z8W5NHUQb", GameBiz = "hk4e_cn" }, + GameBiz.hk4e_global => new GameId { Id = "gopR6Cufr3", GameBiz = "hk4e_global" }, + GameBiz.hk4e_bilibili => new GameId { Id = "T2S0Gz4Dr2", GameBiz = "hk4e_cn" }, + GameBiz.hkrpg_cn => new GameId { Id = "64kMb5iAWu", GameBiz = "hkrpg_cn" }, + GameBiz.hkrpg_global => new GameId { Id = "4ziysqXOQ8", GameBiz = "hkrpg_global" }, + GameBiz.hkrpg_bilibili => new GameId { Id = "EdtUqXfCHh", GameBiz = "hkrpg_cn" }, + GameBiz.nap_cn => new GameId { Id = "x6znKlJ0xK", GameBiz = "nap_cn" }, + GameBiz.nap_global => new GameId { Id = "U5hbdsT9W7", GameBiz = "nap_global" }, + GameBiz.nap_bilibili => new GameId { Id = "HXAFlmYa17", GameBiz = "nap_bilibili" }, _ => null, }; } diff --git a/src/Starward.Core/HoYoPlay/HoYoPlayClient.cs b/src/Starward.Core/HoYoPlay/HoYoPlayClient.cs index cc8e7375b..5574247f1 100644 --- a/src/Starward.Core/HoYoPlay/HoYoPlayClient.cs +++ b/src/Starward.Core/HoYoPlay/HoYoPlayClient.cs @@ -465,17 +465,17 @@ public async Task> GetGameBranchAsync(string launcherId, string public async Task GetGameChunkBuildAsync(GameBranch gameBranch, GameBranchPackage gameBranchPackage, CancellationToken cancellationToken = default) { string? url = null; - if (gameBranch.GameId.ToGameBiz().IsChinaServer()) + if (gameBranch.GameId.GameBiz.IsChinaOfficial()) { url = "https://api-takumi.mihoyo.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf5qt290cg"; } - if (gameBranch.GameId.ToGameBiz().IsGlobalServer()) + if (gameBranch.GameId.GameBiz.IsGlobalOfficial()) { url = "https://sg-public-api.hoyoverse.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf6vlr1reo"; } if (url is null) { - throw new ArgumentOutOfRangeException(nameof(gameBranch), $"Unknown game biz ({gameBranch.GameId.Biz})."); + throw new ArgumentOutOfRangeException(nameof(gameBranch), $"Unknown game biz ({gameBranch.GameId.GameBiz})."); } url += $"&branch={gameBranchPackage.Branch}&package_id={gameBranchPackage.PackageId}&password={gameBranchPackage.Password}"; return await CommonGetAsync(url, cancellationToken); @@ -496,17 +496,17 @@ public async Task GetGameChunkBuildAsync(GameBranch gameBranch, public async Task GetGameChunkBuildAsync(GameBranch gameBranch, GameBranchPackage gameBranchPackage, string version, CancellationToken cancellationToken = default) { string? url = null; - if (gameBranch.GameId.ToGameBiz().IsChinaServer()) + if (gameBranch.GameId.GameBiz.IsChinaOfficial()) { url = "https://api-takumi.mihoyo.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf5qt290cg"; } - if (gameBranch.GameId.ToGameBiz().IsGlobalServer()) + if (gameBranch.GameId.GameBiz.IsGlobalOfficial()) { url = "https://sg-public-api.hoyoverse.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf6vlr1reo"; } if (url is null) { - throw new ArgumentOutOfRangeException(nameof(gameBranch), $"Unknown game biz ({gameBranch.GameId.Biz})."); + throw new ArgumentOutOfRangeException(nameof(gameBranch), $"Unknown game biz ({gameBranch.GameId.GameBiz})."); } url += $"&branch={gameBranchPackage.Branch}&package_id={gameBranchPackage.PackageId}&password={gameBranchPackage.Password}&tag={version}"; return await CommonGetAsync(url, cancellationToken); diff --git a/src/Starward.Core/HoYoPlay/LauncherId.cs b/src/Starward.Core/HoYoPlay/LauncherId.cs index d924aa96a..c8c4b377f 100644 --- a/src/Starward.Core/HoYoPlay/LauncherId.cs +++ b/src/Starward.Core/HoYoPlay/LauncherId.cs @@ -38,7 +38,7 @@ public static bool IsBilibili(string launcherId) public static string? FromGameBiz(GameBiz biz) { - return biz switch + return biz.Value switch { GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => ChinaOfficial, GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.bh3_global or GameBiz.nap_global => GlobalOfficial, diff --git a/src/Starward.Core/JsonConverter/GameBizJsonConverter.cs b/src/Starward.Core/JsonConverter/GameBizJsonConverter.cs new file mode 100644 index 000000000..68aa48082 --- /dev/null +++ b/src/Starward.Core/JsonConverter/GameBizJsonConverter.cs @@ -0,0 +1,17 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Starward.Core.JsonConverter; + +public class GameBizJsonConverter : JsonConverter +{ + public override GameBiz? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + return new GameBiz(reader.GetString()); + } + + public override void Write(Utf8JsonWriter writer, GameBiz value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.Value); + } +} diff --git a/src/Starward.Core/Launcher/LauncherClient.cs b/src/Starward.Core/Launcher/LauncherClient.cs index 5b49078fe..ad4782dd8 100644 --- a/src/Starward.Core/Launcher/LauncherClient.cs +++ b/src/Starward.Core/Launcher/LauncherClient.cs @@ -44,23 +44,23 @@ private async Task CommonSendAsync(HttpRequestMessage request, Cancellatio public async Task GetLauncherContentAsync(GameBiz biz, string? lang = null, CancellationToken cancellationToken = default) { lang = LanguageUtil.FilterLanguage(lang); - var url = biz switch + var url = biz.Value switch { - GameBiz.hk4e_cn or GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => "https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/content?filter_adv=false&key=eYd89JmJ&language=zh-cn&launcher_id=18", + GameBiz.hk4e_cn or GameBiz.clgm_cn or GameBiz.hk4e_bilibili => "https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/content?filter_adv=false&key=eYd89JmJ&language=zh-cn&launcher_id=18", GameBiz.hk4e_global => $"https://sdk-os-static.mihoyo.com/hk4e_global/mdk/launcher/api/content?filter_adv=false&key=gcStgarh&language={lang}&launcher_id=10", GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => "https://api-launcher-static.mihoyo.com/hkrpg_cn/mdk/launcher/api/content?filter_adv=false&key=6KcVuOkbcqjJomjZ&language=zh-cn&launcher_id=33", GameBiz.hkrpg_global => $"https://hkrpg-launcher-static.hoyoverse.com/hkrpg_global/mdk/launcher/api/content?filter_adv=false&key=vplOVX8Vn7cwG8yb&language={lang}&launcher_id=35", GameBiz.bh3_cn => $"https://bh3-launcher-static.mihoyo.com/bh3_cn/mdk/launcher/api/content?key=SyvuPnqL&filter_adv=false&language=zh-cn&launcher_id=4", - GameBiz.bh3_overseas => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=tEGNtVhN&language={lang}&launcher_id=9", + GameBiz.bh3_os => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=tEGNtVhN&language={lang}&launcher_id=9", GameBiz.bh3_global => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=dpz65xJ3&language={lang}&launcher_id=10", - GameBiz.bh3_tw => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=demhUTcW&language=zh-tw&launcher_id=8", + GameBiz.bh3_asia => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=demhUTcW&language=zh-tw&launcher_id=8", GameBiz.bh3_kr => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=PRg571Xh&language=ko-kr&launcher_id=11", GameBiz.bh3_jp => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/content?filter_adv=false&key=ojevZ0EyIyZNCy4n&language=ja-jp&launcher_id=19", GameBiz.nap_cn => "https://nap-launcher-static.mihoyo.com/nap_cn/mdk/launcher/api/content?filter_adv=false&key=9HEb62Pw0qKYX4Mw&language=zh-cn&launcher_id=15", //GameBiz.nap_global => "", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; - if (biz is GameBiz.nap_cn) + if (biz == GameBiz.nap_cn) { return await GetZZZCBT3LauncherContentAsync(cancellationToken); } @@ -123,9 +123,9 @@ public async Task GetZZZCBT3LauncherContentAsync(CancellationTo public async Task GetCloudGameBackgroundAsync(GameBiz biz, CancellationToken cancellationToken = default) { - var url = biz switch + var url = biz.Value switch { - GameBiz.hk4e_cloud => "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getUIConfig", + GameBiz.clgm_cn => "https://api-cloudgame.mihoyo.com/hk4e_cg_cn/gamer/api/getUIConfig", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; var request = new HttpRequestMessage(HttpMethod.Get, url); @@ -136,7 +136,7 @@ public async Task GetCloudGameBackgroundAsync(GameBiz biz, public async Task GetZZZCBT3BackgroundAsync(GameBiz biz, CancellationToken cancellationToken = default) { - var url = biz switch + var url = biz.Value switch { GameBiz.nap_cn => "https://hyp-api.mihoyo.com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=PFKmM45gSW&language=zh-cn&game_id=ol93169Cmh", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), @@ -151,7 +151,7 @@ public async Task GetZZZCBT3BackgroundAsync(GameBiz biz, CancellationTok public async Task GetLauncherGameResourceAsync(GameBiz biz, CancellationToken cancellationToken = default) { - var url = biz switch + var url = biz.Value switch { GameBiz.hk4e_cn => "https://sdk-static.mihoyo.com/hk4e_cn/mdk/launcher/api/resource?channel_id=1&key=eYd89JmJ&launcher_id=18&sub_channel_id=1", GameBiz.hk4e_global => $"https://sdk-os-static.mihoyo.com/hk4e_global/mdk/launcher/api/resource?channel_id=1&key=gcStgarh&launcher_id=10&sub_channel_id=0", @@ -160,9 +160,9 @@ public async Task GetLauncherGameResourceAsync(GameBiz biz GameBiz.hkrpg_global => $"https://hkrpg-launcher-static.hoyoverse.com/hkrpg_global/mdk/launcher/api/resource?channel_id=1&key=vplOVX8Vn7cwG8yb&launcher_id=35&sub_channel_id=1", GameBiz.hkrpg_bilibili => "https://api-launcher-static.mihoyo.com/hkrpg_cn/mdk/launcher/api/resource?channel_id=14&key=fSPJNRwFHRipkprW&launcher_id=28&sub_channel_id=0", GameBiz.bh3_cn => $"https://bh3-launcher-static.mihoyo.com/bh3_cn/mdk/launcher/api/resource?channel_id=1&key=SyvuPnqL&launcher_id=4&sub_channel_id=1", - GameBiz.bh3_overseas => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=tEGNtVhN&launcher_id=9&sub_channel_id=1", + GameBiz.bh3_os => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=tEGNtVhN&launcher_id=9&sub_channel_id=1", GameBiz.bh3_global => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?key=dpz65xJ3&channel_id=1&launcher_id=10&sub_channel_id=1", - GameBiz.bh3_tw => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=demhUTcW&launcher_id=8&sub_channel_id=1", + GameBiz.bh3_asia => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=demhUTcW&launcher_id=8&sub_channel_id=1", GameBiz.bh3_kr => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=PRg571Xh&launcher_id=11&sub_channel_id=1", GameBiz.bh3_jp => $"https://sdk-os-static.mihoyo.com/bh3_global/mdk/launcher/api/resource?channel_id=1&key=ojevZ0EyIyZNCy4n&launcher_id=19&sub_channel_id=6", GameBiz.nap_cn => "https://nap-launcher-static.mihoyo.com/nap_cn/mdk/launcher/api/resource?channel_id=1&key=9HEb62Pw0qKYX4Mw&launcher_id=15&sub_channel_id=1", @@ -171,7 +171,7 @@ public async Task GetLauncherGameResourceAsync(GameBiz biz }; var request = new HttpRequestMessage(HttpMethod.Get, url); var resource = await CommonSendAsync(request, cancellationToken); - if (biz is GameBiz.hkrpg_global) + if (biz == GameBiz.hkrpg_global) { if (string.IsNullOrWhiteSpace(resource.Game.Latest.DecompressedPath) && !string.IsNullOrWhiteSpace(resource.Game.Latest.Path)) { @@ -189,14 +189,14 @@ public static string GetGameNoticesUrl(GameBiz biz, long uid, string? lang = nul { lang = LanguageUtil.FilterLanguage(lang); uid = uid == 0 ? 100000000 : uid; - return biz switch + return biz.Value switch { - GameBiz.hk4e_cn or GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => $"https://webstatic.mihoyo.com/hk4e/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=hk4e_cn&channel_id=1&game=hk4e&game_biz=hk4e_cn&lang={lang}&level=60&platform=pc®ion=cn_gf01&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", + GameBiz.hk4e_cn or GameBiz.clgm_cn or GameBiz.hk4e_bilibili => $"https://webstatic.mihoyo.com/hk4e/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=hk4e_cn&channel_id=1&game=hk4e&game_biz=hk4e_cn&lang={lang}&level=60&platform=pc®ion=cn_gf01&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", GameBiz.hk4e_global => $"https://sdk.hoyoverse.com/hk4e/announcement/index.html?announcement_version=1.37&auth_appid=announcement&bundle_id=hk4e_global&channel_id=1&game=hk4e&game_biz=hk4e_global&lang={lang}&level=60&platform=pc®ion=os_asia&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&uid={uid}", GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => $"https://webstatic.mihoyo.com/hkrpg/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=hkrpg_cn&channel_id=1&game=hkrpg&game_biz=hkrpg_cn&lang={lang}&level=70&platform=pc®ion=prod_gf_cn&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", GameBiz.hkrpg_global => $"https://sdk.hoyoverse.com/hkrpg/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=hkrpg_global&channel_id=1&game=hkrpg&game_biz=hkrpg_global&lang={lang}&level=1&platform=pc®ion=prod_official_asia&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", GameBiz.bh3_cn => $"https://webstatic.mihoyo.com/bh3/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=bh3_cn&channel_id=1&game=bh3&game_biz=bh3_cn&lang=zh-cn&level=88&platform=pc®ion=android01&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", - GameBiz.bh3_global or GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_overseas or GameBiz.bh3_tw => $"https://sdk.hoyoverse.com/bh3/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=bh3_os&channel_id=1&game=bh3&game_biz=bh3_os&lang={lang}&level=88&platform=pc®ion=overseas01&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", + GameBiz.bh3_global or GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_os or GameBiz.bh3_asia => $"https://sdk.hoyoverse.com/bh3/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=bh3_os&channel_id=1&game=bh3&game_biz=bh3_os&lang={lang}&level=88&platform=pc®ion=overseas01&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}", GameBiz.nap_cn or GameBiz.nap_bilibili => $"https://sdk.mihoyo.com/nap/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=nap_cn&channel_id=1&game=nap&game_biz=nap_cn&lang=zh-cn&level=60&platform=pc®ion=prod_gf_cn&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}&version=2.27", GameBiz.nap_global => $"https://sdk.hoyoverse.com/nap/announcement/index.html?auth_appid=announcement&authkey_ver=1&bundle_id=nap_global&channel_id=1&game=nap&game_biz=nap_global&lang={lang}&level=60&platform=pc®ion=prod_gf_jp&sdk_presentation_style=fullscreen&sdk_screen_transparent=true&sign_type=2&uid={uid}&version=2.27", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), @@ -209,14 +209,14 @@ public async Task IsNoticesAlertAsync(GameBiz biz, long uid, string? lang { lang = LanguageUtil.FilterLanguage(lang); uid = uid == 0 ? 100000000 : uid; - string url = biz switch + string url = biz.Value switch { - GameBiz.hk4e_cn or GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => $"https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAlertAnn?bundle_id=hk4e_cn&channel_id=1&game=hk4e&game_biz=hk4e_cn&lang={lang}&level=60&platform=pc®ion=cn_gf01&uid={uid}", + GameBiz.hk4e_cn or GameBiz.clgm_cn or GameBiz.hk4e_bilibili => $"https://hk4e-api.mihoyo.com/common/hk4e_cn/announcement/api/getAlertAnn?bundle_id=hk4e_cn&channel_id=1&game=hk4e&game_biz=hk4e_cn&lang={lang}&level=60&platform=pc®ion=cn_gf01&uid={uid}", GameBiz.hk4e_global => $"https://sg-hk4e-api.hoyoverse.com/common/hk4e_global/announcement/api/getAlertAnn?game=hk4e&game_biz=hk4e_global&lang={lang}&bundle_id=hk4e_global&channel_id=1&level=60&platform=pc®ion=os_asia&uid={uid}", GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => $"https://hkrpg-ann-api.mihoyo.com/common/hkrpg_cn/announcement/api/getAlertAnn?bundle_id=hkrpg_cn&channel_id=1&game=hkrpg&game_biz=hkrpg_cn&lang={lang}&level=70&platform=pc®ion=prod_gf_cn&uid={uid}", GameBiz.hkrpg_global => $"https://sg-hkrpg-api.hoyoverse.com/common/hkrpg_global/announcement/api/getAlertAnn?bundle_id=hkrpg_global&channel_id=1&game=hkrpg&game_biz=hkrpg_global&lang={lang}&level=1&platform=pc®ion=prod_official_asia&uid={uid}", GameBiz.bh3_cn => $"https://ann-api.mihoyo.com/common/bh3_cn/announcement/api/getAlertAnn?game=bh3&game_biz=bh3_cn&lang={lang}&bundle_id=bh3_cn&platform=pc®ion=android01&level=88&channel_id=1&uid={uid}", - GameBiz.bh3_global or GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_overseas or GameBiz.bh3_tw => $"https://sg-public-api.hoyoverse.com/common/bh3_global/announcement/api/getAlertAnn?game=bh3&game_biz=bh3_global&lang={lang}&bundle_id=bh3_os&platform=pc®ion=overseas01&level=88&channel_id=1&uid={uid}", + GameBiz.bh3_global or GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_os or GameBiz.bh3_asia => $"https://sg-public-api.hoyoverse.com/common/bh3_global/announcement/api/getAlertAnn?game=bh3&game_biz=bh3_global&lang={lang}&bundle_id=bh3_os&platform=pc®ion=overseas01&level=88&channel_id=1&uid={uid}", GameBiz.nap_cn or GameBiz.hk4e_bilibili => $"https://announcement-api.mihoyo.com/common/nap_cn/announcement/api/getAlertAnn?bundle_id=nap_cn&channel_id=1&game=nap&game_biz=nap_cn&lang=zh-cn&level=60&platform=pc®ion=prod_gf_cn&uid={uid}", GameBiz.nap_global => $"https://sg-announcement-api.hoyoverse.com/common/nap_global/announcement/api/getAlertAnn?bundle_id=nap_global&channel_id=1&game=nap&game_biz=nap_global&lang={lang}&level=60&platform=pc®ion=prod_gf_jp&uid={uid}", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), diff --git a/src/Starward.Core/Metadata/GameInfo.cs b/src/Starward.Core/Metadata/GameInfo.cs index 7d12ff38a..02b39351c 100644 --- a/src/Starward.Core/Metadata/GameInfo.cs +++ b/src/Starward.Core/Metadata/GameInfo.cs @@ -1,4 +1,5 @@ -using System.Text.Json; +using Starward.Core.JsonConverter; +using System.Text.Json; using System.Text.Json.Serialization; namespace Starward.Core.Metadata; @@ -10,7 +11,7 @@ public class GameInfo public string Name { get; set; } - [JsonConverter(typeof(EnumStringJsonConverter))] + [JsonConverter(typeof(GameBizJsonConverter))] public GameBiz GameBiz { get; set; } diff --git a/src/Starward.Core/SelfQuery/SelfQueryClient.cs b/src/Starward.Core/SelfQuery/SelfQueryClient.cs index aace139d9..183f7ed01 100644 --- a/src/Starward.Core/SelfQuery/SelfQueryClient.cs +++ b/src/Starward.Core/SelfQuery/SelfQueryClient.cs @@ -71,7 +71,7 @@ public async Task InitializeAsync(string url, GameBiz gameBiz } this.gameBiz = gameBiz; authQuery = new Uri(url).Query; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { if (url.StartsWith("https://webstatic.mihoyo.com/csc-service-center-fe/index.html") || url.StartsWith("https://webstatic.mihoyo.com/static/mihoyo-new-csc-service-hall-fe/index.html")) { @@ -87,7 +87,7 @@ public async Task InitializeAsync(string url, GameBiz gameBiz } await GetGenshinUserInfoAsync(cancellationToken); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { if (url.StartsWith("https://webstatic.mihoyo.com/csc-service-center-fe/index.html")) { @@ -103,7 +103,7 @@ public async Task InitializeAsync(string url, GameBiz gameBiz } await GetStarRailUserInfoAsync(cancellationToken); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { if (url.StartsWith("https://webstatic.mihoyo.com/csc-service-center-fe/index.html") || url.StartsWith("https://webstatic.mihoyo.com/static/mihoyo-new-csc-service-hall-fe/index.html")) { @@ -139,7 +139,7 @@ public void Reset() public void EnsureInitialized() { - if (gameBiz is GameBiz.None + if (!gameBiz.IsKnown() || UserInfo is null || string.IsNullOrWhiteSpace(authQuery) || string.IsNullOrWhiteSpace(prefixUrl)) diff --git a/src/Starward/AppConfig.cs b/src/Starward/AppConfig.cs index 09ee0604b..3f6f28734 100644 --- a/src/Starward/AppConfig.cs +++ b/src/Starward/AppConfig.cs @@ -481,7 +481,7 @@ public static string? LastAppVersion public static GameBiz CurrentGameBiz { - get => GetValue(); + get => GetValue(); set => SetValue(value); } @@ -539,24 +539,24 @@ public static void SetBg(GameBiz biz, string? value) public static string? GetCustomBg(GameBiz biz) { - return GetValue(default, UseOneBg ? $"custom_bg_{GameBiz.All}" : $"custom_bg_{biz}"); + return GetValue(default, UseOneBg ? $"custom_bg_All" : $"custom_bg_{biz}"); } public static void SetCustomBg(GameBiz biz, string? value) { - SetValue(value, UseOneBg ? $"custom_bg_{GameBiz.All}" : $"custom_bg_{biz}"); + SetValue(value, UseOneBg ? $"custom_bg_All" : $"custom_bg_{biz}"); } public static bool GetEnableCustomBg(GameBiz biz) { - return GetValue(default, UseOneBg ? $"enable_custom_bg_{GameBiz.All}" : $"enable_custom_bg_{biz}"); + return GetValue(default, UseOneBg ? $"enable_custom_bg_All" : $"enable_custom_bg_{biz}"); } public static void SetEnableCustomBg(GameBiz biz, bool value) { - SetValue(value, UseOneBg ? $"enable_custom_bg_{GameBiz.All}" : $"enable_custom_bg_{biz}"); + SetValue(value, UseOneBg ? $"enable_custom_bg_All" : $"enable_custom_bg_{biz}"); } diff --git a/src/Starward/Controls/AccountSwitcher.xaml.cs b/src/Starward/Controls/AccountSwitcher.xaml.cs index 1406c278f..1b6a878d7 100644 --- a/src/Starward/Controls/AccountSwitcher.xaml.cs +++ b/src/Starward/Controls/AccountSwitcher.xaml.cs @@ -74,7 +74,7 @@ public void UpdateGameAccount() { try { - if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer() || CurrentGameBiz is GameBiz.nap_cn) + if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibili() || CurrentGameBiz.ToGame() == GameBiz.nap) { StackPanel_Account.Visibility = Visibility.Collapsed; return; diff --git a/src/Starward/Controls/BBSWebBridge.xaml.cs b/src/Starward/Controls/BBSWebBridge.xaml.cs index 1dc14800f..afba02683 100644 --- a/src/Starward/Controls/BBSWebBridge.xaml.cs +++ b/src/Starward/Controls/BBSWebBridge.xaml.cs @@ -111,7 +111,7 @@ private async Task InitializeWebViewAsync() { return; } - if (CurrentGameBiz.IsGlobalServer()) + if (CurrentGameBiz.IsGlobalOfficial()) { _gameRecordClient = AppConfig.GetService(); } @@ -151,7 +151,7 @@ public async Task LoadPageAsync(bool force = false) if (coreWebView2.Source is "about:blank" || force) { var manager = coreWebView2.CookieManager; - var cookies = await manager.GetCookiesAsync(CurrentGameBiz.IsGlobalServer() ? "https://act.hoyolab.com" : "https://webstatic.mihoyo.com"); + var cookies = await manager.GetCookiesAsync(CurrentGameBiz.IsGlobalOfficial() ? "https://act.hoyolab.com" : "https://webstatic.mihoyo.com"); foreach (var cookie in cookies) { manager.DeleteCookie(cookie); @@ -161,17 +161,17 @@ public async Task LoadPageAsync(bool force = false) ParseCookie(); foreach (var cookie in cookieDic) { - manager.AddOrUpdateCookie(manager.CreateCookie(cookie.Key, cookie.Value, CurrentGameBiz.IsGlobalServer() ? ".hoyolab.com" : ".mihoyo.com", "/")); + manager.AddOrUpdateCookie(manager.CreateCookie(cookie.Key, cookie.Value, CurrentGameBiz.IsGlobalOfficial() ? ".hoyolab.com" : ".mihoyo.com", "/")); } - string? url = (CurrentGameBiz.IsGlobalServer(), CurrentGameBiz.ToGame()) switch + string? url = (CurrentGameBiz.IsGlobalOfficial(), CurrentGameBiz.ToGame().Value) switch { - (true, GameBiz.GenshinImpact) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=2", - (true, GameBiz.StarRail) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=6", - (true, GameBiz.ZZZ) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=8", - (false, GameBiz.GenshinImpact) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=2", - (false, GameBiz.StarRail) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=6", - (false, GameBiz.ZZZ) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=8", + (true, GameBiz.hk4e) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=2", + (true, GameBiz.hkrpg) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=6", + (true, GameBiz.nap) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=8", + (false, GameBiz.hk4e) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=2", + (false, GameBiz.hkrpg) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=6", + (false, GameBiz.nap) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=8", _ => null, }; if (url is not null) @@ -556,7 +556,7 @@ private void CloseScreenshotGrid() private JsResult? GetDynamicSecrectV1(JsParam param) { string ApiSalt; - if (CurrentGameBiz.IsGlobalServer()) + if (CurrentGameBiz.IsGlobalOfficial()) { ApiSalt = "okr4obncj8bw5a65hbnn5oo6ixjc3l9w"; } @@ -600,7 +600,7 @@ private static string GetRandomString(int timestamp) private JsResult? GetDynamicSecrectV2(JsParam param) { string ApiSalt2; - if (CurrentGameBiz.IsGlobalServer()) + if (CurrentGameBiz.IsGlobalOfficial()) { ApiSalt2 = "h4c1d6ywfq5bsbnbhm1bzq7bxzzv6srt"; } diff --git a/src/Starward/Controls/DownloadGameDialog.xaml.cs b/src/Starward/Controls/DownloadGameDialog.xaml.cs index 3d3f803fd..8cded6edd 100644 --- a/src/Starward/Controls/DownloadGameDialog.xaml.cs +++ b/src/Starward/Controls/DownloadGameDialog.xaml.cs @@ -161,7 +161,7 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e) { ShowAllInfo = false; ShowRepairSwitcher = false; - if (GameBiz.ToGame() is GameBiz.GenshinImpact) + if (GameBiz.ToGame() == GameBiz.hk4e) { ShowVoiceBoxes = true; CanCheckVoiceBoxes = true; @@ -171,7 +171,7 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e) { ShowAllInfo = true; ShowRepairSwitcher = false; - if (GameBiz.ToGame() is GameBiz.GenshinImpact or GameBiz.StarRail) + if (GameBiz.ToGame().Value is GameBiz.hk4e or GameBiz.hkrpg) { ShowVoiceBoxes = true; } @@ -179,7 +179,7 @@ private void UserControl_Loaded(object sender, RoutedEventArgs e) else { ShowAllInfo = true; - if (GameBiz.ToGame() is GameBiz.GenshinImpact or GameBiz.StarRail) + if (GameBiz.ToGame().Value is GameBiz.hk4e or GameBiz.hkrpg) { ShowRepairSwitcher = true; ShowVoiceBoxes = true; diff --git a/src/Starward/Controls/GameBizSelector.xaml.cs b/src/Starward/Controls/GameBizSelector.xaml.cs index 2e4cdda39..3fa8070a4 100644 --- a/src/Starward/Controls/GameBizSelector.xaml.cs +++ b/src/Starward/Controls/GameBizSelector.xaml.cs @@ -63,15 +63,11 @@ public GameBizSelector() public void InitializeGameBiz(GameBiz gameBiz) { CurrentGameBiz = gameBiz; - if (CurrentGameBiz.ToGame() is GameBiz.None) - { - CurrentGameBiz = GameBiz.None; - } string? bizs = AppConfig.SelectedGameBizs; GameBizIcons.Clear(); foreach (string str in bizs?.Split(',') ?? []) { - if (Enum.TryParse(str, out GameBiz biz) && biz.ToGame() is not GameBiz.None) + if (GameBiz.TryParse(str, out GameBiz biz)) { var icon = new GameBizIcon { GameBiz = biz }; GameBizIcons.Add(icon); @@ -84,7 +80,7 @@ public void InitializeGameBiz(GameBiz gameBiz) CurrentGameBizIcon.CurrentGameBiz = true; CurrentGameBizIcon.MaskOpacity = 0; } - else if (CurrentGameBiz.ToGame() is not GameBiz.None) + else if (CurrentGameBiz.IsKnown()) { CurrentGameBizIcon = new GameBizIcon { GameBiz = CurrentGameBiz }; } @@ -126,15 +122,12 @@ public void AutoSearchGameBizs() { var service = AppConfig.GetService(); var sb = new StringBuilder(); - foreach (GameBiz biz in Enum.GetValues()) + foreach (GameBiz biz in GameBiz.AllGameBizs) { - if (biz.ToGame() is not GameBiz.None) + if (service.IsGameExeExists(biz)) { - if (service.IsGameExeExists(biz)) - { - sb.Append(biz.ToString()); - sb.Append(','); - } + sb.Append(biz.ToString()); + sb.Append(','); } } AppConfig.SelectedGameBizs = sb.ToString().TrimEnd(','); @@ -264,7 +257,7 @@ private void Border_FullMask_Tapped(object sender, Microsoft.UI.Xaml.Input.Tappe private void ToggleSwitch_GameBizSelector_Toggled(object sender, RoutedEventArgs e) { - if (sender is ToggleSwitch toggle && Enum.TryParse(toggle.Tag as string, out GameBiz biz)) + if (sender is ToggleSwitch toggle && GameBiz.TryParse(toggle.Tag as string, out GameBiz biz)) { if (GameBizIcons.FirstOrDefault(x => x.GameBiz == biz) is GameBizIcon icon) { diff --git a/src/Starward/Controls/InstallGameDialog.xaml.cs b/src/Starward/Controls/InstallGameDialog.xaml.cs index 8c6ae6e53..a874b2a6d 100644 --- a/src/Starward/Controls/InstallGameDialog.xaml.cs +++ b/src/Starward/Controls/InstallGameDialog.xaml.cs @@ -110,7 +110,7 @@ partial void OnHardLinkChanged(bool value) private string hardLinkPath; - public string HardLinkTargetText => $"{HardLinkTarget.ToGameName()} - {HardLinkTarget.ToGameServer()}"; + public string HardLinkTargetText => $"{HardLinkTarget.ToGameName()} - {HardLinkTarget.ToGameServerName()}"; @@ -161,11 +161,11 @@ private async Task InitializeHardLinkAsync() { try { - if (CurrentGameBiz.ToGame() is GameBiz.GenshinImpact or GameBiz.StarRail or GameBiz.ZZZ) + if (CurrentGameBiz.ToGame().Value is GameBiz.hk4e or GameBiz.hkrpg or GameBiz.nap) { - foreach (var biz in Enum.GetValues()) + foreach (var biz in GameBiz.AllGameBizs) { - if (biz.ToGame() == CurrentGameBiz.ToGame() && biz != CurrentGameBiz && biz != GameBiz.hk4e_cloud) + if (biz.ToGame() == CurrentGameBiz.ToGame() && biz != CurrentGameBiz && biz != GameBiz.clgm_cn) { var path = _gameLauncherService.GetGameInstallPath(biz); var version = await _gameLauncherService.GetLocalGameVersionAsync(biz, path); @@ -334,7 +334,7 @@ private void CreateDesktopShortcut() { try { - string name = $"{CurrentGameBiz.ToGameName()} - {CurrentGameBiz.ToGameServer()}.lnk"; + string name = $"{CurrentGameBiz.ToGameName()} - {CurrentGameBiz.ToGameServerName()}.lnk"; var savePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), name); string exe; if (AppConfig.IsPortable) @@ -381,12 +381,12 @@ private void CreateDesktopShortcut() { try { - var source = gameBiz.ToGame() switch + var source = gameBiz.ToGame().Value switch { - GameBiz.Honkai3rd => @"Assets\Image\icon_bh3.ico", - GameBiz.GenshinImpact => @"Assets\Image\icon_ys.ico", - GameBiz.StarRail => @"Assets\Image\icon_sr.ico", - GameBiz.ZZZ => @"Assets\Image\icon_zzz.ico", + GameBiz.bh3 => @"Assets\Image\icon_bh3.ico", + GameBiz.hk4e => @"Assets\Image\icon_ys.ico", + GameBiz.hkrpg => @"Assets\Image\icon_sr.ico", + GameBiz.nap => @"Assets\Image\icon_zzz.ico", _ => "", }; source = Path.Combine(AppContext.BaseDirectory, source); diff --git a/src/Starward/Controls/SystemTrayControl.xaml.cs b/src/Starward/Controls/SystemTrayControl.xaml.cs index dbb52c150..9fd243356 100644 --- a/src/Starward/Controls/SystemTrayControl.xaml.cs +++ b/src/Starward/Controls/SystemTrayControl.xaml.cs @@ -60,9 +60,9 @@ public void UpdateContent() try { var list = new List(); - foreach (GameBiz biz in Enum.GetValues()) + foreach (GameBiz biz in GameBiz.AllGameBizs) { - if (biz.ToGame() is not GameBiz.None) + if (biz.IsKnown()) { string? folder = _gameLauncherService.GetGameInstallPath(biz); if (string.IsNullOrWhiteSpace(folder)) @@ -149,7 +149,7 @@ public class GameServerModel : IEquatable public string GameName => GameBiz.ToGameName(); - public string GameServer => GameBiz.ToGameServer(); + public string GameServer => GameBiz.ToGameServerName(); public bool Equals(GameServerModel? other) { diff --git a/src/Starward/Models/GameBizIcon.cs b/src/Starward/Models/GameBizIcon.cs index 5cc0a73f8..59b7748ad 100644 --- a/src/Starward/Models/GameBizIcon.cs +++ b/src/Starward/Models/GameBizIcon.cs @@ -19,7 +19,7 @@ public partial class GameBizIcon : ObservableObject, IEquatable public string ServerText => GameBizToServerText(GameBiz); - public string ServerName => GameBiz.ToGameServer(); + public string ServerName => GameBiz.ToGameServerName(); public bool CurrentGameBiz { get; set; } @@ -30,12 +30,12 @@ public partial class GameBizIcon : ObservableObject, IEquatable private static string GameBizToIcon(GameBiz gameBiz) { - return gameBiz.ToGame() switch + return gameBiz.ToGame().Value switch { - GameBiz.Honkai3rd => "ms-appx:///Assets/Image/icon_bh3.jpg", - GameBiz.GenshinImpact => "ms-appx:///Assets/Image/icon_ys.jpg", - GameBiz.StarRail => "ms-appx:///Assets/Image/icon_sr.jpg", - GameBiz.ZZZ => "ms-appx:///Assets/Image/icon_zzz.jpg", + GameBiz.bh3 => "ms-appx:///Assets/Image/icon_bh3.jpg", + GameBiz.hk4e => "ms-appx:///Assets/Image/icon_ys.jpg", + GameBiz.hkrpg => "ms-appx:///Assets/Image/icon_sr.jpg", + GameBiz.nap => "ms-appx:///Assets/Image/icon_zzz.jpg", _ => "ms-appx:///Assets/Image/Transparent.png", }; } @@ -43,11 +43,11 @@ private static string GameBizToIcon(GameBiz gameBiz) private static string GameBizToServerIcon(GameBiz gameBiz) { - return gameBiz switch + return gameBiz.Value switch { GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => "ms-appx:///Assets/Image/gameicon_hyperion.png", GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.nap_global => "ms-appx:///Assets/Image/gameicon_hoyolab.png", - GameBiz.hk4e_cloud => "ms-appx:///Assets/Image/gameicon_cloud.png", + GameBiz.clgm_cn => "ms-appx:///Assets/Image/gameicon_cloud.png", GameBiz.hk4e_bilibili or GameBiz.hkrpg_bilibili or GameBiz.nap_bilibili => "ms-appx:///Assets/Image/gameicon_bilibili.png", _ => "ms-appx:///Assets/Image/Transparent.png", }; @@ -56,13 +56,13 @@ private static string GameBizToServerIcon(GameBiz gameBiz) private static string GameBizToServerText(GameBiz gameBiz) { - return gameBiz switch + return gameBiz.Value switch { GameBiz.bh3_global => "EA", GameBiz.bh3_jp => "JP", GameBiz.bh3_kr => "KR", - GameBiz.bh3_overseas => "SA", - GameBiz.bh3_tw => "TC", + GameBiz.bh3_os => "SA", + GameBiz.bh3_asia => "TC", _ => "", }; } diff --git a/src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs b/src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs index b2b485e67..d61ec64fd 100644 --- a/src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs +++ b/src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs @@ -51,11 +51,11 @@ private void RootGrid_Loaded(object sender, RoutedEventArgs e) try { // todo WinAppSDK 1.5 ΪϷҳõļ - if (GameBiz.ToGame() is GameBiz.GenshinImpact) + if (GameBiz.ToGame() == GameBiz.hk4e) { webview.Source = new Uri("https://ys.mihoyo.com/cloud/"); } - if (GameBiz.ToGame() is GameBiz.StarRail) + if (GameBiz.ToGame() == GameBiz.hkrpg) { webview.Source = new Uri("https://sr.mihoyo.com/cloud/"); } @@ -107,10 +107,10 @@ private async void Button_Click(object sender, RoutedEventArgs e) private static string? GetMatchUrl(GameBiz gameBiz, string html) { - string? prefix = gameBiz.ToGame() switch + string? prefix = gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => SPAN_WEB_PREFIX_YS_CN, - GameBiz.StarRail => SPAN_WEB_PREFIX_SR_CN, + GameBiz.hk4e => SPAN_WEB_PREFIX_YS_CN, + GameBiz.hkrpg => SPAN_WEB_PREFIX_SR_CN, _ => null }; if (prefix is not null) diff --git a/src/Starward/MyWindows/GameNoticesWindow.xaml.cs b/src/Starward/MyWindows/GameNoticesWindow.xaml.cs index 1e2c1a03a..4a4e7526c 100644 --- a/src/Starward/MyWindows/GameNoticesWindow.xaml.cs +++ b/src/Starward/MyWindows/GameNoticesWindow.xaml.cs @@ -183,7 +183,7 @@ private async Task InsertBgAsync() } catch (Exception ex) { - _logger.LogError(ex, "Get background image ({gameBiz})", GameBiz); + _logger.LogError(ex, "Get background image ({gameBiz})", (object)GameBiz); } await webview.EnsureCoreWebView2Async(); string script = $$""" diff --git a/src/Starward/Pages/DownloadGamePage.xaml.cs b/src/Starward/Pages/DownloadGamePage.xaml.cs index 2977b7aad..bbbdcbf2a 100644 --- a/src/Starward/Pages/DownloadGamePage.xaml.cs +++ b/src/Starward/Pages/DownloadGamePage.xaml.cs @@ -60,16 +60,16 @@ public DownloadGamePage() _timer.Interval = TimeSpan.FromMilliseconds(100); _timer.Tick += _timer_Tick; - gameBiz = AppConfig.Configuration.GetValue("biz"); + GameBiz gameBiz = AppConfig.Configuration.GetValue("biz"); gameFolder = AppConfig.Configuration.GetValue("loc")!; voiceLanguage = AppConfig.Configuration.GetValue("lang"); - _installGameService = gameBiz.ToGame() switch + _installGameService = gameBiz.ToGame().Value switch { - GameBiz.Honkai3rd => AppConfig.GetService(), - GameBiz.GenshinImpact => AppConfig.GetService(), - GameBiz.StarRail => AppConfig.GetService(), - GameBiz.ZZZ => AppConfig.GetService(), + GameBiz.bh3 => AppConfig.GetService(), + GameBiz.hk4e => AppConfig.GetService(), + GameBiz.hkrpg => AppConfig.GetService(), + GameBiz.nap => AppConfig.GetService(), _ => null!, }; } @@ -170,7 +170,7 @@ private async Task CheckAvailableAsync() await instance.RedirectActivationToAsync(AppInstance.GetCurrent().GetActivatedEventArgs()); Environment.Exit(0); } - if (gameBiz.ToGame() is GameBiz.None || gameBiz is GameBiz.hk4e_cloud || _installGameService is null) + if (!gameBiz.IsKnown() || gameBiz == GameBiz.clgm_cn || _installGameService is null) { instance.UnregisterKey(); var dialog = new ContentDialog diff --git a/src/Starward/Pages/GachaLogPage.xaml.cs b/src/Starward/Pages/GachaLogPage.xaml.cs index f6def0415..580e8d030 100644 --- a/src/Starward/Pages/GachaLogPage.xaml.cs +++ b/src/Starward/Pages/GachaLogPage.xaml.cs @@ -61,20 +61,20 @@ protected override void OnNavigatedTo(NavigationEventArgs e) if (e.Parameter is GameBiz biz) { GachaTypeText = GachaLogService.GetGachaLogText(biz); - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { EnableGenshinGachaItemStats = true; ToggleSwitch_ShowChronicledWish.Visibility = Visibility.Visible; _gachaLogService = AppConfig.GetService(); Image_Emoji.Source = new BitmapImage(AppConfig.EmojiPaimon); } - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { EnableStarRailGachaItemStats = true; _gachaLogService = AppConfig.GetService(); Image_Emoji.Source = new BitmapImage(AppConfig.EmojiPom); } - if (biz.ToGame() is GameBiz.ZZZ) + if (biz.ToGame() == GameBiz.nap) { IsZZZGachaStatsCardVisible = true; _gachaLogService = AppConfig.GetService(); @@ -84,7 +84,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) Button_Export_JSON.IsEnabled = false; Button_Import.IsEnabled = false; } - if (biz.IsGlobalServer()) + if (biz.IsGlobalOfficial()) { MenuFlyoutItem_CloudGame.Visibility = Visibility.Collapsed; } @@ -251,7 +251,7 @@ private void UpdateGachaTypeStats(long? uid) else { (var gachaStats, var itemStats) = _gachaLogService.GetGachaTypeStats(uid.Value); - if (CurrentGameBiz.ToGame() is GameBiz.GenshinImpact or GameBiz.StarRail) + if (CurrentGameBiz.ToGame().Value is GameBiz.hk4e or GameBiz.hkrpg) { noviceGachaTypeStats = gachaStats.FirstOrDefault(x => x.GachaType == GachaType.NoviceWish || x.GachaType == GachaType.DepartureWarp); chronicledWishStats = gachaStats.FirstOrDefault(x => x.GachaType == GachaType.ChronicledWish); diff --git a/src/Starward/Pages/GameLauncherPage.xaml.cs b/src/Starward/Pages/GameLauncherPage.xaml.cs index f02f53627..3e614ebf4 100644 --- a/src/Starward/Pages/GameLauncherPage.xaml.cs +++ b/src/Starward/Pages/GameLauncherPage.xaml.cs @@ -141,7 +141,7 @@ private void InitializeCurrentGameBiz() OnPropertyChanged(nameof(EnableCustomBg)); #pragma warning restore MVVMTK0034 // Direct field reference to [ObservableProperty] backing field CustomBg = AppConfig.GetCustomBg(CurrentGameBiz); - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { Button_UninstallGame.IsEnabled = false; Button_SettingRepairGame.IsEnabled = false; @@ -172,7 +172,7 @@ private async Task UpdateGameContentAsync() { try { - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { GameBannerAndPost.GameContent = await _hoYoPlayService.GetGameContentAsync(GameBiz.hk4e_cn); } @@ -197,7 +197,7 @@ private async Task UpdateGameNoticesAlertAsync() { try { - if (AppConfig.DisableGameNoticeRedHot || AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer()) + if (AppConfig.DisableGameNoticeRedHot || AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibili()) { GameBannerAndPost.IsGameNoticesAlert = false; return; @@ -282,7 +282,7 @@ partial void OnInstallPathChanged(string? value) private string? hardLinkPath; - public bool IsGameSupportRepair => CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.hk4e_cloud; + public bool IsGameSupportRepair => CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.clgm_cn; public bool IsStartGameButtonEnable => LocalGameVersion != null && LocalGameVersion >= LatestGameVersion && IsGameExeExists && !IsGameRunning; @@ -519,7 +519,7 @@ private void GetGameAccount() { try { - if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer()) + if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibili()) { StackPanel_Account.Visibility = Visibility.Collapsed; return; @@ -829,7 +829,7 @@ private async Task InstallGameAsync() { try { - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { await Launcher.LaunchUriAsync(new Uri("https://ys.mihoyo.com/cloud/#/download")); return; @@ -1051,7 +1051,7 @@ private async Task DownloadGameAsync() { try { - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { await Launcher.LaunchUriAsync(new Uri("https://ys.mihoyo.com/cloud/#/download")); return; diff --git a/src/Starward/Pages/GameResourcePage.xaml.cs b/src/Starward/Pages/GameResourcePage.xaml.cs index e242c3ed1..a6521fff7 100644 --- a/src/Starward/Pages/GameResourcePage.xaml.cs +++ b/src/Starward/Pages/GameResourcePage.xaml.cs @@ -38,7 +38,7 @@ public GameResourcePage() - public string GameServerName => $"{CurrentGameBiz.ToGameName()} - {CurrentGameBiz.ToGameServer()}"; + public string GameServerName => $"{CurrentGameBiz.ToGameName()} - {CurrentGameBiz.ToGameServerName()}"; @@ -65,7 +65,7 @@ protected override async void OnLoaded() gamePackage = await _gamePackageService.GetGamePackageAsync(CurrentGameBiz); LatestVersion = gamePackage.Main.Major!.Version; var list = GetGameResourcePackageGroups(gamePackage.Main); - if (CurrentGameBiz.IsBilibiliServer()) + if (CurrentGameBiz.IsBilibili()) { var sdk = await _hoyoPlayClient.GetGameChannelSDKAsync(LauncherId.FromGameBiz(CurrentGameBiz)!, "", GameId.FromGameBiz(CurrentGameBiz)!); if (sdk is not null) diff --git a/src/Starward/Pages/GameSettingPage.xaml.cs b/src/Starward/Pages/GameSettingPage.xaml.cs index ca968711d..4fd2f642e 100644 --- a/src/Starward/Pages/GameSettingPage.xaml.cs +++ b/src/Starward/Pages/GameSettingPage.xaml.cs @@ -48,12 +48,12 @@ protected override void OnNavigatedTo(NavigationEventArgs e) if (e.Parameter is GameBiz biz) { gameBiz = biz; - Image_Emoji.Source = gameBiz.ToGame() switch + Image_Emoji.Source = gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => new BitmapImage(AppConfig.EmojiPaimon), - GameBiz.StarRail => new BitmapImage(AppConfig.EmojiPom), - GameBiz.Honkai3rd => new BitmapImage(AppConfig.EmojiAI), - GameBiz.ZZZ => new BitmapImage(AppConfig.EmojiBangboo), + GameBiz.bh3 => new BitmapImage(AppConfig.EmojiAI), + GameBiz.hk4e => new BitmapImage(AppConfig.EmojiPaimon), + GameBiz.hkrpg => new BitmapImage(AppConfig.EmojiPom), + GameBiz.nap => new BitmapImage(AppConfig.EmojiBangboo), _ => null, }; } @@ -228,7 +228,7 @@ private async Task InitializeGameSettingAsync() var localVersion = await _gameResourceService.GetLocalGameVersionAsync(gameBiz); if (localVersion is null) { - if (gameBiz is GameBiz.hk4e_cloud) + if (gameBiz == GameBiz.clgm_cn) { TextBlock_GameNotInstalled.Text = Lang.GameSettingPage_FeatureNotSupported; } @@ -236,11 +236,11 @@ private async Task InitializeGameSettingAsync() return; } IsBaseSettingEnable = true; - if (gameBiz.ToGame() is GameBiz.GenshinImpact or GameBiz.StarRail) + if (gameBiz.ToGame().Value is GameBiz.hk4e or GameBiz.hkrpg) { IsLanguageSettingEnable = true; } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { IsGraphicsSettingEnable = true; } diff --git a/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs b/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs index 0b051218e..483366c78 100644 --- a/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs +++ b/src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs @@ -48,14 +48,14 @@ protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter is GameBiz biz) { - CurrentGameBiz = biz switch + CurrentGameBiz = biz.Value switch { - GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => GameBiz.hk4e_cn, + GameBiz.clgm_cn or GameBiz.hk4e_bilibili => GameBiz.hk4e_cn, GameBiz.hkrpg_bilibili => GameBiz.hkrpg_cn, _ => biz }; - _gameRecordService.IsHoyolab = CurrentGameBiz.IsGlobalServer(); - if (CurrentGameBiz.IsGlobalServer()) + _gameRecordService.IsHoyolab = CurrentGameBiz.IsGlobalOfficial(); + if (CurrentGameBiz.IsGlobalOfficial()) { NavigationViewItem_UpdateDeviceInfo.Visibility = Visibility.Collapsed; } @@ -206,7 +206,7 @@ private void CloseNavigationViewPane() private void InitializeNavigationViewItemVisibility() { - if (CurrentGameBiz.ToGame() is GameBiz.GenshinImpact) + if (CurrentGameBiz.ToGame() == GameBiz.hk4e) { NavigationViewItem_BattleChronicle.Visibility = Visibility.Visible; NavigationViewItem_SpiralAbyss.Visibility = Visibility.Visible; @@ -215,7 +215,7 @@ private void InitializeNavigationViewItemVisibility() // 原神战绩图片 Image_BattleChronicle.Source = new BitmapImage(new("ms-appx:///Assets/Image/ced4deac2162690105bbc8baad2b51a3_4109616186965788891.png")); } - if (CurrentGameBiz.ToGame() is GameBiz.StarRail) + if (CurrentGameBiz.ToGame() == GameBiz.hkrpg) { NavigationViewItem_BattleChronicle.Visibility = Visibility.Visible; NavigationViewItem_SimulatedUniverse.Visibility = Visibility.Visible; @@ -253,7 +253,7 @@ private void InitializeNavigationViewItemVisibility() private List gameRoleList; - public string AvatarUrl => CurrentUser?.AvatarUrl ?? $"ms-appx:///Assets/Image/icon_{(CurrentGameBiz.IsGlobalServer() ? "hoyolab" : "hyperion")}.png"; + public string AvatarUrl => CurrentUser?.AvatarUrl ?? $"ms-appx:///Assets/Image/icon_{(CurrentGameBiz.IsGlobalOfficial() ? "hoyolab" : "hyperion")}.png"; diff --git a/src/Starward/Pages/HoyolabToolbox/LoginPage.xaml.cs b/src/Starward/Pages/HoyolabToolbox/LoginPage.xaml.cs index 856366a74..ab6a772b0 100644 --- a/src/Starward/Pages/HoyolabToolbox/LoginPage.xaml.cs +++ b/src/Starward/Pages/HoyolabToolbox/LoginPage.xaml.cs @@ -47,13 +47,13 @@ public LoginPage() private string GetGameBizUrl() { - if (CurrentGameBiz.IsChinaServer()) + if (CurrentGameBiz.IsChinaOfficial()) { - return CurrentGameBiz.ToGame() switch + return CurrentGameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => $"{URL_CN}ys", - GameBiz.StarRail => $"{URL_CN}sr", - GameBiz.Honkai3rd => $"{URL_CN}bh3", + GameBiz.bh3 => $"{URL_CN}bh3", + GameBiz.hk4e => $"{URL_CN}ys", + GameBiz.hkrpg => $"{URL_CN}sr", _ => URL_CN, }; } diff --git a/src/Starward/Pages/LauncherPage.xaml.cs b/src/Starward/Pages/LauncherPage.xaml.cs index b8cf8682a..355515716 100644 --- a/src/Starward/Pages/LauncherPage.xaml.cs +++ b/src/Starward/Pages/LauncherPage.xaml.cs @@ -148,12 +148,12 @@ private void InitializeCurrentGameBiz() OnPropertyChanged(nameof(EnableCustomBg)); CustomBg = AppConfig.GetCustomBg(CurrentGameBiz); - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { Button_UninstallGame.IsEnabled = false; Grid_BannerAndPost.HorizontalAlignment = HorizontalAlignment.Right; } - if (CurrentGameBiz is GameBiz.nap_cn) + if (CurrentGameBiz == GameBiz.nap_cn) { Button_RepairDropDown.IsEnabled = false; Button_UninstallGame.IsEnabled = false; @@ -316,7 +316,7 @@ private async Task UpdateGameNoticesAlertAsync() { try { - if (AppConfig.DisableGameNoticeRedHot || AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer()) + if (AppConfig.DisableGameNoticeRedHot || AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibili()) { Image_GameNoticesAlert.Visibility = Visibility.Collapsed; return; @@ -452,7 +452,7 @@ private void UpdateGameButtonStyle() private bool isGameExeExists; - public bool IsGameSupportCompleteRepair => CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.hk4e_cloud && (CurrentGameBiz.ToGame() != GameBiz.Honkai3rd || (CurrentGameBiz.ToGame() == GameBiz.Honkai3rd && IsGameExeExists)); + public bool IsGameSupportCompleteRepair => CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.clgm_cn && (CurrentGameBiz.ToGame() != GameBiz.bh3 || (CurrentGameBiz.ToGame() == GameBiz.bh3 && IsGameExeExists)); public bool IsStartGameButtonEnable => LocalGameVersion != null && LocalGameVersion >= LatestGameVersion && IsGameExeExists && !IsGameRunning; @@ -530,7 +530,7 @@ private async void CheckGameVersion() InstallPath = _gameResourceService.GetGameInstallPath(CurrentGameBiz); _logger.LogInformation("Game install path of {biz}: {path}", CurrentGameBiz, InstallPath); IsGameExeExists = _gameResourceService.IsGameExeExists(CurrentGameBiz); - if (CurrentGameBiz == GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { if (Directory.Exists(InstallPath)) { @@ -782,7 +782,7 @@ private void GetGameAccount() { try { - if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer() || CurrentGameBiz is GameBiz.nap_cn) + if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibili() || CurrentGameBiz == GameBiz.nap_cn) { StackPanel_Account.Visibility = Visibility.Collapsed; return; @@ -1008,13 +1008,13 @@ private async Task DownloadGameAsync() { try { - if (CurrentGameBiz is GameBiz.hk4e_cloud) + if (CurrentGameBiz == GameBiz.clgm_cn) { await Launcher.LaunchUriAsync(new Uri("https://mhyy.mihoyo.com/")); return; } - if (CurrentGameBiz is GameBiz.nap_cn) + if (CurrentGameBiz == GameBiz.nap_cn) { await LauncherZZZCBTLauncherAsync(); return; @@ -1229,7 +1229,7 @@ private async Task RepairGameAsync() { try { - if (CurrentGameBiz is GameBiz.nap_cn) + if (CurrentGameBiz == GameBiz.nap_cn) { await LauncherZZZCBTLauncherAsync(); return; @@ -1439,7 +1439,7 @@ private void OpenGameResourcePage() - public bool IsSettingGameRepairButtonEnabled => CurrentGameBiz.ToGame() != GameBiz.ZZZ && CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.hk4e_cloud && LocalGameVersion != null; + public bool IsSettingGameRepairButtonEnabled => CurrentGameBiz.ToGame() != GameBiz.nap && CurrentGameBiz.ToGame() != GameBiz.None && CurrentGameBiz != GameBiz.clgm_cn && LocalGameVersion != null; [ObservableProperty] diff --git a/src/Starward/Pages/MainPage.xaml.cs b/src/Starward/Pages/MainPage.xaml.cs index 477da65ab..d35db521a 100644 --- a/src/Starward/Pages/MainPage.xaml.cs +++ b/src/Starward/Pages/MainPage.xaml.cs @@ -185,7 +185,7 @@ private async Task ShowRecentUpdateContentAsync() private void InitializeGameBiz() { CurrentGameBiz = AppConfig.CurrentGameBiz; - if (CurrentGameBiz.ToGame() is GameBiz.None) + if (!CurrentGameBiz.IsKnown()) { CurrentGameBiz = GameBiz.None; } @@ -281,7 +281,7 @@ private void InitializeBackgroundImage() } else { - if (CurrentGameBiz is GameBiz.hk4e_cloud && !AppConfig.GetEnableCustomBg(GameBiz.hk4e_cloud)) + if (CurrentGameBiz == GameBiz.clgm_cn && !AppConfig.GetEnableCustomBg(GameBiz.clgm_cn)) { Image_Content.HorizontalAlignment = HorizontalAlignment.Left; } @@ -416,7 +416,7 @@ public async Task UpdateBackgroundImageAsync(bool force = false) return; } MainWindow.Current.ChangeAccentColor(back, fore); - if (CurrentGameBiz is GameBiz.hk4e_cloud && !AppConfig.GetEnableCustomBg(GameBiz.hk4e_cloud)) + if (CurrentGameBiz == GameBiz.clgm_cn && !AppConfig.GetEnableCustomBg(GameBiz.clgm_cn)) { Image_Content.HorizontalAlignment = HorizontalAlignment.Left; } @@ -510,7 +510,7 @@ public void PauseVideo(bool sessionLock = false) private void UpdateNavigationViewItemsText() { - if (CurrentGameBiz.ToGame() is GameBiz.None) + if (!CurrentGameBiz.IsKnown()) { NavigationViewItem_Launcher.Visibility = Visibility.Collapsed; NavigationViewItem_GameSetting.Visibility = Visibility.Collapsed; @@ -519,7 +519,7 @@ private void UpdateNavigationViewItemsText() NavigationViewItem_HoyolabToolbox.Visibility = Visibility.Collapsed; NavigationViewItem_SelfQuery.Visibility = Visibility.Collapsed; } - else if (CurrentGameBiz.ToGame() is GameBiz.Honkai3rd) + else if (CurrentGameBiz.ToGame() == GameBiz.bh3) { NavigationViewItem_Launcher.Visibility = Visibility.Visible; NavigationViewItem_GameSetting.Visibility = Visibility.Visible; @@ -528,7 +528,7 @@ private void UpdateNavigationViewItemsText() NavigationViewItem_HoyolabToolbox.Visibility = Visibility.Collapsed; NavigationViewItem_SelfQuery.Visibility = Visibility.Collapsed; } - else if (CurrentGameBiz.ToGame() is GameBiz.ZZZ) + else if (CurrentGameBiz.ToGame() == GameBiz.nap) { NavigationViewItem_Launcher.Visibility = Visibility.Visible; NavigationViewItem_GameSetting.Visibility = Visibility.Visible; @@ -546,30 +546,30 @@ private void UpdateNavigationViewItemsText() NavigationViewItem_HoyolabToolbox.Visibility = Visibility.Visible; NavigationViewItem_SelfQuery.Visibility = Visibility.Visible; } - if (CurrentGameBiz.ToGame() is GameBiz.GenshinImpact) + if (CurrentGameBiz.ToGame() == GameBiz.hk4e) { // 祈愿记录 ToolTipService.SetToolTip(NavigationViewItem_GachaLog, Lang.GachaLogService_WishRecords); TextBlock_GachaLog.Text = Lang.GachaLogService_WishRecords; } - if (CurrentGameBiz.ToGame() is GameBiz.StarRail) + if (CurrentGameBiz.ToGame() == GameBiz.hkrpg) { // 跃迁记录 ToolTipService.SetToolTip(NavigationViewItem_GachaLog, Lang.GachaLogService_WarpRecords); TextBlock_GachaLog.Text = Lang.GachaLogService_WarpRecords; } - if (CurrentGameBiz.ToGame() is GameBiz.ZZZ) + if (CurrentGameBiz.ToGame() == GameBiz.nap) { // 调频记录 ToolTipService.SetToolTip(NavigationViewItem_GachaLog, Lang.GachaLogService_SignalSearchRecords); TextBlock_GachaLog.Text = Lang.GachaLogService_SignalSearchRecords; } - if (CurrentGameBiz.IsChinaServer()) + if (CurrentGameBiz.IsChinaOfficial()) { ToolTipService.SetToolTip(NavigationViewItem_HoyolabToolbox, Lang.HyperionToolbox); TextBlock_HoyolabToolbox.Text = Lang.HyperionToolbox; } - if (CurrentGameBiz.IsGlobalServer()) + if (CurrentGameBiz.IsGlobalOfficial()) { ToolTipService.SetToolTip(NavigationViewItem_HoyolabToolbox, Lang.HoYoLABToolbox); TextBlock_HoyolabToolbox.Text = Lang.HoYoLABToolbox; @@ -624,8 +624,8 @@ public void NavigateTo(Type? page, object? param = null, NavigationTransitionInf { string? destPage = page?.Name; if (destPage is null or nameof(BlankPage) - || (CurrentGameBiz.ToGame() is GameBiz.Honkai3rd && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(ScreenshotPage)) - || CurrentGameBiz.ToGame() is GameBiz.ZZZ && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(GachaLogPage) and not nameof(ScreenshotPage) and not nameof(SelfQueryPage)) + || (CurrentGameBiz.ToGame() == GameBiz.bh3 && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(ScreenshotPage)) + || CurrentGameBiz.ToGame() == GameBiz.nap && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(GachaLogPage) and not nameof(ScreenshotPage) and not nameof(SelfQueryPage)) { page = typeof(GameLauncherPage); destPage = nameof(GameLauncherPage); diff --git a/src/Starward/Pages/PageBase.cs b/src/Starward/Pages/PageBase.cs index 5f4608546..d8ce9d8e6 100644 --- a/src/Starward/Pages/PageBase.cs +++ b/src/Starward/Pages/PageBase.cs @@ -8,7 +8,7 @@ public abstract class PageBase : Page { - public GameBiz CurrentGameBiz { get; protected set; } + public GameBiz CurrentGameBiz { get; protected set; } = GameBiz.None; public PageBase() diff --git a/src/Starward/Pages/ScreenshotPage.xaml.cs b/src/Starward/Pages/ScreenshotPage.xaml.cs index 444c58103..26abae1c3 100644 --- a/src/Starward/Pages/ScreenshotPage.xaml.cs +++ b/src/Starward/Pages/ScreenshotPage.xaml.cs @@ -56,12 +56,12 @@ protected override void OnNavigatedTo(NavigationEventArgs e) if (e.Parameter is GameBiz biz) { gameBiz = biz; - Image_Emoji.Source = gameBiz.ToGame() switch + Image_Emoji.Source = gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => new BitmapImage(AppConfig.EmojiPaimon), - GameBiz.StarRail => new BitmapImage(AppConfig.EmojiPom), - GameBiz.Honkai3rd => new BitmapImage(AppConfig.EmojiAI), - GameBiz.ZZZ => new BitmapImage(AppConfig.EmojiBangboo), + GameBiz.hk4e => new BitmapImage(AppConfig.EmojiPaimon), + GameBiz.hkrpg => new BitmapImage(AppConfig.EmojiPom), + GameBiz.bh3 => new BitmapImage(AppConfig.EmojiAI), + GameBiz.nap => new BitmapImage(AppConfig.EmojiBangboo), _ => null, }; } diff --git a/src/Starward/Pages/SelfQueryPage.xaml.cs b/src/Starward/Pages/SelfQueryPage.xaml.cs index 59218ebe7..898b9a54a 100644 --- a/src/Starward/Pages/SelfQueryPage.xaml.cs +++ b/src/Starward/Pages/SelfQueryPage.xaml.cs @@ -49,12 +49,12 @@ public SelfQueryPage() private GameBiz gameBiz; - public string GameIcon => gameBiz.ToGame() switch + public string GameIcon => gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => "ms-appx:///Assets/Image/icon_ys.jpg", - GameBiz.StarRail => "ms-appx:///Assets/Image/icon_sr.jpg", - GameBiz.Honkai3rd => "ms-appx:///Assets/Image/icon_bh3.jpg", - GameBiz.ZZZ => "ms-appx:///Assets/Image/icon_zzz.jpg", + GameBiz.hk4e => "ms-appx:///Assets/Image/icon_ys.jpg", + GameBiz.hkrpg => "ms-appx:///Assets/Image/icon_sr.jpg", + GameBiz.bh3 => "ms-appx:///Assets/Image/icon_bh3.jpg", + GameBiz.nap => "ms-appx:///Assets/Image/icon_zzz.jpg", _ => "", }; @@ -65,19 +65,19 @@ protected override void OnNavigatedTo(NavigationEventArgs e) base.OnNavigatedTo(e); if (e.Parameter is GameBiz biz) { - if (biz is GameBiz.hk4e_cloud) + if (biz == GameBiz.clgm_cn) { biz = GameBiz.hk4e_cn; } - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { ListView_QueryItems_Genshin.Visibility = Visibility.Visible; } - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { ListView_QueryItems_StarRail.Visibility = Visibility.Visible; } - if (biz.ToGame() is GameBiz.ZZZ) + if (biz.ToGame() == GameBiz.nap) { ListView_QueryItems_ZZZ.Visibility = Visibility.Visible; } @@ -179,15 +179,15 @@ private void LoadUidList() { try { - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { UidList = new(_selfQueryService.GetGenshinUids()); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { UidList = new(_selfQueryService.GetStarRailUids()); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { UidList = new(_selfQueryService.GetZZZUids()); } @@ -229,7 +229,7 @@ private void LoadQueryTypeStats() return; } long uid = SelectUid.Value; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { var list = new List(); using var dapper = _databaseService.CreateConnection(); @@ -248,7 +248,7 @@ private void LoadQueryTypeStats() } TypeStatsList = list; } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { var list = new List(); using var dapper = _databaseService.CreateConnection(); @@ -267,7 +267,7 @@ private void LoadQueryTypeStats() } TypeStatsList = list; } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { var list = new List(); using var dapper = _databaseService.CreateConnection(); @@ -375,15 +375,15 @@ private async void Button_UpdateSelfQueryItems_Click(object sender, RoutedEventA return; } stats.IsUpdating = true; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { await UpdateGenshinQueryItemsAsync(stats, (GenshinQueryType)stats.Type); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { await UpdateStarRailQueryItemsAsync(stats, (StarRailQueryType)stats.Type); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { await UpdateZZZQueryItemsAsync(stats, (ZZZQueryType)stats.Type); } @@ -507,19 +507,19 @@ private void TypeStatsChanged(int type) } long uid = SelectUid.Value; using var dapper = _databaseService.CreateConnection(); - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { TypeStatsMonthList = dapper.Query(""" SELECT DISTINCT STRFTIME('%Y-%m', DateTime) FROM GenshinQueryItem WHERE Type=@type ORDER BY DateTime DESC; """, new { uid, type }).ToList(); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { TypeStatsMonthList = dapper.Query(""" SELECT DISTINCT STRFTIME('%Y-%m', Time) FROM StarRailQueryItem WHERE Type=@type ORDER BY Time DESC; """, new { uid, type }).ToList(); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { TypeStatsMonthList = dapper.Query(""" SELECT DISTINCT STRFTIME('%Y-%m', DateTime) FROM ZZZQueryItem WHERE Type=@type ORDER BY DateTime DESC; @@ -545,7 +545,7 @@ private void LoadMonthQueryItems(int type, string month) } long uid = SelectUid.Value; using var dapper = _databaseService.CreateConnection(); - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { GenshinQueryItemList = dapper.Query(""" SELECT * FROM GenshinQueryItem WHERE Uid=@uid AND Type=@type AND DateTime LIKE @month ORDER BY DateTime DESC; @@ -553,7 +553,7 @@ private void LoadMonthQueryItems(int type, string month) MonthAddNum = GenshinQueryItemList.Where(x => x.AddNum > 0).Sum(x => x.AddNum); MonthSubNum = GenshinQueryItemList.Where(x => x.AddNum < 0).Sum(x => x.AddNum); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { StarRailQueryItemList = dapper.Query(""" SELECT * FROM StarRailQueryItem WHERE Uid=@uid AND Type=@type AND Time LIKE @month ORDER BY Time DESC; @@ -561,7 +561,7 @@ private void LoadMonthQueryItems(int type, string month) MonthAddNum = StarRailQueryItemList.Where(x => x.AddNum > 0).Sum(x => x.AddNum); MonthSubNum = StarRailQueryItemList.Where(x => x.AddNum < 0).Sum(x => x.AddNum); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { var list = ZZZQueryItemList = dapper.Query(""" SELECT * FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND DateTime LIKE @month ORDER BY DateTime DESC; @@ -598,15 +598,15 @@ private async Task DeleteCurrentMonthData() long uid = SelectUid.Value; string type = ""; string month = SelectTypeStatsMonth; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { type = ((GenshinQueryType)SelectTypeStats.Type).ToLocalization(); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { type = ((StarRailQueryType)SelectTypeStats.Type).ToLocalization(); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { type = ((ZZZQueryType)SelectTypeStats.Type).ToLocalization(); } @@ -624,19 +624,19 @@ private async Task DeleteCurrentMonthData() _logger.LogInformation($"Ready to delete records of {type} in {month}."); using var dapper = _databaseService.CreateConnection(); int count = 0; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { count = dapper.Execute(""" DELETE FROM GenshinQueryItem WHERE Uid=@uid AND Type=@Type AND DateTime LIKE @time; """, new { uid, SelectTypeStats.Type, time = month + "%" }); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { count = dapper.Execute(""" DELETE FROM StarRailQueryItem WHERE Uid=@uid AND Type=@Type AND Time LIKE @time; """, new { uid, SelectTypeStats.Type, time = month + "%" }); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { count = dapper.Execute(""" DELETE FROM ZZZQueryItem WHERE Uid=@uid AND Type=@Type AND DateTime LIKE @time; @@ -674,15 +674,15 @@ private async Task UpdateAllQueryItemsAsync() return; } stats.IsUpdating = true; - if (gameBiz.ToGame() is GameBiz.GenshinImpact) + if (gameBiz.ToGame() == GameBiz.hk4e) { await UpdateGenshinQueryItemsAsync(stats, (GenshinQueryType)stats.Type, true); } - if (gameBiz.ToGame() is GameBiz.StarRail) + if (gameBiz.ToGame() == GameBiz.hkrpg) { await UpdateStarRailQueryItemsAsync(stats, (StarRailQueryType)stats.Type, true); } - if (gameBiz.ToGame() is GameBiz.ZZZ) + if (gameBiz.ToGame() == GameBiz.nap) { await UpdateZZZQueryItemsAsync(stats, (ZZZQueryType)stats.Type, true); } diff --git a/src/Starward/Pages/Welcome/SelectGamePage.xaml.cs b/src/Starward/Pages/Welcome/SelectGamePage.xaml.cs index 161a8fd8d..27730fb64 100644 --- a/src/Starward/Pages/Welcome/SelectGamePage.xaml.cs +++ b/src/Starward/Pages/Welcome/SelectGamePage.xaml.cs @@ -152,9 +152,9 @@ private async Task NextAsync() private void InitializeGameComboBox() { ComboBox_Game.Items.Clear(); - ComboBox_Game.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_cn.ToGameName(), Tag = GameBiz.Honkai3rd }); - ComboBox_Game.Items.Add(new ComboBoxItem { Content = GameBiz.hk4e_cn.ToGameName(), Tag = GameBiz.GenshinImpact }); - ComboBox_Game.Items.Add(new ComboBoxItem { Content = GameBiz.hkrpg_cn.ToGameName(), Tag = GameBiz.StarRail }); + ComboBox_Game.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_cn).ToGameName(), Tag = GameBiz.bh3 }); + ComboBox_Game.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hk4e_cn).ToGameName(), Tag = GameBiz.hk4e }); + ComboBox_Game.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hkrpg_cn).ToGameName(), Tag = GameBiz.hkrpg }); } @@ -165,27 +165,27 @@ private void ComboBox_Game_SelectionChanged(object sender, SelectionChangedEvent ComboBox_GameServer.Items.Clear(); if (e.AddedItems.FirstOrDefault() is ComboBoxItem item) { - if (item.Tag is GameBiz.Honkai3rd) + if (item.Tag == GameBiz.bh3) { - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_cn.ToGameServer(), Tag = GameBiz.bh3_cn }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_global.ToGameServer(), Tag = GameBiz.bh3_global }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_jp.ToGameServer(), Tag = GameBiz.bh3_jp }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_kr.ToGameServer(), Tag = GameBiz.bh3_kr }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_overseas.ToGameServer(), Tag = GameBiz.bh3_overseas }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.bh3_tw.ToGameServer(), Tag = GameBiz.bh3_tw }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_cn).ToGameServerName(), Tag = GameBiz.bh3_cn }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_global).ToGameServerName(), Tag = GameBiz.bh3_global }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_jp).ToGameServerName(), Tag = GameBiz.bh3_jp }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_kr).ToGameServerName(), Tag = GameBiz.bh3_kr }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_os).ToGameServerName(), Tag = GameBiz.bh3_os }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.bh3_asia).ToGameServerName(), Tag = GameBiz.bh3_asia }); } - if (item.Tag is GameBiz.GenshinImpact) + if (item.Tag is GameBiz.hk4e) { - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hk4e_cn.ToGameServer(), Tag = GameBiz.hk4e_cn }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hk4e_global.ToGameServer(), Tag = GameBiz.hk4e_global }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hk4e_cloud.ToGameServer(), Tag = GameBiz.hk4e_cloud }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hk4e_bilibili.ToGameServer(), Tag = GameBiz.hk4e_bilibili }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hk4e_cn).ToGameServerName(), Tag = GameBiz.hk4e_cn }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hk4e_global).ToGameServerName(), Tag = GameBiz.hk4e_global }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.clgm_cn).ToGameServerName(), Tag = GameBiz.clgm_cn }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hk4e_bilibili).ToGameServerName(), Tag = GameBiz.hk4e_bilibili }); } - if (item.Tag is GameBiz.StarRail) + if (item.Tag is GameBiz.hkrpg) { - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hkrpg_cn.ToGameServer(), Tag = GameBiz.hkrpg_cn }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hkrpg_global.ToGameServer(), Tag = GameBiz.hkrpg_global }); - ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = GameBiz.hkrpg_bilibili.ToGameServer(), Tag = GameBiz.hkrpg_bilibili }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hkrpg_cn).ToGameServerName(), Tag = GameBiz.hkrpg_cn }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hkrpg_global).ToGameServerName(), Tag = GameBiz.hkrpg_global }); + ComboBox_GameServer.Items.Add(new ComboBoxItem { Content = ((GameBiz)GameBiz.hkrpg_bilibili).ToGameServerName(), Tag = GameBiz.hkrpg_bilibili }); } } } @@ -202,7 +202,7 @@ private void ComboBox_GameServer_SelectionChanged(object sender, SelectionChange private void ChangeGameBiz(string bizStr) { - if (Enum.TryParse(bizStr, out var biz)) + if (GameBiz.TryParse(bizStr, out GameBiz biz)) { _logger.LogInformation("Change game region to {gamebiz}", biz); SelectBiz = biz; @@ -237,7 +237,7 @@ private void ChangeGameInfo() var sw = Stopwatch.StartNew(); try { - var game_info = games.FirstOrDefault(x => x.GameBiz == SelectBiz); + var game_info = games.FirstOrDefault((Func)(x => x.GameBiz == SelectBiz)); if (game_info is null) { Grid_GameInfo.Opacity = 0; diff --git a/src/Starward/Program.cs b/src/Starward/Program.cs index 66c6d9ce7..83d4546e8 100644 --- a/src/Starward/Program.cs +++ b/src/Starward/Program.cs @@ -30,8 +30,8 @@ static void Main(string[] args) if (args[0].ToLower() is "playtime") { int pid = AppConfig.Configuration.GetValue("pid"); - GameBiz biz = AppConfig.Configuration.GetValue("biz"); - if (pid > 0 && biz > 0) + GameBiz biz = (GameBiz)AppConfig.Configuration.GetValue("biz"); + if (pid > 0 && biz.IsKnown()) { var playtime = AppConfig.GetService(); playtime.LogPlayTimeAsync(biz, pid).GetAwaiter().GetResult(); @@ -41,7 +41,7 @@ static void Main(string[] args) if (args[0].ToLower() is "uninstall") { - GameBiz biz = AppConfig.Configuration.GetValue("biz"); + GameBiz biz = (GameBiz)AppConfig.Configuration.GetValue("biz"); string? loc = AppConfig.Configuration.GetValue("loc"); UninstallStep steps = AppConfig.Configuration.GetValue("steps"); var gameService = AppConfig.GetService(); @@ -52,7 +52,7 @@ static void Main(string[] args) if (args[0].ToLower() is "startgame") { - GameBiz biz = AppConfig.Configuration.GetValue("biz"); + GameBiz biz = (GameBiz)AppConfig.Configuration.GetValue("biz"); var p = AppConfig.GetService().StartGame(biz, true); if (p != null) { diff --git a/src/Starward/Services/DatabaseService.cs b/src/Starward/Services/DatabaseService.cs index 499ea87e0..e035b7e8d 100644 --- a/src/Starward/Services/DatabaseService.cs +++ b/src/Starward/Services/DatabaseService.cs @@ -1,6 +1,7 @@ using Dapper; using Microsoft.Data.Sqlite; using Microsoft.Extensions.Logging; +using Starward.Core; using Starward.Core.GameRecord.Genshin.TravelersDiary; using Starward.Core.GameRecord.StarRail.TrailblazeCalendar; using System; @@ -32,6 +33,7 @@ static DatabaseService() SqlMapper.AddTypeHandler(new DapperSqlMapper.TravelersDiaryPrimogemsMonthGroupStatsListHandler()); SqlMapper.AddTypeHandler(new DapperSqlMapper.TrailblazeCalendarMonthDataGroupByListHandler()); SqlMapper.AddTypeHandler(new DapperSqlMapper.StringListHandler()); + SqlMapper.AddTypeHandler(new DapperSqlMapper.GameBizHandler()); } @@ -777,6 +779,20 @@ public override void SetValue(IDbDataParameter parameter, List? value) } + public class GameBizHandler : SqlMapper.TypeHandler + { + public override GameBiz? Parse(object value) + { + return new GameBiz(value as string); + } + + public override void SetValue(IDbDataParameter parameter, GameBiz? value) + { + parameter.Value = value?.ToString() ?? ""; + } + } + + } diff --git a/src/Starward/Services/Download/GenshinInstallGameService.cs b/src/Starward/Services/Download/GenshinInstallGameService.cs index aa70de7ca..e7ee5054a 100644 --- a/src/Starward/Services/Download/GenshinInstallGameService.cs +++ b/src/Starward/Services/Download/GenshinInstallGameService.cs @@ -179,7 +179,7 @@ private async Task> GetAudioPkgVersionsAsync(string prefix protected async Task MoveAudioAssetsFromPersistentToStreamAssetsAsync() { - string dataName = CurrentGameBiz switch + string dataName = CurrentGameBiz.Value switch { GameBiz.hk4e_cn => "YuanShen_Data", GameBiz.hk4e_global => "GenshinImpact_Data", diff --git a/src/Starward/Services/Download/InstallGameManager.cs b/src/Starward/Services/Download/InstallGameManager.cs index db4185b80..e568ba8c1 100644 --- a/src/Starward/Services/Download/InstallGameManager.cs +++ b/src/Starward/Services/Download/InstallGameManager.cs @@ -110,7 +110,7 @@ private void Model_InstallFinished(object? sender, EventArgs e) model.InstallCanceled -= Model_InstallCanceled; InstallTaskRemoved?.Invoke(this, model); WeakReferenceMessenger.Default.Send(new InstallGameFinishedMessage(model.GameBiz)); - NotificationBehavior.Instance.Success(Lang.InstallGameManager_DownloadTaskCompleted, $"{InstallTaskToString(model.Service.InstallTask)} - {model.GameBiz.ToGameName()} - {model.GameBiz.ToGameServer()}", 0); + NotificationBehavior.Instance.Success(Lang.InstallGameManager_DownloadTaskCompleted, $"{InstallTaskToString(model.Service.InstallTask)} - {model.GameBiz.ToGameName()} - {model.GameBiz.ToGameServerName()}", 0); } } @@ -120,7 +120,7 @@ private void Model_InstallFailed(object? sender, Exception e) { if (sender is InstallGameStateModel model) { - NotificationBehavior.Instance.Error(e, $"{Lang.InstallGameManager_DownloadTaskFailed} ({InstallTaskToString(model.Service.InstallTask)} - {model.GameBiz.ToGameName()} - {model.GameBiz.ToGameServer()})", 0); + NotificationBehavior.Instance.Error(e, $"{Lang.InstallGameManager_DownloadTaskFailed} ({InstallTaskToString(model.Service.InstallTask)} - {model.GameBiz.ToGameName()} - {model.GameBiz.ToGameServerName()})", 0); } } diff --git a/src/Starward/Services/Download/InstallGameService.cs b/src/Starward/Services/Download/InstallGameService.cs index dcfb4f570..50efd2bb8 100644 --- a/src/Starward/Services/Download/InstallGameService.cs +++ b/src/Starward/Services/Download/InstallGameService.cs @@ -57,12 +57,12 @@ public InstallGameService(ILogger logger, HttpClient httpCli public static InstallGameService FromGameBiz(GameBiz gameBiz) { - return gameBiz.ToGame() switch + return gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => AppConfig.GetService(), - GameBiz.StarRail => AppConfig.GetService(), - GameBiz.Honkai3rd => AppConfig.GetService(), - GameBiz.ZZZ => AppConfig.GetService(), + GameBiz.bh3 => AppConfig.GetService(), + GameBiz.hk4e => AppConfig.GetService(), + GameBiz.hkrpg => AppConfig.GetService(), + GameBiz.nap => AppConfig.GetService(), _ => throw new ArgumentOutOfRangeException(nameof(gameBiz), $"Game ({gameBiz}) is not supported."), }; } @@ -232,7 +232,7 @@ public async Task GetGamePackageDecompressedSizeAsync(GameBiz gameBiz, str public async Task InitializeAsync(GameBiz gameBiz, string installPath) { - if (gameBiz.ToGame() is GameBiz.None) + if (!gameBiz.IsKnown()) { throw new ArgumentOutOfRangeException(nameof(gameBiz), gameBiz, $"GameBiz ({gameBiz}) is invalid."); } diff --git a/src/Starward/Services/Gacha/GachaLogService.cs b/src/Starward/Services/Gacha/GachaLogService.cs index 1797dfdd3..abe793289 100644 --- a/src/Starward/Services/Gacha/GachaLogService.cs +++ b/src/Starward/Services/Gacha/GachaLogService.cs @@ -47,9 +47,9 @@ protected GachaLogService(ILogger logger, DatabaseService datab public static string GetGachaLogText(GameBiz biz) { - return biz switch + return biz.Value switch { - GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_cloud => Lang.GachaLogService_WishRecords, + GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.clgm_cn => Lang.GachaLogService_WishRecords, GameBiz.hkrpg_cn or GameBiz.hkrpg_global => Lang.GachaLogService_WarpRecords, GameBiz.nap_cn or GameBiz.nap_global or GameBiz.nap_bilibili => Lang.GachaLogService_SignalSearchRecords, _ => "" diff --git a/src/Starward/Services/Gacha/GenshinGachaService.cs b/src/Starward/Services/Gacha/GenshinGachaService.cs index 840c44768..9a3cdd664 100644 --- a/src/Starward/Services/Gacha/GenshinGachaService.cs +++ b/src/Starward/Services/Gacha/GenshinGachaService.cs @@ -22,7 +22,7 @@ internal class GenshinGachaService : GachaLogService - protected override GameBiz GameBiz { get; } = GameBiz.GenshinImpact; + protected override GameBiz GameBiz { get; } = GameBiz.hk4e; protected override string GachaTableName { get; } = "GenshinGachaItem"; diff --git a/src/Starward/Services/Gacha/StarRailGachaService.cs b/src/Starward/Services/Gacha/StarRailGachaService.cs index 281686cc9..f287431bc 100644 --- a/src/Starward/Services/Gacha/StarRailGachaService.cs +++ b/src/Starward/Services/Gacha/StarRailGachaService.cs @@ -21,7 +21,7 @@ internal class StarRailGachaService : GachaLogService { - protected override GameBiz GameBiz { get; } = GameBiz.StarRail; + protected override GameBiz GameBiz { get; } = GameBiz.hkrpg; protected override string GachaTableName { get; } = "StarRailGachaItem"; diff --git a/src/Starward/Services/Gacha/ZZZGachaService.cs b/src/Starward/Services/Gacha/ZZZGachaService.cs index 25d18229e..293c4ccf2 100644 --- a/src/Starward/Services/Gacha/ZZZGachaService.cs +++ b/src/Starward/Services/Gacha/ZZZGachaService.cs @@ -16,7 +16,7 @@ internal class ZZZGachaService : GachaLogService { - protected override GameBiz GameBiz { get; } = GameBiz.ZZZ; + protected override GameBiz GameBiz { get; } = GameBiz.nap; protected override string GachaTableName { get; } = "ZZZGachaItem"; diff --git a/src/Starward/Services/GameAccountService.cs b/src/Starward/Services/GameAccountService.cs index f05fcfb51..de04fc798 100644 --- a/src/Starward/Services/GameAccountService.cs +++ b/src/Starward/Services/GameAccountService.cs @@ -35,11 +35,12 @@ public GameAccountService(ILogger logger, DatabaseService da public GameAccount? GetGameAccountsFromRegistry(GameBiz biz) { var key = biz.GetGameRegistryKey(); - var keyName = (int)biz switch + var keyName = (biz.IsChinaOfficial(), biz.IsGlobalOfficial(), biz.IsBilibili(), biz.IsChinaCloud()) switch { - 11 or 21 or 31 or 14 or 24 or 41 or 44 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, - 13 => GameRegistry.MIHOYOSDK_ADL_0, - 12 or 22 or (>= 32 and <= 36) or 42 => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, + (true, false, false, false) => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + (false, false, true, false) => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + (false, false, false, true) => GameRegistry.MIHOYOSDK_ADL_0, + (false, true, false, false) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; @@ -53,15 +54,15 @@ 12 or 22 or (>= 32 and <= 36) or 42 => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h Value = adl, IsLogin = true, }; - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { account.Uid = (int)(Registry.GetValue(key, GameRegistry.App_LastUserID_h2841727341, 0) ?? 0); } - else if (biz.ToGame() is GameBiz.Honkai3rd) + else if (biz.ToGame() == GameBiz.bh3) { account.Uid = (int)(Registry.GetValue(key, GameRegistry.GENERAL_DATA_V2_LastLoginUserId_h47158221, 0) ?? 0); } - else if (biz is GameBiz.hk4e_cn or GameBiz.hk4e_global) + else if (biz.Value is GameBiz.hk4e_cn or GameBiz.hk4e_global) { byte[]? uidBytes = Registry.GetValue(key, GameRegistry.__LastUid___h2153286551, 0) as byte[]; if (uidBytes is not null) @@ -140,7 +141,7 @@ public void SaveGameAccount(GameAccount account) public void DeleteGameAccount(GameAccount account) { using var dapper = _database.CreateConnection(); - dapper.Execute("DELETE FROM GameAccount WHERE SHA256=@SHA256;", account); + dapper.Execute("DELETE FROM GameAccount WHERE GameBiz=@GameBiz AND SHA256=@SHA256;", account); _logger.LogInformation("Delete account {name} ({biz}) successfully!", account.Name, account.GameBiz); } @@ -150,27 +151,30 @@ public void DeleteGameAccount(GameAccount account) public void ChangeGameAccount(GameAccount account) { var key = account.GameBiz.GetGameRegistryKey(); - var keyName = (int)account.GameBiz switch + var biz = account.GameBiz; + var keyName = (biz.IsChinaOfficial(), biz.IsGlobalOfficial(), biz.IsBilibili(), biz.IsChinaCloud()) switch { - 11 or 21 or 31 or 14 or 24 or 41 or 44 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, - 13 => GameRegistry.MIHOYOSDK_ADL_0, - 12 or 22 or (>= 32 and <= 36) or 42 => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, - _ => throw new ArgumentOutOfRangeException($"Unknown region {account.GameBiz}"), + (true, false, false, false) => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + (false, false, true, false) => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + (false, false, false, true) => GameRegistry.MIHOYOSDK_ADL_0, + (false, true, false, false) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, + _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; + Registry.SetValue(key, keyName, account.Value); - if (account.GameBiz.ToGame() is GameBiz.StarRail) + if (account.GameBiz.ToGame() == GameBiz.hkrpg) { Registry.SetValue(key, GameRegistry.App_LastUserID_h2841727341, (int)account.Uid, RegistryValueKind.DWord); } - if (account.GameBiz.ToGame() is GameBiz.Honkai3rd) + if (account.GameBiz.ToGame() == GameBiz.bh3) { Registry.SetValue(key, GameRegistry.GENERAL_DATA_V2_LastLoginUserId_h47158221, (int)account.Uid, RegistryValueKind.DWord); } - if (account.GameBiz.ToGame() is GameBiz.GenshinImpact) + if (account.GameBiz.ToGame() == GameBiz.hk4e) { Registry.SetValue(key, GameRegistry.__LastUid___h2153286551, Encoding.UTF8.GetBytes($"{account.Uid}\0")); } - _logger.LogInformation("Change account {name} ({biz}) successfully!", account.Name, account.GameBiz); + _logger.LogInformation("Change account {name} ({biz}) successfully!", account.Name, (object)account.GameBiz); } diff --git a/src/Starward/Services/GameResourceService.cs b/src/Starward/Services/GameResourceService.cs index de4441259..175707d64 100644 --- a/src/Starward/Services/GameResourceService.cs +++ b/src/Starward/Services/GameResourceService.cs @@ -93,16 +93,16 @@ public bool IsGameExeExists(GameBiz biz) public static string GetGameExeName(GameBiz biz) { - return biz switch + return biz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => "YuanShen.exe", GameBiz.hk4e_global => "GenshinImpact.exe", - GameBiz.hk4e_cloud => "Genshin Impact Cloud Game.exe", - _ => biz.ToGame() switch + GameBiz.clgm_cn => "Genshin Impact Cloud Game.exe", + _ => biz.ToGame().Value switch { - GameBiz.StarRail => "StarRail.exe", - GameBiz.Honkai3rd => "BH3.exe", - GameBiz.ZZZ => "ZenlessZoneZero.exe", + GameBiz.hkrpg => "StarRail.exe", + GameBiz.bh3 => "BH3.exe", + GameBiz.nap => "ZenlessZoneZero.exe", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }, }; @@ -139,7 +139,7 @@ public GameBiz GetLocalGameBiz(GameBiz biz, string? installPath = null) { return GameBiz.None; } - if (biz is GameBiz.nap_cn) + if (biz == GameBiz.nap_cn) { return GameBiz.nap_cn; } @@ -148,7 +148,7 @@ public GameBiz GetLocalGameBiz(GameBiz biz, string? installPath = null) if (File.Exists(config)) { var str = File.ReadAllText(config); - Enum.TryParse(Regex.Match(str, @"game_biz=(.+)").Groups[1].Value, out gameBiz); + gameBiz = Regex.Match(str, @"game_biz=(.+)").Groups[1].Value; } else { @@ -174,7 +174,7 @@ public async Task GetGameResourceAsync(GameBiz biz) public async Task<(Version? LatestVersion, Version? PreDownloadVersion)> GetGameResourceVersionAsync(GameBiz biz) { - if (biz is GameBiz.nap_cn) + if (biz == GameBiz.nap_cn) { const string url = "https://hyp-api.mihoyo.com/hyp/hyp-connect/api/getGamePackages?game_ids%5B%5D=ol93169Cmh&launcher_id=PFKmM45gSW"; var str = await _httpClient.GetStringAsync(url); @@ -377,7 +377,7 @@ public async Task GetVoiceLanguageAsync(GameBiz biz, string? inst { return VoiceLanguage.None; } - var file = biz switch + var file = biz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => Path.Join(installPath, @"YuanShen_Data\Persistent\audio_lang_14"), GameBiz.hk4e_global => Path.Join(installPath, @"GenshinImpact_Data\Persistent\audio_lang_14"), @@ -386,7 +386,7 @@ public async Task GetVoiceLanguageAsync(GameBiz biz, string? inst }; if (!File.Exists(file)) { - file = biz switch + file = biz.Value switch { GameBiz.hk4e_global => Path.Join(installPath, @"YuanShen_Data\Persistent\audio_lang_14"), GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => Path.Join(installPath, @"GenshinImpact_Data\Persistent\audio_lang_14"), @@ -410,9 +410,9 @@ public async Task GetVoiceLanguageAsync(GameBiz biz, string? inst public async Task SetVoiceLanguageAsync(GameBiz biz, string installPath, VoiceLanguage lang) { - if (biz is GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hkrpg_cn or GameBiz.hkrpg_global) + if (biz.Value is GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hkrpg_cn or GameBiz.hkrpg_global) { - var file = biz switch + var file = biz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => Path.Join(installPath, @"YuanShen_Data\Persistent\audio_lang_14"), GameBiz.hk4e_global => Path.Join(installPath, @"GenshinImpact_Data\Persistent\audio_lang_14"), diff --git a/src/Starward/Services/GameService.cs b/src/Starward/Services/GameService.cs index 002d9f259..9c98b905c 100644 --- a/src/Starward/Services/GameService.cs +++ b/src/Starward/Services/GameService.cs @@ -35,7 +35,7 @@ public GameService(ILogger logger, GameLauncherService gameLauncher public string? GetGameScreenshotPath(GameBiz biz) { string? folder = null; - if (biz is GameBiz.hk4e_cloud) + if (biz == GameBiz.clgm_cn) { var config = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"GenshinImpactCloudGame\config\config.ini"); if (File.Exists(config)) @@ -48,12 +48,12 @@ public GameService(ILogger logger, GameLauncherService gameLauncher else { folder = _gameLauncherService.GetGameInstallPath(biz); - var relativePath = biz.ToGame() switch + var relativePath = biz.ToGame().Value switch { - GameBiz.GenshinImpact => "ScreenShot", - GameBiz.StarRail => @"StarRail_Data\ScreenShots", - GameBiz.Honkai3rd => @"ScreenShot", - GameBiz.ZZZ => @"ScreenShot", + GameBiz.hk4e => "ScreenShot", + GameBiz.hkrpg => @"StarRail_Data\ScreenShots", + GameBiz.bh3 => @"ScreenShot", + GameBiz.nap => @"ScreenShot", _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; folder = Path.Join(folder, relativePath); @@ -129,7 +129,7 @@ public GameService(ILogger logger, GameLauncherService gameLauncher var name = GameResourceService.GetGameExeName(biz); exe = Path.Join(folder, name); arg = AppConfig.GetStartArgument(biz)?.Trim(); - verb = (biz is GameBiz.hk4e_cloud) ? "" : "runas"; + verb = (biz == GameBiz.clgm_cn) ? "" : "runas"; if (!File.Exists(exe)) { _logger.LogWarning("Game exe not found: {path}", exe); @@ -176,12 +176,12 @@ public int UninstallGame(GameBiz gameBiz, string? loc, UninstallStep steps) if (steps.HasFlag(UninstallStep.BackupScreenshot) && Directory.Exists(AppConfig.UserDataFolder)) { _logger.LogInformation("Start to backup screenshot"); - string relativePath = gameBiz.ToGame() switch + string relativePath = gameBiz.ToGame().Value switch { - GameBiz.GenshinImpact => "ScreenShot", - GameBiz.StarRail => @"StarRail_Data\ScreenShots", - GameBiz.Honkai3rd => @"ScreenShot", - GameBiz.ZZZ => @"ScreenShot", + GameBiz.hk4e => "ScreenShot", + GameBiz.hkrpg => @"StarRail_Data\ScreenShots", + GameBiz.bh3 => @"ScreenShot", + GameBiz.nap => @"ScreenShot", _ => throw new ArgumentOutOfRangeException($"Unknown region {gameBiz}"), }; string folder = Path.Join(loc, relativePath); diff --git a/src/Starward/Services/GameSettingService.cs b/src/Starward/Services/GameSettingService.cs index 1bd9ee835..c2b01511a 100644 --- a/src/Starward/Services/GameSettingService.cs +++ b/src/Starward/Services/GameSettingService.cs @@ -51,12 +51,12 @@ public GameSettingService(ILogger logger) public GraphicsSettings_PCResolution_h431323223? GetGameResolutionSetting(GameBiz biz) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.Honkai3rd or GameBiz.StarRail) + if (biz.ToGame().Value is GameBiz.bh3 or GameBiz.hkrpg) { - var keyName = biz.ToGame() switch + var keyName = biz.ToGame().Value switch { - GameBiz.Honkai3rd => GENERAL_DATA_V2_ScreenSettingData_h1916288658, - GameBiz.StarRail => GraphicsSettings_PCResolution_h431323223, + GameBiz.bh3 => GENERAL_DATA_V2_ScreenSettingData_h1916288658, + GameBiz.hkrpg => GraphicsSettings_PCResolution_h431323223, _ => "" }; var data = Registry.GetValue(keyPath, keyName, null) as byte[]; @@ -66,7 +66,7 @@ public GameSettingService(ILogger logger) return JsonSerializer.Deserialize(str); } } - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { var fullScreen = (int)(Registry.GetValue(keyPath, Screenmanager_Is_Fullscreen_mode_h3981298716, 0) ?? 0) != 0; var width = (int)(Registry.GetValue(keyPath, Screenmanager_Resolution_Width_h182942802, 0) ?? 0); @@ -76,7 +76,7 @@ public GameSettingService(ILogger logger) return new GraphicsSettings_PCResolution_h431323223 { Width = width, Height = height, IsFullScreen = fullScreen }; } } - if (biz.ToGame() is GameBiz.ZZZ) + if (biz.ToGame() == GameBiz.nap) { var fullScreen = (int)(Registry.GetValue(keyPath, Screenmanager_Fullscreen_mode_h3630240806, 0) ?? 0) != 3; var width = (int)(Registry.GetValue(keyPath, Screenmanager_Resolution_Width_h182942802, 0) ?? 0); @@ -95,7 +95,7 @@ public GameSettingService(ILogger logger) public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_h431323223 model) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.Honkai3rd) + if (biz.ToGame() == GameBiz.bh3) { var str = JsonSerializer.Serialize(model) + "\0"; Registry.SetValue(keyPath, GENERAL_DATA_V2_ScreenSettingData_h1916288658, Encoding.UTF8.GetBytes(str)); @@ -103,7 +103,7 @@ public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_ Registry.SetValue(keyPath, Screenmanager_Resolution_Width_h182942802, model.Width); Registry.SetValue(keyPath, Screenmanager_Resolution_Height_h2627697771, model.Height); } - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var str = JsonSerializer.Serialize(model) + "\0"; Registry.SetValue(keyPath, GraphicsSettings_PCResolution_h431323223, Encoding.UTF8.GetBytes(str)); @@ -111,13 +111,13 @@ public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_ Registry.SetValue(keyPath, Screenmanager_Resolution_Width_h182942802, model.Width); Registry.SetValue(keyPath, Screenmanager_Resolution_Height_h2627697771, model.Height); } - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { Registry.SetValue(keyPath, Screenmanager_Is_Fullscreen_mode_h3981298716, model.IsFullScreen ? 1 : 0); Registry.SetValue(keyPath, Screenmanager_Resolution_Width_h182942802, model.Width); Registry.SetValue(keyPath, Screenmanager_Resolution_Height_h2627697771, model.Height); } - if (biz.ToGame() is GameBiz.ZZZ) + if (biz.ToGame() == GameBiz.nap) { Registry.SetValue(keyPath, Screenmanager_Fullscreen_mode_h3630240806, model.IsFullScreen ? 1 : 3); Registry.SetValue(keyPath, Screenmanager_Resolution_Width_h182942802, model.Width); @@ -131,7 +131,7 @@ public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_ public int? GetGameVoiceLanguageSetting(GameBiz biz) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { var data = Registry.GetValue(keyPath, GENERAL_DATA_h2389025596, null) as byte[]; if (data is not null) @@ -142,7 +142,7 @@ public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_ return value >= 0 ? value : null; } } - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var data = Registry.GetValue(keyPath, LanguageSettings_LocalAudioLanguage_h882585060, null) as byte[]; if (data is not null) @@ -166,7 +166,7 @@ public void SetGameResolutionSetting(GameBiz biz, GraphicsSettings_PCResolution_ public void SetGameVoiceLanguageSetting(GameBiz biz, int lang) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.GenshinImpact) + if (biz.ToGame() == GameBiz.hk4e) { var data = Registry.GetValue(keyPath, GENERAL_DATA_h2389025596, null) as byte[]; JsonNode? node = null; @@ -189,7 +189,7 @@ public void SetGameVoiceLanguageSetting(GameBiz biz, int lang) Registry.SetValue(keyPath, GENERAL_DATA_h2389025596, Encoding.UTF8.GetBytes($"{{\"deviceVoiceLanguageType\": {lang}}}\0")); } } - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var str = lang switch { @@ -211,7 +211,7 @@ public void SetGameVoiceLanguageSetting(GameBiz biz, int lang) public int? GetGraphicsQualitySetting(GameBiz biz) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var value = (int)(Registry.GetValue(keyPath, GraphicsSettings_GraphicsQuality_h523255858, 0) ?? -1); return value >= 0 ? value : null; @@ -224,7 +224,7 @@ public void SetGameVoiceLanguageSetting(GameBiz biz, int lang) public void SetGraphicsQualitySetting(GameBiz biz, int value) { - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var keyPath = biz.GetGameRegistryKey(); Registry.SetValue(keyPath, GraphicsSettings_GraphicsQuality_h523255858, value); @@ -236,7 +236,7 @@ public void SetGraphicsQualitySetting(GameBiz biz, int value) public GraphicsSettings_Model_h2986158309? GetGraphicsSettingModel(GameBiz biz) { var keyPath = biz.GetGameRegistryKey(); - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var data = Registry.GetValue(keyPath, GraphicsSettings_Model_h2986158309, null) as byte[]; if (data is not null) @@ -253,7 +253,7 @@ public void SetGraphicsQualitySetting(GameBiz biz, int value) public void SetGraphicsSettingModel(GameBiz biz, GraphicsSettings_Model_h2986158309? model) { - if (biz.ToGame() is GameBiz.StarRail) + if (biz.ToGame() == GameBiz.hkrpg) { var keyPath = biz.GetGameRegistryKey(); var str = JsonSerializer.Serialize(model) + "\0"; diff --git a/src/Starward/Services/HoYoPlayService.cs b/src/Starward/Services/HoYoPlayService.cs index 04c122cf5..c6b2380ac 100644 --- a/src/Starward/Services/HoYoPlayService.cs +++ b/src/Starward/Services/HoYoPlayService.cs @@ -98,27 +98,27 @@ private async Task PrepareDataForServerAsync(string launcherId, string? language List infos = await _client.GetGameInfoAsync(launcherId, language); foreach (GameInfo item in infos) { - _gameInfo[item.ToGameBiz()] = item; + _gameInfo[item.GameBiz] = item; } List backgrounds = await _client.GetGameBackgroundAsync(launcherId, language); foreach (GameBackgroundInfo item in backgrounds) { - _gameBackground[item.GameId.ToGameBiz()] = item; + _gameBackground[item.GameId.GameBiz] = item; } foreach (var item in infos) { GameContent content = await _client.GetGameContentAsync(launcherId, language, item); - _gameContent[content.GameId.ToGameBiz()] = content; + _gameContent[content.GameId.GameBiz] = content; } List packages = await _client.GetGamePackageAsync(launcherId, language); foreach (GamePackage item in packages) { - _gamePackage[item.GameId.ToGameBiz()] = item; + _gamePackage[item.GameId.GameBiz] = item; } List configs = await _client.GetGameConfigAsync(launcherId, language); foreach (GameConfig item in configs) { - _gameConfig[item.GameId.ToGameBiz()] = item; + _gameConfig[item.GameId.GameBiz] = item; } } catch (Exception ex) @@ -221,7 +221,7 @@ private static List GetSelectedGameBizs() List bizs = new(); foreach (string str in AppConfig.SelectedGameBizs?.Split(',') ?? []) { - if (Enum.TryParse(str, out GameBiz biz) && biz.ToGame() is not GameBiz.None) + if (GameBiz.TryParse(str, out GameBiz biz)) { bizs.Add(biz); } @@ -237,7 +237,7 @@ public async Task GetGameInfoAsync(GameBiz biz) if (!_gameInfo.TryGetValue(biz, out GameInfo? info)) { string lang = CultureInfo.CurrentUICulture.Name; - if (biz.IsBilibiliServer()) + if (biz.IsBilibili()) { var list = await _client.GetGameInfoAsync(LauncherId.FromGameBiz(biz)!, lang); info = list.First(); @@ -248,9 +248,9 @@ public async Task GetGameInfoAsync(GameBiz biz) var list = await _client.GetGameInfoAsync(LauncherId.FromGameBiz(biz)!, lang); foreach (var item in list) { - _gameInfo[item.ToGameBiz()] = item; + _gameInfo[item.GameBiz] = item; } - info = list.First(x => x.Biz == biz.ToString()); + info = list.First(x => x.GameBiz == biz.ToString()); } } return info; @@ -263,7 +263,7 @@ public async Task GetGameBackgroundAsync(GameBiz biz) if (!_gameBackground.TryGetValue(biz, out GameBackgroundInfo? background)) { string lang = CultureInfo.CurrentUICulture.Name; - if (biz.IsBilibiliServer()) + if (biz.IsBilibili()) { var list = await _client.GetGameBackgroundAsync(LauncherId.FromGameBiz(biz)!, lang); background = list.First(); @@ -274,9 +274,9 @@ public async Task GetGameBackgroundAsync(GameBiz biz) var list = await _client.GetGameBackgroundAsync(LauncherId.FromGameBiz(biz)!, lang); foreach (var item in list) { - _gameBackground[item.GameId.ToGameBiz()] = item; + _gameBackground[item.GameId.GameBiz] = item; } - background = list.First(x => x.GameId.ToGameBiz() == biz); + background = list.First(x => x.GameId.GameBiz == biz); } } return background; @@ -289,7 +289,7 @@ public async Task GetGameContentAsync(GameBiz biz) if (!_gameContent.TryGetValue(biz, out GameContent? content)) { string lang = CultureInfo.CurrentUICulture.Name; - if (biz.IsBilibiliServer()) + if (biz.IsBilibili()) { content = await _client.GetGameContentAsync(LauncherId.FromGameBiz(biz)!, lang, GameId.FromGameBiz(biz)!); _gameContent[biz] = content; @@ -310,7 +310,7 @@ public async Task GetGamePackageAsync(GameBiz biz) if (!_gamePackage.TryGetValue(biz, out GamePackage? package)) { string lang = CultureInfo.CurrentUICulture.Name; - if (biz.IsBilibiliServer()) + if (biz.IsBilibili()) { var list = await _client.GetGamePackageAsync(LauncherId.FromGameBiz(biz)!, lang); package = list.First(); @@ -321,9 +321,9 @@ public async Task GetGamePackageAsync(GameBiz biz) var list = await _client.GetGamePackageAsync(LauncherId.FromGameBiz(biz)!, lang); foreach (var item in list) { - _gamePackage[item.GameId.ToGameBiz()] = item; + _gamePackage[item.GameId.GameBiz] = item; } - package = list.First(x => x.GameId.ToGameBiz() == biz); + package = list.First(x => x.GameId.GameBiz == biz); } } return package; @@ -333,14 +333,14 @@ public async Task GetGamePackageAsync(GameBiz biz) public async Task GetGameConfigAsync(GameBiz biz) { - if (biz.ToGame() is GameBiz.Honkai3rd && biz.IsGlobalOfficial()) + if (biz.ToGame() == GameBiz.bh3 && biz.IsGlobalOfficial()) { return null; } if (!_gameConfig.TryGetValue(biz, out GameConfig? config)) { string lang = CultureInfo.CurrentUICulture.Name; - if (biz.IsBilibiliServer()) + if (biz.IsBilibili()) { var list = await _client.GetGameConfigAsync(LauncherId.FromGameBiz(biz)!, lang); config = list.First(); @@ -351,9 +351,9 @@ public async Task GetGamePackageAsync(GameBiz biz) var list = await _client.GetGameConfigAsync(LauncherId.FromGameBiz(biz)!, lang); foreach (var item in list) { - _gameConfig[item.GameId.ToGameBiz()] = item; + _gameConfig[item.GameId.GameBiz] = item; } - config = list.FirstOrDefault(x => x.GameId.ToGameBiz() == biz); + config = list.FirstOrDefault(x => x.GameId.GameBiz == biz); } } return config; @@ -363,7 +363,7 @@ public async Task GetGamePackageAsync(GameBiz biz) public async Task> GetGameDeprecatedFilesAsync(GameBiz biz) { - if (biz.ToGame() is GameBiz.Honkai3rd && biz.IsGlobalOfficial()) + if (biz.ToGame() == GameBiz.bh3 && biz.IsGlobalOfficial()) { biz = GameBiz.bh3_global; } @@ -384,7 +384,7 @@ public async Task> GetGameDeprecatedFilesAsync(GameBiz public async Task GetGameChannelSDKAsync(GameBiz biz) { - if (biz.ToGame() is GameBiz.Honkai3rd && biz.IsGlobalOfficial()) + if (biz.ToGame() == GameBiz.bh3 && biz.IsGlobalOfficial()) { biz = GameBiz.bh3_global; } diff --git a/src/Starward/Services/InstallGame/GenshinInstallGameService.cs b/src/Starward/Services/InstallGame/GenshinInstallGameService.cs index b96ec8b9f..bb78ba901 100644 --- a/src/Starward/Services/InstallGame/GenshinInstallGameService.cs +++ b/src/Starward/Services/InstallGame/GenshinInstallGameService.cs @@ -16,7 +16,7 @@ internal class GenshinInstallGameService : InstallGameService { - public override GameBiz CurrentGame => GameBiz.GenshinImpact; + public override GameBiz CurrentGame => GameBiz.hk4e; public GenshinInstallGameService(ILogger logger, GameLauncherService gameLauncherService, GamePackageService gamePackageService, HoYoPlayClient hoyoPlayClient, HttpClient httpClient) @@ -56,7 +56,7 @@ protected override async Task PrepareForRepairAsync() string? exe_os = Path.Join(InstallPath, "GenshinImpact.exe"); string? data_cn = Path.Join(InstallPath, "YuanShen_Data"); string? data_os = Path.Join(InstallPath, "GenshinImpact_Data"); - if (CurrentGameBiz is GameBiz.hk4e_cn) + if (CurrentGameBiz == GameBiz.hk4e_cn) { if (File.Exists(exe_os)) { @@ -67,7 +67,7 @@ protected override async Task PrepareForRepairAsync() Directory.Move(data_os, data_cn); } } - if (CurrentGameBiz is GameBiz.hk4e_global) + if (CurrentGameBiz == GameBiz.hk4e_global) { if (File.Exists(exe_cn)) { @@ -90,9 +90,9 @@ protected override async Task PrepareForRepairAsync() /// protected async Task MoveAudioAssetsFromPersistentToStreamAssetsAsync() { - await Task.Run(() => + await Task.Run((Action)(() => { - string dataName = CurrentGameBiz switch + string dataName = CurrentGameBiz.Value switch { GameBiz.hk4e_cn => "YuanShen_Data", GameBiz.hk4e_global => "GenshinImpact_Data", @@ -123,7 +123,7 @@ await Task.Run(() => } } } - }).ConfigureAwait(false); + })).ConfigureAwait(false); } @@ -133,7 +133,7 @@ protected override async Task VerifySeparateFilesAsync(CancellationToken cancell await base.VerifySeparateFilesAsync(cancellationToken).ConfigureAwait(false); // 清理不在资源列表中的文件 - string assetsFolder = CurrentGameBiz switch + string assetsFolder = CurrentGameBiz.Value switch { GameBiz.hk4e_cn => Path.Combine(InstallPath, @"YuanShen_Data\StreamingAssets"), GameBiz.hk4e_global => Path.Combine(InstallPath, @"GenshinImpact_Data\StreamingAssets"), diff --git a/src/Starward/Services/InstallGame/Honkai3rdInstallGameService.cs b/src/Starward/Services/InstallGame/Honkai3rdInstallGameService.cs index 01bd621a5..e0a1d7edf 100644 --- a/src/Starward/Services/InstallGame/Honkai3rdInstallGameService.cs +++ b/src/Starward/Services/InstallGame/Honkai3rdInstallGameService.cs @@ -14,7 +14,7 @@ namespace Starward.Services.InstallGame; internal class Honkai3rdInstallGameService : InstallGameService { - public override GameBiz CurrentGame => GameBiz.Honkai3rd; + public override GameBiz CurrentGame => GameBiz.bh3; public Honkai3rdInstallGameService(ILogger logger, GameLauncherService gameLauncherService, GamePackageService gamePackageService, HoYoPlayClient hoyoPlayClient, HttpClient httpClient) diff --git a/src/Starward/Services/InstallGame/InstallGameService.cs b/src/Starward/Services/InstallGame/InstallGameService.cs index b6e5ba8dc..2c1573bb4 100644 --- a/src/Starward/Services/InstallGame/InstallGameService.cs +++ b/src/Starward/Services/InstallGame/InstallGameService.cs @@ -461,7 +461,7 @@ await Parallel.ForEachAsync(separateResources, cancellationToken, async (item, t /// protected async Task PrepareBilibiliServerGameSDKAsync() { - if (!IsPreInstall && CurrentGameBiz.IsBilibiliServer()) + if (!IsPreInstall && CurrentGameBiz.IsBilibili()) { if (gameChannelSDK is null) { @@ -492,7 +492,7 @@ protected async Task PrepareBilibiliServerGameSDKAsync() /// protected void DecompressBilibiliServerGameSDK() { - if (!IsPreInstall && CurrentGameBiz.IsBilibiliServer()) + if (!IsPreInstall && CurrentGameBiz.IsBilibili()) { if (gameChannelSDK is not null) { @@ -750,17 +750,17 @@ protected async Task WriteConfigFileAsync() string version = gamePackage.Main.Major?.Version ?? ""; string sdk_version = gameChannelSDK?.Version ?? ""; string cps = "", channel = "1", sub_channel = "1"; - if (CurrentGameBiz.IsBilibiliServer()) + if (CurrentGameBiz.IsBilibili()) { cps = "bilibili"; channel = "14"; sub_channel = "0"; } - else if (CurrentGameBiz.IsChinaServer()) + else if (CurrentGameBiz.IsChinaOfficial()) { cps = "mihoyo"; } - else if (CurrentGameBiz.IsGlobalServer()) + else if (CurrentGameBiz.IsGlobalOfficial()) { cps = "hoyoverse"; } diff --git a/src/Starward/Services/InstallGame/StarRailInstallGameService.cs b/src/Starward/Services/InstallGame/StarRailInstallGameService.cs index 6429534b8..23919ac1c 100644 --- a/src/Starward/Services/InstallGame/StarRailInstallGameService.cs +++ b/src/Starward/Services/InstallGame/StarRailInstallGameService.cs @@ -15,7 +15,7 @@ internal class StarRailInstallGameService : InstallGameService { - public override GameBiz CurrentGame => GameBiz.StarRail; + public override GameBiz CurrentGame => GameBiz.hkrpg; public StarRailInstallGameService(ILogger logger, GameLauncherService gameLauncherService, GamePackageService gamePackageService, HoYoPlayClient hoyoPlayClient, HttpClient httpClient) diff --git a/src/Starward/Services/InstallGame/ZZZInstallGameService.cs b/src/Starward/Services/InstallGame/ZZZInstallGameService.cs index c8d27c6ec..7ad22a307 100644 --- a/src/Starward/Services/InstallGame/ZZZInstallGameService.cs +++ b/src/Starward/Services/InstallGame/ZZZInstallGameService.cs @@ -10,7 +10,7 @@ internal class ZZZInstallGameService : InstallGameService { - public override GameBiz CurrentGame => GameBiz.ZZZ; + public override GameBiz CurrentGame => GameBiz.nap; public ZZZInstallGameService(ILogger logger, GameLauncherService gameLauncherService, GamePackageService gamePackageService, HoYoPlayClient hoyoPlayClient, HttpClient httpClient) diff --git a/src/Starward/Services/Launcher/GameLauncherService.cs b/src/Starward/Services/Launcher/GameLauncherService.cs index e365704c4..d22c2e4b6 100644 --- a/src/Starward/Services/Launcher/GameLauncherService.cs +++ b/src/Starward/Services/Launcher/GameLauncherService.cs @@ -107,7 +107,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService } else if (gameBiz.IsGlobalOfficial()) { - if (gameBiz.ToGame() is GameBiz.Honkai3rd) + if (gameBiz.ToGame() == GameBiz.bh3) { return GachaLogClient.GetGameInstallPathFromRegistry(gameBiz); } @@ -139,7 +139,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService /// public async Task GetLatestGameVersionAsync(GameBiz gameBiz) { - if (gameBiz.IsGlobalOfficial() && gameBiz.ToGame() is GameBiz.Honkai3rd) + if (gameBiz.IsGlobalOfficial() && gameBiz.ToGame() == GameBiz.bh3) { var resource = await _launcherClient.GetLauncherGameResourceAsync(gameBiz); return TryParseVersion(resource.Game.Latest.Version); @@ -164,7 +164,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService public async Task GetLocalGameVersionAsync(GameBiz gameBiz, string? installPath = null) { installPath ??= GetGameInstallPath(gameBiz); - if (gameBiz is GameBiz.hk4e_cloud) + if (gameBiz == GameBiz.clgm_cn) { var exe = Path.Join(installPath, GetGameExeName(gameBiz)); if (File.Exists(exe)) @@ -205,7 +205,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService public async Task<(GameBiz, string?)> GetHardLinkInfoAsync(GameBiz gameBiz, string? installPath = null) { installPath ??= GetGameInstallPath(gameBiz); - if (gameBiz is GameBiz.hk4e_cloud) + if (gameBiz == GameBiz.clgm_cn) { return (GameBiz.None, null); } @@ -219,7 +219,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService if (File.Exists(config)) { var str = await File.ReadAllTextAsync(config); - Enum.TryParse(Regex.Match(str, @"hardlink_gamebiz=(.+)").Groups[1].Value, out GameBiz biz); + GameBiz biz = Regex.Match(str, @"hardlink_gamebiz=(.+)").Groups[1].Value; var path = Regex.Match(str, @"hardlink_path=(.+)").Groups[1].Value; return (biz, path); } @@ -239,7 +239,7 @@ public GameLauncherService(ILogger logger, HoYoPlayService /// public async Task GetPreDownloadGameVersionAsync(GameBiz gameBiz) { - if (gameBiz.IsGlobalOfficial() && gameBiz.ToGame() is GameBiz.Honkai3rd) + if (gameBiz.IsGlobalOfficial() && gameBiz.ToGame() == GameBiz.bh3) { var resource = await _launcherClient.GetLauncherGameResourceAsync(gameBiz); return TryParseVersion(resource.PreDownloadGame?.Latest.Version); @@ -278,16 +278,16 @@ public GameLauncherService(ILogger logger, HoYoPlayService /// public string GetGameExeName(GameBiz gameBiz) { - return gameBiz switch + return gameBiz.Value switch { GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => "YuanShen.exe", GameBiz.hk4e_global => "GenshinImpact.exe", - GameBiz.hk4e_cloud => "Genshin Impact Cloud Game.exe", - _ => gameBiz.ToGame() switch + GameBiz.clgm_cn => "Genshin Impact Cloud Game.exe", + _ => gameBiz.ToGame().Value switch { - GameBiz.StarRail => "StarRail.exe", - GameBiz.Honkai3rd => "BH3.exe", - GameBiz.ZZZ => "ZenlessZoneZero.exe", + GameBiz.hkrpg => "StarRail.exe", + GameBiz.bh3 => "BH3.exe", + GameBiz.nap => "ZenlessZoneZero.exe", _ => throw new ArgumentOutOfRangeException($"Unknown region {gameBiz}"), }, }; @@ -372,7 +372,7 @@ public bool IsGameExeExists(GameBiz biz, string? installPath = null) var name = GetGameExeName(biz); exe = Path.Join(folder, name); arg = AppConfig.GetStartArgument(biz)?.Trim(); - verb = (biz is GameBiz.hk4e_cloud) ? "" : "runas"; + verb = (biz == GameBiz.clgm_cn) ? "" : "runas"; if (!File.Exists(exe)) { _logger.LogWarning("Game exe not found: {path}", exe); diff --git a/src/Starward/Services/Launcher/GamePackageService.cs b/src/Starward/Services/Launcher/GamePackageService.cs index c41d51e6e..1a573d0d4 100644 --- a/src/Starward/Services/Launcher/GamePackageService.cs +++ b/src/Starward/Services/Launcher/GamePackageService.cs @@ -39,7 +39,7 @@ public GamePackageService(ILogger logger, LauncherClient lau public async Task GetGamePackageAsync(GameBiz biz) { - if (biz.ToGame() is GameBiz.Honkai3rd && biz.IsGlobalOfficial()) + if (biz.ToGame() == GameBiz.bh3 && biz.IsGlobalOfficial()) { var res = await _launcherClient.GetLauncherGameResourceAsync(biz); var package = new GamePackage @@ -214,7 +214,7 @@ private static long GetFileDownloadedLength(string file) public async Task GetVoiceLanguageAsync(GameBiz biz, string? installPath = null) { - if (biz.ToGame() is GameBiz.Honkai3rd) + if (biz.ToGame() == GameBiz.bh3) { return VoiceLanguage.None; } @@ -245,7 +245,7 @@ public async Task GetVoiceLanguageAsync(GameBiz biz, string? inst public async Task SetVoiceLanguageAsync(GameBiz biz, string installPath, VoiceLanguage lang) { - if (biz.ToGame() is GameBiz.Honkai3rd) + if (biz.ToGame() == GameBiz.bh3) { return; } diff --git a/src/Starward/Services/Launcher/LauncherBackgroundService.cs b/src/Starward/Services/Launcher/LauncherBackgroundService.cs index 79cef6221..ef0c7b43a 100644 --- a/src/Starward/Services/Launcher/LauncherBackgroundService.cs +++ b/src/Starward/Services/Launcher/LauncherBackgroundService.cs @@ -87,12 +87,12 @@ public LauncherBackgroundService(ILogger logger, HoYo public async Task GetBackgroundImageUrlAsync(GameBiz gameBiz, CancellationToken cancellationToken = default) { string? url; - if (gameBiz.ToGame() is GameBiz.Honkai3rd && gameBiz.IsGlobalServer()) + if (gameBiz.ToGame() == GameBiz.bh3 && gameBiz.IsGlobalOfficial()) { var content = await GetLauncherContentAsync(gameBiz, cancellationToken); url = content.BackgroundImage?.Background; } - else if (gameBiz is GameBiz.hk4e_cloud) + else if (gameBiz == GameBiz.clgm_cn) { var background = await _hoYoPlayService.GetGameInfoAsync(GameBiz.hk4e_cn); url = background.Display.Background.Url; diff --git a/src/Starward/Services/LauncherContentService.cs b/src/Starward/Services/LauncherContentService.cs index 7f3fa3cd1..dd1789bed 100644 --- a/src/Starward/Services/LauncherContentService.cs +++ b/src/Starward/Services/LauncherContentService.cs @@ -115,12 +115,12 @@ public async Task IsNoticesAlertAsync(GameBiz gameBiz, long uid, Cancellat } string? url; - if (gameBiz.ToGame() is GameBiz.Honkai3rd && gameBiz.IsGlobalServer()) + if (gameBiz.ToGame() == GameBiz.bh3 && gameBiz.IsGlobalOfficial()) { var content = await GetLauncherContentAsync(gameBiz, tokenSource.Token); url = content.BackgroundImage?.Background; } - else if (gameBiz is GameBiz.hk4e_cloud) + else if (gameBiz == GameBiz.clgm_cn) { var background = await _hoYoPlayService.GetGameInfoAsync(GameBiz.hk4e_cn); url = background.Display.Background.Url; @@ -165,11 +165,11 @@ public async Task IsNoticesAlertAsync(GameBiz gameBiz, long uid, Cancellat else { string baseFolder = AppContext.BaseDirectory; - string? path = gameBiz.ToGame() switch + string? path = gameBiz.ToGame().Value switch { - GameBiz.Honkai3rd => Path.Combine(baseFolder, @"Assets\Image\poster_honkai.png"), - GameBiz.GenshinImpact => Path.Combine(baseFolder, @"Assets\Image\poster_genshin.png"), - GameBiz.StarRail => Path.Combine(baseFolder, @"Assets\Image\poster_starrail.png"), + GameBiz.bh3 => Path.Combine(baseFolder, @"Assets\Image\poster_honkai.png"), + GameBiz.hk4e => Path.Combine(baseFolder, @"Assets\Image\poster_genshin.png"), + GameBiz.hkrpg => Path.Combine(baseFolder, @"Assets\Image\poster_starrail.png"), _ => null, }; if (File.Exists(path)) diff --git a/src/Starward/Services/PlayTimeService.cs b/src/Starward/Services/PlayTimeService.cs index 7b91c9129..f5de5964d 100644 --- a/src/Starward/Services/PlayTimeService.cs +++ b/src/Starward/Services/PlayTimeService.cs @@ -295,7 +295,7 @@ private static TimeSpan ComputePlayTime(List items, DateTime } foreach (var process in processes) { - if (biz.ToGame() is GameBiz.Honkai3rd && process.MainWindowHandle == 0) + if (biz.ToGame() == GameBiz.bh3 && process.MainWindowHandle == 0) { _logger.LogInformation("Game process ({biz}, {gamePid}) has no window", biz, process.Id); continue; diff --git a/src/Starward/Services/UrlProtocolService.cs b/src/Starward/Services/UrlProtocolService.cs index f90f91154..284946150 100644 --- a/src/Starward/Services/UrlProtocolService.cs +++ b/src/Starward/Services/UrlProtocolService.cs @@ -64,7 +64,7 @@ public static async Task HandleUrlProtocolAsync(string url) } if (uri.Host is "startgame") { - if (Enum.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz)) + if (GameBiz.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz)) { var kvs = HttpUtility.ParseQueryString(uri.Query); string? uidStr = kvs["uid"]; @@ -102,7 +102,7 @@ public static async Task HandleUrlProtocolAsync(string url) } if (uri.Host is "playtime") { - if (Enum.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz)) + if (GameBiz.TryParse(uri.AbsolutePath.Trim('/'), out GameBiz biz)) { var kvs = HttpUtility.ParseQueryString(uri.Query); await AppConfig.GetService().StartProcessToLogAsync(biz);