From 736c26f0fdab6502f3ae47e005b2c90732392e3f Mon Sep 17 00:00:00 2001 From: Scighost Date: Wed, 25 Sep 2024 23:17:09 +0800 Subject: [PATCH] fix the error where audio packages doesn't download in some language environment #1103 --- src/Starward.Core/LanguageUtil.cs | 21 +++++++++++++++++++ .../Download/GenshinInstallGameService.cs | 2 +- .../Services/Download/InstallGameService.cs | 2 +- .../Download/ZZZInstallGameService.cs | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Starward.Core/LanguageUtil.cs b/src/Starward.Core/LanguageUtil.cs index 332fee72b..defd71e3e 100644 --- a/src/Starward.Core/LanguageUtil.cs +++ b/src/Starward.Core/LanguageUtil.cs @@ -35,4 +35,25 @@ public static string FilterLanguage(string? lang) } + public static string FilterAudioLanguage(string? lang) + { + // zh-cn,zh-tw,en-us,de-de,es-es,fr-fr,id-id,it-it,ja-jp,ko-kr,pt-pt,ru-ru,th-th,tr-tr,vi-vn + var low = lang?.ToLower() ?? ""; + if (low.Length < 2) + { + low = ".."; + } + return low switch + { + _ => low[..2] switch + { + "zh" => "zh-cn", + "ja" => "ja-jp", + "ko" => "ko-kr", + _ => "en-us", + } + }; + } + + } diff --git a/src/Starward/Services/Download/GenshinInstallGameService.cs b/src/Starward/Services/Download/GenshinInstallGameService.cs index aa70de7ca..ecb890cc0 100644 --- a/src/Starward/Services/Download/GenshinInstallGameService.cs +++ b/src/Starward/Services/Download/GenshinInstallGameService.cs @@ -151,7 +151,7 @@ private async Task> GetAudioPkgVersionsAsync(string prefix string lang = await GetAudioLanguageAsync(); if (string.IsNullOrWhiteSpace(lang)) { - lang = LanguageUtil.FilterLanguage(CultureInfo.CurrentUICulture.Name); + lang = LanguageUtil.FilterAudioLanguage(CultureInfo.CurrentUICulture.Name); await SetAudioLanguageAsync(lang); } List list = []; diff --git a/src/Starward/Services/Download/InstallGameService.cs b/src/Starward/Services/Download/InstallGameService.cs index 8a8bd84a3..ff8b37eee 100644 --- a/src/Starward/Services/Download/InstallGameService.cs +++ b/src/Starward/Services/Download/InstallGameService.cs @@ -442,7 +442,7 @@ protected async Task> GetAudioPackageFilesFromGameResource string lang = await GetAudioLanguageAsync(); if (string.IsNullOrWhiteSpace(lang)) { - lang = LanguageUtil.FilterLanguage(CultureInfo.CurrentUICulture.Name); + lang = LanguageUtil.FilterAudioLanguage(CultureInfo.CurrentUICulture.Name); await SetAudioLanguageAsync(lang); } List list = []; diff --git a/src/Starward/Services/Download/ZZZInstallGameService.cs b/src/Starward/Services/Download/ZZZInstallGameService.cs index 134b6cd72..d779a7b19 100644 --- a/src/Starward/Services/Download/ZZZInstallGameService.cs +++ b/src/Starward/Services/Download/ZZZInstallGameService.cs @@ -126,7 +126,7 @@ private async Task> GetAudioPkgVersionsAsync(string prefix string lang = await GetAudioLanguageAsync(); if (string.IsNullOrWhiteSpace(lang)) { - lang = LanguageUtil.FilterLanguage(CultureInfo.CurrentUICulture.Name); + lang = LanguageUtil.FilterAudioLanguage(CultureInfo.CurrentUICulture.Name); await SetAudioLanguageAsync(lang); } List list = [];