1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-23 14:45:37 +01:00
GiantsTools/Giants.Launcher/VersionHelper.cs

72 lines
2.2 KiB
C#
Raw Normal View History

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