Skip to content

Commit

Permalink
Notify about HermesProxy GitHub errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu committed Nov 13, 2023
1 parent 519185b commit 2dc1de0
Showing 1 changed file with 83 additions and 63 deletions.
146 changes: 83 additions & 63 deletions WinterspringLauncher/LauncherLogic.StartGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,69 +215,7 @@ public void StartGame()
_model.SetProgressbar("Checking HermesProxy status", 50, overallProgressColor);
await Task.Delay(TimeSpan.FromSeconds(0.5));
string? localHermesVersion = null;
var hermesProxyVersionFile = Path.Combine(_config.HermesProxyLocation, "version.txt");
if (File.Exists(hermesProxyVersionFile))
{
localHermesVersion = File.ReadLines(hermesProxyVersionFile).First();
}
if (localHermesVersion == null || _config.CheckForHermesUpdates)
{
GitHubReleaseInfo releaseInfo = GitHubApi.LatestReleaseVersion("WowLegacyCore/HermesProxy");
var versionString = $"{releaseInfo.TagName}|{releaseInfo.Name}";
if (localHermesVersion != versionString)
{
var osName = weAreOnMacOs ? "mac" : "win";
var possibleDownloads = releaseInfo.Assets!.FindAll(a => a.Name.Contains(osName, StringComparison.CurrentCultureIgnoreCase));
if (possibleDownloads.Count != 1)
throw new Exception($"Found {possibleDownloads.Count} HermesProxy versions for your OS");
var targetDir = new DirectoryInfo(FullPath(_config.HermesProxyLocation)).FullName;
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);
var downloadDestLocation = targetDir + ".partial-download";
_model.SetProgressbar("Downloading HermesProxy", 0, Brush.Parse("#1976d2"));
var downloadUrl = possibleDownloads[0].DownloadUrl;
_model.AddLogEntry($"Download URL: {downloadUrl}");
_model.AddLogEntry($"Download Location: {downloadDestLocation}");
RunDownload(downloadUrl, downloadDestLocation);
var directories = Directory.GetDirectories(targetDir);
foreach (string directory in directories)
{
if (!directory.Contains("AccountData")) // we want to keep our AccountData
Directory.Delete(directory, recursive: true);
}
Directory.CreateDirectory(targetDir);
_model.SetProgressbar("Unpack HermesProxy", 0, Brush.Parse("#d84315"));
RunUnpack(downloadDestLocation, targetDir);
#if !DEBUG
try
{
File.Delete(downloadDestLocation);
}
catch(Exception e)
{
_model.AddLogEntry($"Failed to delete tmp file '{downloadDestLocation}'");
await Task.Delay(TimeSpan.FromSeconds(5));
}
#endif
File.WriteAllLines(hermesProxyVersionFile, new string[]
{
versionString,
$"Source: {downloadUrl}"
});
_model.SetHermesVersion(releaseInfo.TagName);
}
}
await UpdateHermesProxyIfNecessary();
var modernBuild = ushort.Parse(gameInstallation.Version.Split(".").Last());
Expand Down Expand Up @@ -331,4 +269,86 @@ public void StartGame()
}
});
}

private async Task UpdateHermesProxyIfNecessary()
{
string? localHermesVersion = null;
var hermesProxyVersionFile = Path.Combine(_config.HermesProxyLocation, "version.txt");
if (File.Exists(hermesProxyVersionFile))
{
localHermesVersion = File.ReadLines(hermesProxyVersionFile).First();
}

if (localHermesVersion == null || _config.CheckForHermesUpdates)
{
GitHubReleaseInfo? releaseInfo;
try
{
releaseInfo = GitHubApi.LatestReleaseVersion("WowLegacyCore/HermesProxy");
}
catch (Exception e) when (localHermesVersion != null)
{
_model.AddLogEntry("Error: Failed to check HermesProxy version!");
Console.WriteLine("Exception while checking GitHub status of HermesProxy");
Console.WriteLine(e);
await Task.Delay(TimeSpan.FromSeconds(5));
return;
}

bool weAreOnMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);

var versionString = $"{releaseInfo.TagName}|{releaseInfo.Name}";
if (localHermesVersion != versionString)
{
var osName = weAreOnMacOs ? "mac" : "win";
var possibleDownloads = releaseInfo.Assets!.FindAll(a => a.Name.Contains(osName, StringComparison.CurrentCultureIgnoreCase));
if (possibleDownloads.Count != 1)
throw new Exception($"Found {possibleDownloads.Count} HermesProxy versions for your OS");

var targetDir = new DirectoryInfo(FullPath(_config.HermesProxyLocation)).FullName;
if (!Directory.Exists(targetDir))
Directory.CreateDirectory(targetDir);

var downloadDestLocation = targetDir + ".partial-download";

_model.SetProgressbar("Downloading HermesProxy", 0, Brush.Parse("#1976d2"));
var downloadUrl = possibleDownloads[0].DownloadUrl;
_model.AddLogEntry($"Download URL: {downloadUrl}");
_model.AddLogEntry($"Download Location: {downloadDestLocation}");
RunDownload(downloadUrl, downloadDestLocation);

var directories = Directory.GetDirectories(targetDir);
foreach (string directory in directories)
{
if (!directory.Contains("AccountData")) // we want to keep our AccountData
Directory.Delete(directory, recursive: true);
}

Directory.CreateDirectory(targetDir);

_model.SetProgressbar("Unpack HermesProxy", 0, Brush.Parse("#d84315"));
RunUnpack(downloadDestLocation, targetDir);

#if !DEBUG
try
{
File.Delete(downloadDestLocation);
}
catch(Exception e)

Check warning on line 337 in WinterspringLauncher/LauncherLogic.StartGame.cs

View workflow job for this annotation

GitHub Actions / build_windows (windows)

The variable 'e' is declared but never used
{
_model.AddLogEntry($"Failed to delete tmp file '{downloadDestLocation}'");
await Task.Delay(TimeSpan.FromSeconds(5));
}
#endif

File.WriteAllLines(hermesProxyVersionFile, new string[]
{
versionString,
$"Source: {downloadUrl}"
});

_model.SetHermesVersion(releaseInfo.TagName);
}
}
}
}

0 comments on commit 2dc1de0

Please sign in to comment.