1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-21 21:55:38 +01:00

Compare commits

..

No commits in common. "31625f7466042c8705c392d75fcf3a973eca0e68" and "90296b25853e984707d60c08a955318a3002a4e3" have entirely different histories.

4 changed files with 27 additions and 66 deletions

View File

@ -3,6 +3,7 @@
public static class ConfigKeys
{
// Update
public const string BranchName = "branchName";
public const string EnableBranchSelection = "enableBranchSelection";
// Network

View File

@ -29,7 +29,6 @@ namespace Giants.Launcher
private string gamePath = null;
private Updater updater;
private readonly Config config;
private Version localGameVersion;
private string branchName;
private string communityAppUri;
@ -51,6 +50,9 @@ 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()
@ -123,11 +125,14 @@ namespace Giants.Launcher
form.ShowDialog();
if (!string.IsNullOrEmpty(form.SelectedBranch))
this.config.TryGetBool(ConfigSections.Update, ConfigKeys.EnableBranchSelection, defaultValue: false, out bool enableBranchSelection);
if (enableBranchSelection)
{
if (!this.branchName.Equals(form.SelectedBranch))
this.config.TryGetString(ConfigSections.Update, ConfigKeys.BranchName, defaultValue: ConfigDefaults.BranchNameDefault, out string branchName);
if (!this.branchName.Equals(branchName))
{
this.branchName = form.SelectedBranch;
this.branchName = branchName;
VersionInfo gameVersionInfo = await this.GetVersionInfo(
GetApplicationName(ApplicationType.Game), this.branchName);
@ -158,18 +163,8 @@ namespace Giants.Launcher
}
}
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);
// Read game settings from registry
GameSettings.Load(this.gamePath);
if (GameSettings.Get<int>("NoAutoUpdate") == 0)
{
@ -204,6 +199,7 @@ 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);
@ -319,6 +315,12 @@ 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();

View File

@ -17,8 +17,6 @@ namespace Giants.Launcher
private readonly bool enableBranchSelection;
private readonly BranchesClient branchesClient;
public string SelectedBranch { get; set; }
public OptionsForm(
string title,
string gamePath,
@ -286,7 +284,7 @@ namespace Giants.Launcher
string newBranch = this.cmbBranch.SelectedItem?.ToString();
if (!string.IsNullOrEmpty(newBranch) && !newBranch.Equals(this.currentBranchName, StringComparison.OrdinalIgnoreCase))
{
this.SelectedBranch = newBranch;
this.config.SetValue(ConfigSections.Update, ConfigKeys.BranchName, newBranch);
}
}

View File

@ -1,38 +1,25 @@
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 bool TryGetGameVersion(string gamePath, out Version version, out string branch)
public static Version GetGameVersion(string gamePath)
{
version = default;
branch = string.Empty;
try
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gamePath);
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;
return new Version(fvi.FileVersion.Replace(',', '.'));
}
catch (Exception)
{
return false;
string message = string.Format(Resources.AppNotFound, Resources.AppName);
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
return null;
}
}
@ -40,32 +27,5 @@
{
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;
}
}
}