Skip to content

Commit

Permalink
fix: Close file-handle after checking checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Sep 29, 2024
1 parent 9fabd4c commit 394d5a2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions CelesteTAS-EverestInterop/Source/EverestInterop/StudioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,14 @@ private static async Task DownloadStudio() {
bool skipDownload = false;

if (File.Exists(DownloadPath)) {
await using var fs = File.OpenRead(DownloadPath);
await using (var fs = File.OpenRead(DownloadPath)) {
string hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
if (Checksum.Equals(hash, StringComparison.OrdinalIgnoreCase)) {
skipDownload = true;
}
}

string hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
if (Checksum.Equals(hash, StringComparison.OrdinalIgnoreCase)) {
skipDownload = true;
} else {
if (!skipDownload) {
// Try handling double ZIPs caused by GitHub actions
if (DoubleZipArchive) {
string innerPath;
Expand All @@ -205,7 +207,8 @@ private static async Task DownloadStudio() {
File.Move(innerPath, DownloadPath, overwrite: true);
}

hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
await using var fs = File.OpenRead(DownloadPath);
string hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
if (Checksum.Equals(hash, StringComparison.OrdinalIgnoreCase)) {
skipDownload = true;
}
Expand Down

0 comments on commit 394d5a2

Please sign in to comment.