Skip to content

Commit

Permalink
Fix CDN and download related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
0blu committed Nov 9, 2023
1 parent 7ff3228 commit 11b4b15
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 20 deletions.
5 changes: 1 addition & 4 deletions WinterspringLauncher/LauncherActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ public static void PrepareGameConfigWtf(string gamePath, string portalAddress)
List<string> configContent;
if (!File.Exists(configWtfPath))
{
// TODO Take the language from this launcher
configContent = new List<string>();
string bestDefaultTextLocale = CultureInfo.CurrentCulture.Name.StartsWith("zh", StringComparison.InvariantCultureIgnoreCase)
? "zhCN"
: "enUS";
string bestDefaultTextLocale = LocaleDefaults.GetBestWoWConfigLocale();
configContent.Add($"SET textLocale {bestDefaultTextLocale}");
}
else
Expand Down
49 changes: 44 additions & 5 deletions WinterspringLauncher/LauncherConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using WinterspringLauncher.Utils;

namespace WinterspringLauncher;

Expand Down Expand Up @@ -75,8 +77,8 @@ public class LauncherConfig : VersionedBaseConfig
ClientPatchInfoURL = "https://wow-patches.blu.wtf/patches/1.14.2.42597_summary.json",
CustomBuildInfoURL = "https://asia.cdn.everlook.org/everlook_asia_1.14.2_prod/.build.info",
BaseClientDownloadURL = new Dictionary<OperatingSystem, string>() {
[OperatingSystem.Windows] = "https://download.wowdl.net/downloadFiles/Clients/WoW%20Classic%201.14.2.42597%20All%20Languages.rar",
[OperatingSystem.MacOs] = "https://download.wowdl.net/downloadFiles/Clients/WoW_Classic_1.14.2.42597_macOS.zip",
[OperatingSystem.Windows] = "http://asia.cdn.everlook.aclon.cn/game-client-patch-cdn/wow_classic_1_14_2_42597_all_languages.rar",
[OperatingSystem.MacOs] = "http://asia.cdn.everlook.aclon.cn/game-client-patch-cdn/wow_classic_1_14_2_42597_all_languages_macos.rar",
},
},
["Default 1.14.2 installation"] = new InstallationLocation
Expand Down Expand Up @@ -173,16 +175,16 @@ private static string PatchConfigIfNeeded(string currentConfig)
{
var knownServer = v2Config.KnownServers.First(g => g.RealmlistAddress.Contains("everlook-wow", StringComparison.InvariantCultureIgnoreCase));
var knownInstallation = v2Config.GameInstallations.First(g => g.Key == knownServer.UsedInstallation);
knownInstallation.Value.Directory = v1Config.GamePath;
v2Config.LastSelectedServerName = knownServer.Name;
v2Config.GitHubMirror = "https://asia.cdn.everlook-wow.net/github-mirror/api/";
v2Config.LastSelectedServerName = knownServer.Name;
TryUpgradeOldGameFolder(knownInstallation.Value.Directory, v1Config.GamePath);
}
else if (v1Config.Realmlist.Contains("everlook.org", StringComparison.InvariantCultureIgnoreCase))
{
var knownServer = v2Config.KnownServers.First(g => g.RealmlistAddress.Contains("everlook.org", StringComparison.InvariantCultureIgnoreCase));
var knownInstallation = v2Config.GameInstallations.First(g => g.Key == knownServer.UsedInstallation);
knownInstallation.Value.Directory = v1Config.GamePath;
v2Config.LastSelectedServerName = knownServer.Name;
TryUpgradeOldGameFolder(oldGameFolder: v1Config.GamePath, newGameFolder: knownInstallation.Value.Directory);
}

return JsonSerializer.Serialize(v2Config);
Expand All @@ -192,6 +194,43 @@ private static string PatchConfigIfNeeded(string currentConfig)
return currentConfig;
}

private static void TryUpgradeOldGameFolder(string oldGameFolder, string newGameFolder)
{
try
{
bool weAreOnMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
if (!weAreOnMacOs)
{
string known_1_14_2_client_hash = "43F407C7915602D195812620D68C3E5AE10F20740549D2D63A0B04658C02A123";

var gameExecutablePath = Path.Combine(oldGameFolder, "_classic_era_", "WoWClassic.exe");

if (File.Exists(gameExecutablePath) && HashHelper.CreateHexSha256HashFromFilename(gameExecutablePath) == known_1_14_2_client_hash)
{
// We can just move the whole folder
Directory.Move(oldGameFolder, newGameFolder); // <-- might fail if target is not empty
}
else
{
// Just copy the WTF and Interface folder

var oldInterfaceFolder = Path.Combine(oldGameFolder, "_classic_era_", "Interface");
var newInterfaceFolder = Path.Combine(newGameFolder, "_classic_era_", "Interface");
DirectoryCopy.Copy(oldInterfaceFolder, newInterfaceFolder);

var oldWtfFolder = Path.Combine(oldGameFolder, "_classic_era_", "WTF");
var newWtfFolder = Path.Combine(newGameFolder, "_classic_era_", "WTF");
DirectoryCopy.Copy(oldWtfFolder, newWtfFolder);
}
}
}
catch (Exception e)
{
Console.WriteLine("Error while TryUpgradeOldGameFolder");
Console.WriteLine(e);
}
}

