mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-12-22 15:27:22 +01:00
Merge pull request #20 from ncblakely/users/tos/branchname
Get branch name from comments field instead of config.
This commit is contained in:
commit
31625f7466
@ -3,7 +3,6 @@
|
||||
public static class ConfigKeys
|
||||
{
|
||||
// Update
|
||||
public const string BranchName = "branchName";
|
||||
public const string EnableBranchSelection = "enableBranchSelection";
|
||||
|
||||
// Network
|
||||
|
@ -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<int>("NoAutoUpdate") == 0)
|
||||
{
|
||||
@ -199,7 +204,6 @@ namespace Giants.Launcher
|
||||
Task<VersionInfo> 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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<string, string> 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<string, string> GetCommentSettings(string comments)
|
||||
{
|
||||
Dictionary<string, string> commentSettingsDictionary = new Dictionary<string, string>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user