diff --git a/src/ImeSense.Launchers.Belarus.Core/Services/DownloadResourcesService.cs b/src/ImeSense.Launchers.Belarus.Core/Services/DownloadResourcesService.cs index fc72702..27bb9da 100644 --- a/src/ImeSense.Launchers.Belarus.Core/Services/DownloadResourcesService.cs +++ b/src/ImeSense.Launchers.Belarus.Core/Services/DownloadResourcesService.cs @@ -101,17 +101,22 @@ public async Task DownloadAsync(string path, Uri url, IProgress progress, _hashResources ??= await _gitStorageApiService .DownloadJsonAsync>(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);