Skip to content

Commit

Permalink
optimize update service
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 29, 2024
1 parent c3fb7bb commit b3ad6ca
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Starward/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,15 @@ private async Task DownloadFileAsync(ReleaseFile releaseFile, CancellationToken
readLength += length;
Interlocked.Add(ref progress_BytesDownloaded, length);
}
ms.Position = 0;
string hash = Convert.ToHexString(SHA256.HashData(ms));
if (hash != releaseFile.Hash)
{
_logger.LogWarning("Checksum failed, path: {path}, actual hash: {hash}, true hash: {truehash}", releaseFile.Path, hash, releaseFile.Hash);
throw new Exception($"Checksum failed: {releaseFile.Path}");
}
await File.WriteAllBytesAsync(file, ms.ToArray(), cancellationToken);
Interlocked.Increment(ref progress_FileCountDownloaded);

}
using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
string hash = Convert.ToHexString(await SHA256.HashDataAsync(fs, cancellationToken));
if (!string.Equals(hash, releaseFile.Hash, StringComparison.OrdinalIgnoreCase))
{
_logger.LogWarning("Checksum failed, path: {path}, actual hash: {hash}, true hash: {truehash}", releaseFile.Path, hash, releaseFile.Hash);
throw new Exception($"Checksum failed: {releaseFile.Path}");
}
break;
}
Expand Down

0 comments on commit b3ad6ca

Please sign in to comment.