Skip to content

Commit

Permalink
Enforce IsUsePreallocatedDownloader on InstallManagerBase
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Aug 29, 2024
1 parent 053e1ea commit 8e5e92d
Showing 1 changed file with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -3521,30 +3518,26 @@ 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
continue;
}

// 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)
Expand Down Expand Up @@ -3712,7 +3705,9 @@ private async ValueTask<long> 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;
Expand All @@ -3732,7 +3727,9 @@ private async ValueTask<long> 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;
Expand Down

0 comments on commit 8e5e92d

Please sign in to comment.