Skip to content

Commit

Permalink
Fix downloading game updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Drombeys committed Jan 13, 2024
1 parent bc4782a commit ad33463
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,22 @@ public async Task DownloadAsync(string path, Uri url, IProgress<int> progress,
_hashResources ??= await _gitStorageApiService
.DownloadJsonAsync<IList<GameResource>>(FileNamesStorage.HashResources, UriStorage.BelarusApiUri);

bool verifyFile;
var verifyFile = false;
do {
await _fileDownloadManager.DownloadAsync(url, path, progress, tokenSource.Token);
// Check the downloaded file for integrity
var assetName = Path.GetFileName(path);
var gameResource = _hashResources?.FirstOrDefault(x => x.Title.Equals(assetName,
StringComparison.OrdinalIgnoreCase));
verifyFile = await _hashChecker.VerifyFileHashAsync(path, gameResource!.Hash);
if (!verifyFile) {
try {
await _fileDownloadManager.DownloadAsync(url, path, progress, tokenSource.Token);
// Check the downloaded file for integrity
var assetName = Path.GetFileName(path);
var gameResource = _hashResources?.FirstOrDefault(x => x.Title.Equals(assetName,
StringComparison.OrdinalIgnoreCase));
verifyFile = await _hashChecker.VerifyFileHashAsync(path, gameResource!.Hash);
if (!verifyFile) {
File.Delete(path);
}
} catch (HttpRequestException ex) when (ex.Message.Contains("416")) {
_logger.LogInformation("Unsuccessful attempt to download the file! The file will be deleted and downloaded again");
File.Delete(path);
}
}
} while (!verifyFile);

progress.Report(0);
Expand Down

0 comments on commit ad33463

Please sign in to comment.