Skip to content

Commit

Permalink
Warn on possibly corrupt Olympus installations
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Jan 11, 2021
1 parent 54e26ab commit 3e29368
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions launcher-winforms/OlympusForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,34 @@ public void Invoke(Action a) {
public void RunDownloader() {
Console.WriteLine("Downloader thread running");

Thread.Sleep(2000);
if (Directory.Exists(Program.InstallDir) && Directory.GetFiles(Program.InstallDir).Length != 0) {
Invoke(() => {
MessageBox.Show(
@"
A previous version of Olympus was already downloaded.
Sadly, some important files went missing or are corrupted.
The Olympus downloader will now try to redownload them.
If Olympus is still crashing or if this happens often:
please ping the Everest team on the Celeste Discord server.
".Trim().Replace("\r\n", "\n"),
"Olympus Downloader",
MessageBoxButtons.OK
);
});
}

Console.WriteLine($"Wiping {Program.InstallDir}");
try {
Directory.Delete(Program.InstallDir, true);
} catch (Exception e) {
Console.WriteLine(e);
}
try {
Directory.CreateDirectory(Program.InstallDir);
} catch (Exception e) {
Console.WriteLine(e);
}

const string artifactFormat = "https://dev.azure.com/EverestAPI/Olympus/_apis/build/builds/{0}/artifacts?artifactName=windows.main&$format=zip";
const string index = "https://dev.azure.com/EverestAPI/Olympus/_apis/build/builds";
Expand All @@ -55,6 +82,7 @@ public void RunDownloader() {
using (JsonTextReader jsonReader = new JsonTextReader(reader))
root = (JObject) JToken.ReadFrom(jsonReader);

string urlWindowsInit = null;
string urlStable = null;
string urlMain = null;

Expand All @@ -69,6 +97,8 @@ public void RunDownloader() {

int id = build.Value<int>("id");
string branch = build.Value<string>("sourceBranch").Replace("refs/heads/", "");
if (string.IsNullOrEmpty(urlWindowsInit) && branch == "windows-init")
urlWindowsInit = string.Format(artifactFormat, id);
if (string.IsNullOrEmpty(urlStable) && branch == "stable")
urlStable = string.Format(artifactFormat, id);
if (string.IsNullOrEmpty(urlMain) && (branch == "main" || branch == "dev"))
Expand All @@ -78,7 +108,7 @@ public void RunDownloader() {
break;
}

string url = !string.IsNullOrEmpty(urlStable) ? urlStable : urlMain;
string url = !string.IsNullOrEmpty(urlWindowsInit) ? urlWindowsInit : !string.IsNullOrEmpty(urlStable) ? urlStable : urlMain;
if (string.IsNullOrEmpty(url))
throw new Exception("Couldn't find valid latest build entry.");

Expand All @@ -96,13 +126,6 @@ public void RunDownloader() {
Console.WriteLine("Opening dist .zip");
using (Stream stream = wrapper.GetEntry("windows.main/dist.zip").Open())
using (ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Read)) {
Console.WriteLine($"Wiping {Program.InstallDir}");
try {
Directory.Delete(Program.InstallDir);
Directory.CreateDirectory(Program.InstallDir);
} catch (Exception e) {
Console.WriteLine(e);
}
Console.WriteLine($"Extracting to {Program.InstallDir}");
zip.ExtractToDirectory(Program.InstallDir);
}
Expand Down

0 comments on commit 3e29368

Please sign in to comment.