diff --git a/WinterspringLauncher/LauncherActions.cs b/WinterspringLauncher/LauncherActions.cs index 2ec4b3e..c56bdd6 100644 --- a/WinterspringLauncher/LauncherActions.cs +++ b/WinterspringLauncher/LauncherActions.cs @@ -41,11 +41,8 @@ public static void PrepareGameConfigWtf(string gamePath, string portalAddress) List configContent; if (!File.Exists(configWtfPath)) { - // TODO Take the language from this launcher configContent = new List(); - string bestDefaultTextLocale = CultureInfo.CurrentCulture.Name.StartsWith("zh", StringComparison.InvariantCultureIgnoreCase) - ? "zhCN" - : "enUS"; + string bestDefaultTextLocale = LocaleDefaults.GetBestWoWConfigLocale(); configContent.Add($"SET textLocale {bestDefaultTextLocale}"); } else diff --git a/WinterspringLauncher/LauncherConfig.cs b/WinterspringLauncher/LauncherConfig.cs index 0d5e88d..c069e71 100644 --- a/WinterspringLauncher/LauncherConfig.cs +++ b/WinterspringLauncher/LauncherConfig.cs @@ -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; @@ -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.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 @@ -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); @@ -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; } diff --git a/WinterspringLauncher/LauncherLogic.StartGame.cs b/WinterspringLauncher/LauncherLogic.StartGame.cs index 93ae77b..e4295cd 100644 --- a/WinterspringLauncher/LauncherLogic.StartGame.cs +++ b/WinterspringLauncher/LauncherLogic.StartGame.cs @@ -48,6 +48,7 @@ public void StartGame() } IBrush overallProgressColor = Brush.Parse("#4caf50"); + IBrush sideProgressColor = Brush.Parse("#553399"); Task.Run(async () => { if (_model.HermesIsRunning) @@ -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); @@ -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; } } @@ -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) diff --git a/WinterspringLauncher/LauncherLogic.cs b/WinterspringLauncher/LauncherLogic.cs index be5ebca..753993f 100644 --- a/WinterspringLauncher/LauncherLogic.cs +++ b/WinterspringLauncher/LauncherLogic.cs @@ -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) diff --git a/WinterspringLauncher/LocaleDefaults.cs b/WinterspringLauncher/LocaleDefaults.cs new file mode 100644 index 0000000..b90713a --- /dev/null +++ b/WinterspringLauncher/LocaleDefaults.cs @@ -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)"; + } +} diff --git a/WinterspringLauncher/Utils/DirectoryCopy.cs b/WinterspringLauncher/Utils/DirectoryCopy.cs new file mode 100644 index 0000000..8262d09 --- /dev/null +++ b/WinterspringLauncher/Utils/DirectoryCopy.cs @@ -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); + } + } +} diff --git a/WinterspringLauncher/Utils/HashHelper.cs b/WinterspringLauncher/Utils/HashHelper.cs index dcccff0..8202940 100644 --- a/WinterspringLauncher/Utils/HashHelper.cs +++ b/WinterspringLauncher/Utils/HashHelper.cs @@ -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(); } }