Add informational version type

This commit is contained in:
John Gross
2017-12-03 10:22:11 -08:00
parent 1be1c938cc
commit 74d9999202
6 changed files with 67 additions and 14 deletions

View File

@@ -65,7 +65,7 @@ namespace Torch.API
/// <summary> /// <summary>
/// The binary version of the current instance. /// The binary version of the current instance.
/// </summary> /// </summary>
Version TorchVersion { get; } InformationalVersion TorchVersion { get; }
/// <summary> /// <summary>
/// Invoke an action on the game thread. /// Invoke an action on the game thread.

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API
{
/// <summary>
/// Version in the form v#.#.#.#-info
/// </summary>
public class InformationalVersion
{
public Version Version { get; set; }
public string[] Information { get; set; }
public static bool TryParse(string input, out InformationalVersion version)
{
version = default(InformationalVersion);
var trim = input.TrimStart('v');
var info = trim.Split('-');
if (!Version.TryParse(info[0], out Version result))
return false;
version = new InformationalVersion { Version = result };
if (info.Length > 1)
version.Information = info.Skip(1).ToArray();
return true;
}
/// <inheritdoc />
public override string ToString()
{
if (Information == null || Information.Length == 0)
return $"v{Version}";
return $"v{Version}-{string.Join("-", Information)}";
}
public static explicit operator InformationalVersion(Version v)
{
return new InformationalVersion { Version = v };
}
public static implicit operator Version(InformationalVersion v)
{
return v.Version;
}
}
}

View File

@@ -160,6 +160,7 @@
<Link>Properties\AssemblyVersion.cs</Link> <Link>Properties\AssemblyVersion.cs</Link>
</Compile> </Compile>
<Compile Include="ConnectionState.cs" /> <Compile Include="ConnectionState.cs" />
<Compile Include="InformationalVersion.cs" />
<Compile Include="ITorchConfig.cs" /> <Compile Include="ITorchConfig.cs" />
<Compile Include="Managers\DependencyManagerExtensions.cs" /> <Compile Include="Managers\DependencyManagerExtensions.cs" />
<Compile Include="Managers\DependencyProviderExtensions.cs" /> <Compile Include="Managers\DependencyProviderExtensions.cs" />

View File

@@ -24,8 +24,8 @@
<DataTemplate DataType="managers:WorldViewModel"> <DataTemplate DataType="managers:WorldViewModel">
<StackPanel> <StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Label Content="Name: " Padding="0"/> <Label Content="{Binding Checkpoint.SessionName}" FontWeight="Bold" Padding="0"/>
<Label Content="{Binding Checkpoint.SessionName}" FontStyle="Oblique" Padding="0"/> <Label Content="{Binding WorldPath}" Padding="5,0,0,0"/>
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<Label Content="Last saved: " Padding="0"/> <Label Content="Last saved: " Padding="0"/>

View File

@@ -15,7 +15,7 @@ namespace Torch
public static bool TryExtractVersion(this string version, out Version result) public static bool TryExtractVersion(this string version, out Version result)
{ {
result = null; result = null;
var match = Regex.Match(version, @"(\d+\.)?(\d+\.)?(\d+)"); var match = Regex.Match(version, @"(\d+\.)?(\d+\.)?(\d+\.)?(\d+)");
return match.Success && Version.TryParse(match.Value, out result); return match.Success && Version.TryParse(match.Value, out result);
} }
} }

View File

@@ -85,12 +85,7 @@ namespace Torch
public ITorchConfig Config { get; protected set; } public ITorchConfig Config { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
public Version TorchVersion { get; } public InformationalVersion TorchVersion { get; }
/// <summary>
/// The version of Torch used, with extra data.
/// </summary>
public string TorchVersionVerbose { get; }
/// <inheritdoc /> /// <inheritdoc />
public Version GameVersion { get; private set; } public Version GameVersion { get; private set; }
@@ -139,10 +134,15 @@ namespace Torch
Instance = this; Instance = this;
TorchVersion = Assembly.GetExecutingAssembly().GetName().Version; var versionString = Assembly.GetEntryAssembly()
TorchVersionVerbose = Assembly.GetEntryAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>() .GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? TorchVersion.ToString(); .InformationalVersion;
if (!InformationalVersion.TryParse(versionString, out InformationalVersion version))
throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
TorchVersion = version;
RunArgs = new string[0]; RunArgs = new string[0];
Managers = new DependencyManager(); Managers = new DependencyManager();
@@ -326,7 +326,7 @@ namespace Torch
#else #else
Log.Info("RELEASE"); Log.Info("RELEASE");
#endif #endif
Log.Info($"Torch Version: {TorchVersionVerbose}"); Log.Info($"Torch Version: {TorchVersion}");
Log.Info($"Game Version: {GameVersion}"); Log.Info($"Game Version: {GameVersion}");
Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}"); Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}"); Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");