From 8e5e92d876b7607c0a308fa0c59a37d836bf112a Mon Sep 17 00:00:00 2001 From: Kemal Setya Adhi Date: Thu, 29 Aug 2024 23:54:38 +0700 Subject: [PATCH] Enforce ``IsUsePreallocatedDownloader`` on ``InstallManagerBase`` --- .../BaseClass/InstallManagerBase.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs b/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs index 45e3e7c9e..454803b08 100644 --- a/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs +++ b/CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs @@ -3507,9 +3507,6 @@ private async ValueTask InvokePackageDownloadRoutine(DownloadClient do // Subscribe the download progress to the event adapter _httpClient.DownloadProgress += HttpClientDownloadProgressAdapter; - // Create a speed limiter instance for the new DownloadClient and register it - DownloadSpeedLimiter speedLimiter = DownloadSpeedLimiter.CreateInstance(LauncherConfig.DownloadSpeedLimitCached); - LauncherConfig.DownloadSpeedLimitChanged += speedLimiter.GetListener(); try { // Iterate the package list @@ -3521,7 +3518,7 @@ private async ValueTask InvokePackageDownloadRoutine(DownloadClient do // Iterate the segment list for (int i = 0; i < package.Segments.Count; i++) { - await RunPackageDownloadRoutine(_httpClient, downloadClient, speedLimiter, package.Segments[i], token, packageCount); + await RunPackageDownloadRoutine(_httpClient, downloadClient, package.Segments[i], token, packageCount); } // Skip action below and continue to the next segment @@ -3529,22 +3526,18 @@ private async ValueTask InvokePackageDownloadRoutine(DownloadClient do } // Else, run the routine as normal - await RunPackageDownloadRoutine(_httpClient, downloadClient, speedLimiter, package, token, packageCount); + await RunPackageDownloadRoutine(_httpClient, downloadClient, package, token, packageCount); } } finally { // Unsubscribe the download progress from the event adapter _httpClient.DownloadProgress -= HttpClientDownloadProgressAdapter; - - // Unregister the speed limiter - LauncherConfig.DownloadSpeedLimitChanged -= speedLimiter.GetListener(); } } private async ValueTask RunPackageDownloadRoutine(Http httpClient, DownloadClient downloadClient, - DownloadSpeedLimiter downloadSpeedLimiter, GameInstallPackage package, CancellationToken token, int packageCount) @@ -3712,7 +3705,9 @@ private async ValueTask GetExistingDownloadPackageSize(DownloadClient down packageList[i].Segments[j].Size, token ); - bool isUseLegacySegmentedSize = segmentDownloaded > newSegmentedDownloaded || newSegmentedDownloaded > packageList[i].Segments[j].Size; + bool isUseLegacySegmentedSize = !LauncherConfig.IsUsePreallocatedDownloader + || segmentDownloaded > newSegmentedDownloaded + || newSegmentedDownloaded > packageList[i].Segments[j].Size; totalSize += isUseLegacySegmentedSize ? segmentDownloaded : newSegmentedDownloaded; totalSegmentDownloaded += isUseLegacySegmentedSize ? segmentDownloaded : newSegmentedDownloaded; packageList[i].Segments[j].SizeDownloaded = isUseLegacySegmentedSize ? segmentDownloaded : newSegmentedDownloaded; @@ -3732,7 +3727,9 @@ private async ValueTask GetExistingDownloadPackageSize(DownloadClient down packageList[i].Size, token ); - bool isUseLegacySize = legacyDownloadedSize > newDownloaderSize || newDownloaderSize > packageList[i].Size; + bool isUseLegacySize = !LauncherConfig.IsUsePreallocatedDownloader + || legacyDownloadedSize > newDownloaderSize + || newDownloaderSize > packageList[i].Size; packageList[i].IsUseLegacyDownloader = isUseLegacySize; packageList[i].SizeDownloaded = isUseLegacySize ? legacyDownloadedSize : newDownloaderSize; totalSize += packageList[i].SizeDownloaded;