private class LegacyV1Config : VersionedBaseConfig
{
public string GitRepoWinterspringLauncher { get; set; }

Check warning on line 236 in WinterspringLauncher/LauncherConfig.cs

View workflow job for this annotation

GitHub Actions / build_windows (windows)

Non-nullable property 'GitRepoWinterspringLauncher' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Expand Down
10 changes: 9 additions & 1 deletion WinterspringLauncher/LauncherLogic.StartGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void StartGame()
}

IBrush overallProgressColor = Brush.Parse("#4caf50");
IBrush sideProgressColor = Brush.Parse("#553399");
Task.Run(async () =>
{
if (_model.HermesIsRunning)
Expand Down Expand Up @@ -165,6 +166,7 @@ public void StartGame()
_model.GameIsInstalled = true;
}
bool buildInfoWasChanged = false;
if (gameInstallation.CustomBuildInfoURL != null && (clientWasDownloadedInThisSession || _config.CheckForClientBuildInfoUpdates))
{
_model.SetProgressbar("Checking BuildInfo status", 35, overallProgressColor);
Expand All @@ -173,13 +175,14 @@ public void StartGame()
_model.AddLogEntry($"BuildInfo URL: {gameInstallation.CustomBuildInfoURL}");
string newBuildInfo = SimpleFileDownloader.PerformGetStringRequest(gameInstallation.CustomBuildInfoURL);
string existingBuildInfo = File.ReadAllText(buildInfoFilePath);
string existingBuildInfo = File.Exists(buildInfoFilePath) ? File.ReadAllText(buildInfoFilePath) : string.Empty;
if (newBuildInfo.ReplaceLineEndings() != existingBuildInfo.ReplaceLineEndings())
{
_model.AddLogEntry("BuildInfo update detected");
await Task.Delay(TimeSpan.FromSeconds(0.5));
File.WriteAllText(buildInfoFilePath, newBuildInfo);
buildInfoWasChanged = true;
}
}
Expand Down Expand Up @@ -273,6 +276,11 @@ public void StartGame()
_model.SetProgressbar("Starting Game", 95, overallProgressColor);
await Task.Delay(TimeSpan.FromSeconds(0.5));
LauncherActions.StartGame(Path.Combine(gameInstallation.Directory, SubPathToWowForCustomServers));
if (buildInfoWasChanged)
{
_model.SetProgressbar("Your game is updating please wait a bit (check Task Manager!)", 100, sideProgressColor);
await Task.Delay(TimeSpan.FromSeconds(30));
}
}).ContinueWith((t) =>
{
if (t.Exception != null)
Expand Down
11 changes: 2 additions & 9 deletions WinterspringLauncher/LauncherLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ public LauncherLogic(MainWindowViewModel model)

if (_config.LastSelectedServerName == "") // first configuration
{
bool isAsia = CultureInfo.CurrentCulture.Name.StartsWith("zh", StringComparison.InvariantCultureIgnoreCase);

_config.LastSelectedServerName = isAsia
? "Everlook (Asia)"
: "Everlook (Europe)";

_config.GitHubMirror = isAsia
? "https://asia.cdn.everlook-wow.net/github-mirror/api/"
: null;
_config.LastSelectedServerName = LocaleDefaults.GetBestServerName();
_config.GitHubMirror = LocaleDefaults.GetBestGitHubMirror();
}

if (_config.GitHubMirror != null)
Expand Down
24 changes: 24 additions & 0 deletions WinterspringLauncher/LocaleDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Globalization;

namespace WinterspringLauncher;

public static class LocaleDefaults
{
public static bool ShouldUseAsiaPreferences { get; set; } = CultureInfo.CurrentCulture.Name.StartsWith("zh", StringComparison.InvariantCultureIgnoreCase);

public static string GetBestWoWConfigLocale()
{
return ShouldUseAsiaPreferences ? "zhCN" : "enUS";
}

public static string? GetBestGitHubMirror()
{
return ShouldUseAsiaPreferences ? "https://asia.cdn.everlook-wow.net/github-mirror/api/" : null;
}

public static string GetBestServerName()
{
return ShouldUseAsiaPreferences ? "Everlook (Asia)" : "Everlook (Europe)";
}
}
35 changes: 35 additions & 0 deletions WinterspringLauncher/Utils/DirectoryCopy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;

namespace WinterspringLauncher.Utils;

public static class DirectoryCopy
{
public static void Copy(string sourceDirectory, string targetDirectory)
{
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);

CopyAll(diSource, diTarget);
}

public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
{
Directory.CreateDirectory(target.FullName);

// Copy each file into the new directory.
foreach (FileInfo fi in source.GetFiles())
{
Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
}

// Copy each subdirectory using recursion.
foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
{
DirectoryInfo nextTargetSubDir =
target.CreateSubdirectory(diSourceSubDir.Name);
CopyAll(diSourceSubDir, nextTargetSubDir);
}
}
}
2 changes: 1 addition & 1 deletion WinterspringLauncher/Utils/HashHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static string ConvertBinarySha256ToHex(byte[] binarySha256Hash)

StringBuilder hashBuilder = new StringBuilder(32);
foreach (byte b in binarySha256Hash)
hashBuilder.Append(b.ToString("x2"));
hashBuilder.Append(b.ToString("X2"));
return hashBuilder.ToString();
}
}

0 comments on commit 11b4b15

Please sign in to comment.