Skip to content

Commit

Permalink
fix: Studio-installation with nested archive from GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Jan 3, 2025
1 parent fb74560 commit 92f693c
Showing 1 changed file with 15 additions and 36 deletions.
51 changes: 15 additions & 36 deletions CelesteTAS-EverestInterop/Source/EverestInterop/StudioHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class StudioHelper {
private static string TempStudioInstallDirectory => Path.Combine(StudioDirectory, ".temp_install");
private static string VersionFile => Path.Combine(StudioDirectory, ".version");
private static string DownloadPath => Path.Combine(StudioDirectory, FileName);
private static string InnerArchivePath => Path.Combine(StudioDirectory, ".InnerArchive.zip");

private static string DownloadURL {
get {
Expand Down Expand Up @@ -228,42 +229,17 @@ private static async Task DownloadStudio() {
bool skipDownload = false;

if (File.Exists(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;
} else {
$"Checksum for {FileName} doesn't match. Expected {Checksum}, found {hash}".Log(LogLevel.Verbose);
}
}

if (!skipDownload) {
// Try handling double ZIPs caused by GitHub actions
if (DoubleZipArchive) {
string innerPath;
using (var zip = ZipFile.OpenRead(DownloadPath)) {
var entry = zip.Entries[0]; // There should only be a single entry in this case
innerPath = Path.Combine(StudioDirectory, entry.Name);
$"Extracting inner ZIP archive: '{entry.Name}'".Log(LogLevel.Verbose);

entry.ExtractToFile(innerPath);
}

File.Move(innerPath, DownloadPath, overwrite: true);
}

await using var fs = File.OpenRead(DownloadPath);
string hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
if (Checksum.Equals(hash, StringComparison.OrdinalIgnoreCase)) {
skipDownload = true;
} else {
$"Checksum for inner archive of {FileName} doesn't match. Expected {Checksum}, found {hash}".Log(LogLevel.Verbose);
}
await using var fs = File.OpenRead(DownloadPath);
string hash = BitConverter.ToString(await md5.ComputeHashAsync(fs)).Replace("-", "");
if (Checksum.Equals(hash, StringComparison.OrdinalIgnoreCase)) {
skipDownload = true;
} else {
$"Checksum for {FileName} doesn't match. Expected {Checksum}, found {hash}".Log(LogLevel.Verbose);
}
}

if (!skipDownload) {
// Existing archive doesn't match at all
// Existing archive doesn't match
if (File.Exists(DownloadPath)) {
File.Delete(DownloadPath);
}
Expand Down Expand Up @@ -295,16 +271,18 @@ private static async Task DownloadStudio() {

// Handle double ZIPs caused by GitHub actions
if (DoubleZipArchive) {
string innerPath;
if (File.Exists(InnerArchivePath)) {
File.Delete(InnerArchivePath);
}

using (var zip = ZipFile.OpenRead(DownloadPath)) {
var entry = zip.Entries[0]; // There should only be a single entry in this case
innerPath = Path.Combine(StudioDirectory, entry.Name);
$"Extracting inner ZIP archive: '{entry.Name}'".Log(LogLevel.Verbose);

entry.ExtractToFile(innerPath);
entry.ExtractToFile(InnerArchivePath);
}

File.Move(innerPath, DownloadPath, overwrite: true);
File.Move(InnerArchivePath, DownloadPath, overwrite: true);
}
}

Expand Down Expand Up @@ -474,6 +452,7 @@ internal static void LaunchStudio() => Task.Run(async () => {

private static void ReportError(string error, string? additionalInfo = null) {
error.Log(LogLevel.Error);
additionalInfo?.Log(LogLevel.Error);

if (!Directory.Exists(StudioDirectory)) {
Directory.CreateDirectory(StudioDirectory);
Expand Down

0 comments on commit 92f693c

Please sign in to comment.