2020-08-11 20:24:04 +02:00
|
|
|
|
namespace Giants.Launcher
|
|
|
|
|
{
|
|
|
|
|
using System;
|
2022-09-26 04:56:20 +02:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-11 20:24:04 +02:00
|
|
|
|
using System.Diagnostics;
|
2022-09-26 04:56:20 +02:00
|
|
|
|
using System.Linq;
|
2020-08-11 20:24:04 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
public static class VersionHelper
|
|
|
|
|
{
|
2022-09-26 04:56:20 +02:00
|
|
|
|
public static bool TryGetGameVersion(string gamePath, out Version version, out string branch)
|
2020-08-11 20:24:04 +02:00
|
|
|
|
{
|
2022-09-26 04:56:20 +02:00
|
|
|
|
version = default;
|
|
|
|
|
branch = string.Empty;
|
|
|
|
|
|
2020-08-11 20:24:04 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(gamePath);
|
2022-09-26 04:56:20 +02:00
|
|
|
|
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;
|
2020-08-11 20:24:04 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
2022-09-26 04:56:20 +02:00
|
|
|
|
return false;
|
2020-08-11 20:24:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Version GetLauncherVersion()
|
|
|
|
|
{
|
|
|
|
|
return new Version(Application.ProductVersion);
|
|
|
|
|
}
|
2022-09-26 04:56:20 +02:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-08-11 20:24:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|