diff --git a/src/Starward.Core/Gacha/GachaLogClient.cs b/src/Starward.Core/Gacha/GachaLogClient.cs index bcd048560..9b24c17ab 100644 --- a/src/Starward.Core/Gacha/GachaLogClient.cs +++ b/src/Starward.Core/Gacha/GachaLogClient.cs @@ -32,8 +32,8 @@ public abstract class GachaLogClient protected const string WEB_CACHE_SR_PATH = @"StarRail_Data\webCaches\Cache\Cache_Data\data_2"; - protected const string API_PREFIX_SR_CN = "https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog"; - protected const string API_PREFIX_SR_OS = "https://api-os-takumi.mihoyo.com/common/gacha_record/api/getGachaLog"; + protected const string API_PREFIX_SR_CN = "https://public-operation-hkrpg.mihoyo.com/common/gacha_record/api/getGachaLog"; + protected const string API_PREFIX_SR_OS = "https://public-operation-hkrpg-sg.hoyoverse.com/common/gacha_record/api/getGachaLog"; protected static ReadOnlySpan SPAN_WEB_PREFIX_SR_CN => "https://webstatic.mihoyo.com/hkrpg/event/e20211215gacha-v2/index.html"u8; protected static ReadOnlySpan SPAN_WEB_PREFIX_SR_OS => "https://gs.hoyoverse.com/hkrpg/event/e20211215gacha-v2/index.html"u8; diff --git a/src/Starward.Core/Gacha/Genshin/GenshinGachaClient.cs b/src/Starward.Core/Gacha/Genshin/GenshinGachaClient.cs index 4d9d61185..0ba18768d 100644 --- a/src/Starward.Core/Gacha/Genshin/GenshinGachaClient.cs +++ b/src/Starward.Core/Gacha/Genshin/GenshinGachaClient.cs @@ -44,7 +44,7 @@ protected override string GetGachaUrlPrefix(string gachaUrl, string? lang = null } return gachaUrl; } - match = Regex.Match(gachaUrl, @"(https://hk4e-api[!-z]+)"); + match = Regex.Match(gachaUrl, @"(https://public-operation-hk4e[!-z]+)"); if (match.Success) { gachaUrl = match.Groups[1].Value; diff --git a/src/Starward.Core/Gacha/StarRail/StarRailGachaClient.cs b/src/Starward.Core/Gacha/StarRail/StarRailGachaClient.cs index 60771c2ed..45240d9bb 100644 --- a/src/Starward.Core/Gacha/StarRail/StarRailGachaClient.cs +++ b/src/Starward.Core/Gacha/StarRail/StarRailGachaClient.cs @@ -46,7 +46,7 @@ protected override string GetGachaUrlPrefix(string gachaUrl, string? lang = null } return gachaUrl; } - match = Regex.Match(gachaUrl, @"(https://api[!-z]+)"); + match = Regex.Match(gachaUrl, @"(https://public-operation-hkrpg[!-z]+)"); if (match.Success) { gachaUrl = match.Groups[1].Value; diff --git a/src/Starward/Services/Download/InstallGameManager.cs b/src/Starward/Services/Download/InstallGameManager.cs index beec78791..4d44574a3 100644 --- a/src/Starward/Services/Download/InstallGameManager.cs +++ b/src/Starward/Services/Download/InstallGameManager.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.Mvvm.Messaging; using Starward.Core; using Starward.Helpers; using Starward.Messages; @@ -23,7 +23,6 @@ private InstallGameManager() _services = new(); int speed = AppConfig.SpeedLimitKBPerSecond * 1024; SpeedLimitBytesPerSecond = speed == 0 ? int.MaxValue : speed; - GlobalRateLimiter = GetRateLimiter(SpeedLimitBytesPerSecond); } @@ -35,7 +34,7 @@ private InstallGameManager() public static int SpeedLimitBytesPerSecond { get; set; } - public static TokenBucketRateLimiter GlobalRateLimiter; + public static TokenBucketRateLimiter GlobalRateLimiter = GetRateLimiter(SpeedLimitBytesPerSecond); public static bool IsEnableSpeedLimit => SpeedLimitBytesPerSecond != int.MaxValue; diff --git a/src/Starward/Services/Download/InstallGameService.cs b/src/Starward/Services/Download/InstallGameService.cs index 4225632b2..e5f4307fd 100644 --- a/src/Starward/Services/Download/InstallGameService.cs +++ b/src/Starward/Services/Download/InstallGameService.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Starward.Core; using Starward.Core.HoYoPlay; using Starward.Services.InstallGame; @@ -21,6 +21,7 @@ using System.Text; using System.Text.Json.Nodes; using System.Threading; +using System.Threading.RateLimiting; using System.Threading.Tasks; using Vanara.PInvoke; @@ -245,7 +246,7 @@ await Task.Run(() => { File.SetAttributes(file, FileAttributes.Normal); } - }); + }).ConfigureAwait(false); CurrentGameBiz = gameBiz; _installPath = installPath; _initialized = true; @@ -984,7 +985,7 @@ protected async Task CleanGameDeprecatedFilesAsync() { File.Delete(file); } - foreach (var file in await _hoYoPlayService.GetGameDeprecatedFilesAsync(CurrentGameBiz)) + foreach (var file in await _hoYoPlayService.GetGameDeprecatedFilesAsync(CurrentGameBiz).ConfigureAwait(false)) { var path = Path.Combine(_installPath, file.Name); if (File.Exists(path)) @@ -992,7 +993,7 @@ protected async Task CleanGameDeprecatedFilesAsync() File.Delete(path); } } - await WriteConfigFileAsync(); + await WriteConfigFileAsync().ConfigureAwait(false); CurrentTaskFinished(); } @@ -1129,19 +1130,19 @@ protected async Task ExecuteTaskItemAsync(CancellationToken cancellationToken = case InstallGameItemType.None: break; case InstallGameItemType.Download: - await DownloadItemAsync(item, cancellationToken); + await DownloadItemAsync(item, cancellationToken).ConfigureAwait(false); Interlocked.Increment(ref _finishCount); break; case InstallGameItemType.Verify: - await VerifyItemAsync(item, cancellationToken); + await VerifyItemAsync(item, cancellationToken).ConfigureAwait(false); Interlocked.Increment(ref _finishCount); break; case InstallGameItemType.Decompress: - await DecompressItemAsync(item, cancellationToken); + await DecompressItemAsync(item, cancellationToken).ConfigureAwait(false); Interlocked.Increment(ref _finishCount); break; case InstallGameItemType.HardLink: - await HardLinkItemAsync(item, cancellationToken); + await HardLinkItemAsync(item, cancellationToken).ConfigureAwait(false); Interlocked.Increment(ref _finishCount); break; default: @@ -1152,7 +1153,7 @@ protected async Task ExecuteTaskItemAsync(CancellationToken cancellationToken = { // network error _installItemQueue.Enqueue(item); - await Task.Delay(1000, CancellationToken.None); + await Task.Delay(1000, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) when (ex is OperationCanceledException or TaskCanceledException) { @@ -1182,7 +1183,7 @@ protected async Task ExecuteTaskItemAsync(CancellationToken cancellationToken = protected async Task DownloadItemAsync(InstallGameItem item, CancellationToken cancellationToken = default) { - const int BUFFER_SIZE = 1 << 14; + const int BUFFER_SIZE = 1 << 10; string file = item.Path; string file_tmp = item.Path + "_tmp"; string file_target; @@ -1277,7 +1278,7 @@ protected async Task VerifyItemAsync(InstallGameItem item, CancellationToken can var buffer = ArrayPool.Shared.Rent(BUFFER_SIZE); try { - await _verifyGlobalSemaphore.WaitAsync(cancellationToken); + await _verifyGlobalSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); using var fs = File.OpenRead(file_target); if (fs.Length != item.Size) { @@ -1324,7 +1325,7 @@ protected async Task DecompressItemAsync(InstallGameItem item, CancellationToken { try { - await _decompressSemaphore.WaitAsync(); + await _decompressSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); using var fs = new FileSliceStream(item.DecompressPackageFiles); if (item.DecompressPackageFiles[0].Contains(".7z", StringComparison.CurrentCultureIgnoreCase)) { @@ -1341,7 +1342,7 @@ await Task.Run(() => }; extra.Extract(item.DecompressPath, true); _finishBytes += fs.Length - sum; - }).ConfigureAwait(false); + }, cancellationToken).ConfigureAwait(false); } else { @@ -1366,8 +1367,8 @@ await Task.Run(async () => } } _finishBytes += fs.Length - sum; - await ApplyDiffFilesAsync(item.DecompressPath); - }).ConfigureAwait(false); + await ApplyDiffFilesAsync(item.DecompressPath).ConfigureAwait(false); + }, cancellationToken).ConfigureAwait(false); } fs.Dispose(); foreach (var file in item.DecompressPackageFiles) @@ -1471,7 +1472,7 @@ protected async Task HardLinkItemAsync(InstallGameItem item, CancellationToken c var buffer = ArrayPool.Shared.Rent(BUFFER_SIZE); try { - await _verifyGlobalSemaphore.WaitAsync(cancellationToken); + await _verifyGlobalSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); using var fs = File.OpenRead(file_source); if (fs.Length != item.Size) {