diff --git a/Giants.Launcher/ConfigKeys.cs b/Giants.Launcher/ConfigKeys.cs index ff7bf59..3b2087d 100644 --- a/Giants.Launcher/ConfigKeys.cs +++ b/Giants.Launcher/ConfigKeys.cs @@ -3,7 +3,6 @@ public static class ConfigKeys { // Update - public const string BranchName = "branchName"; public const string EnableBranchSelection = "enableBranchSelection"; // Network diff --git a/Giants.Launcher/Forms/LauncherForm.cs b/Giants.Launcher/Forms/LauncherForm.cs index d8c897e..0f038fb 100644 --- a/Giants.Launcher/Forms/LauncherForm.cs +++ b/Giants.Launcher/Forms/LauncherForm.cs @@ -29,6 +29,7 @@ namespace Giants.Launcher private string gamePath = null; private Updater updater; private readonly Config config; + private Version localGameVersion; private string branchName; private string communityAppUri; @@ -50,9 +51,6 @@ namespace Giants.Launcher this.config.Read(); this.config.TryGetString(ConfigSections.Network, ConfigKeys.MasterServerHostName, ConfigDefaults.MasterServerHostNameDefault, out string baseUrl); - this.config.TryGetString(ConfigSections.Update, ConfigKeys.BranchName, defaultValue: ConfigDefaults.BranchNameDefault, out string branchName); - - this.branchName = branchName; this.httpClient = new HttpClient( new HttpClientHandler() @@ -125,14 +123,11 @@ namespace Giants.Launcher form.ShowDialog(); - this.config.TryGetBool(ConfigSections.Update, ConfigKeys.EnableBranchSelection, defaultValue: false, out bool enableBranchSelection); - if (enableBranchSelection) + if (!string.IsNullOrEmpty(form.SelectedBranch)) { - this.config.TryGetString(ConfigSections.Update, ConfigKeys.BranchName, defaultValue: ConfigDefaults.BranchNameDefault, out string branchName); - - if (!this.branchName.Equals(branchName)) + if (!this.branchName.Equals(form.SelectedBranch)) { - this.branchName = branchName; + this.branchName = form.SelectedBranch; VersionInfo gameVersionInfo = await this.GetVersionInfo( GetApplicationName(ApplicationType.Game), this.branchName); @@ -163,8 +158,18 @@ namespace Giants.Launcher } } - // Read game settings from registry - GameSettings.Load(this.gamePath); + if (!VersionHelper.TryGetGameVersion(this.gamePath, out Version localGameVersion, out string branch)) + { + string message = string.Format(Resources.AppNotFound, Resources.AppName); + MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + Application.Exit(); + } + + this.localGameVersion = localGameVersion; + this.branchName = branch; + + // Read game settings from registry + GameSettings.Load(this.gamePath); if (GameSettings.Get("NoAutoUpdate") == 0) { @@ -199,7 +204,6 @@ namespace Giants.Launcher Task launcherVersionInfo = this.GetVersionInfo( GetApplicationName(ApplicationType.Launcher), this.branchName); - Version localGameVersion = VersionHelper.GetGameVersion(this.gamePath); Version localLauncherVersion = VersionHelper.GetLauncherVersion(); await Task.WhenAll(gameVersionInfo, launcherVersionInfo); @@ -315,12 +319,6 @@ namespace Giants.Launcher updaterProcess.Start(); - this.config.TryGetBool(ConfigSections.Update, ConfigKeys.EnableBranchSelection, defaultValue: false, out bool enableBranchSelection); - if (enableBranchSelection) - { - this.config.SetValue(ConfigSections.Update, ConfigKeys.BranchName, this.branchName); - } - this.config.Write(); Application.Exit(); diff --git a/Giants.Launcher/Forms/OptionsForm.cs b/Giants.Launcher/Forms/OptionsForm.cs index 909cc76..cb788cc 100644 --- a/Giants.Launcher/Forms/OptionsForm.cs +++ b/Giants.Launcher/Forms/OptionsForm.cs @@ -17,6 +17,8 @@ namespace Giants.Launcher private readonly bool enableBranchSelection; private readonly BranchesClient branchesClient; + public string SelectedBranch { get; set; } + public OptionsForm( string title, string gamePath, @@ -284,7 +286,7 @@ namespace Giants.Launcher string newBranch = this.cmbBranch.SelectedItem?.ToString(); if (!string.IsNullOrEmpty(newBranch) && !newBranch.Equals(this.currentBranchName, StringComparison.OrdinalIgnoreCase)) { - this.config.SetValue(ConfigSections.Update, ConfigKeys.BranchName, newBranch); + this.SelectedBranch = newBranch; } } diff --git a/Giants.Launcher/VersionHelper.cs b/Giants.Launcher/VersionHelper.cs index 58d1e31..95b8108 100644 --- a/Giants.Launcher/VersionHelper.cs +++ b/Giants.Launcher/VersionHelper.cs @@ -1,25 +1,38 @@ namespace Giants.Launcher { using System; + using System.Collections.Generic; using System.Diagnostics; + using System.Linq; using System.Windows.Forms; public static class VersionHelper { - public static Version GetGameVersion(string gamePath) + public static bool TryGetGameVersion(string gamePath, out Version version, out string branch) { + version = default; + branch = string.Empty; + try { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gamePath); - return new Version(fvi.FileVersion.Replace(',', '.')); + version = new Version(fvi.FileVersion.Replace(',', '.')); + + Dictionary commentSettings = GetCommentSettings(fvi.Comments); + if (commentSettings.ContainsKey("Branch")) + { + branch = commentSettings["Branch"]; + } + else + { + branch = "Release"; + } + + return true; } catch (Exception) { - string message = string.Format(Resources.AppNotFound, Resources.AppName); - MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - Application.Exit(); - - return null; + return false; } } @@ -27,5 +40,32 @@ { return new Version(Application.ProductVersion); } + + private static Dictionary GetCommentSettings(string comments) + { + Dictionary commentSettingsDictionary = new Dictionary(); + string[] commentSettings = comments.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); + + if (!commentSettings.Any()) + { + return commentSettingsDictionary; + } + + foreach (var keyValuePair in commentSettings) + { + string[] commentKeyValuePairs = keyValuePair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); + if (commentKeyValuePairs.Length != 2) + { + continue; + } + + if (!commentSettingsDictionary.ContainsKey(commentKeyValuePairs[0])) + { + commentSettingsDictionary.Add(commentKeyValuePairs[0], commentKeyValuePairs[1]); + } + } + + return commentSettingsDictionary; + } } }