Add informational version type
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Torch.API
|
||||
/// <summary>
|
||||
/// The binary version of the current instance.
|
||||
/// </summary>
|
||||
Version TorchVersion { get; }
|
||||
InformationalVersion TorchVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoke an action on the game thread.
|
||||
|
52
Torch.API/InformationalVersion.cs
Normal file
52
Torch.API/InformationalVersion.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -160,6 +160,7 @@
|
||||
<Link>Properties\AssemblyVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ConnectionState.cs" />
|
||||
<Compile Include="InformationalVersion.cs" />
|
||||
<Compile Include="ITorchConfig.cs" />
|
||||
<Compile Include="Managers\DependencyManagerExtensions.cs" />
|
||||
<Compile Include="Managers\DependencyProviderExtensions.cs" />
|
||||
|
@@ -24,8 +24,8 @@
|
||||
<DataTemplate DataType="managers:WorldViewModel">
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Name: " Padding="0"/>
|
||||
<Label Content="{Binding Checkpoint.SessionName}" FontStyle="Oblique" Padding="0"/>
|
||||
<Label Content="{Binding Checkpoint.SessionName}" FontWeight="Bold" Padding="0"/>
|
||||
<Label Content="{Binding WorldPath}" Padding="5,0,0,0"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Last saved: " Padding="0"/>
|
||||
|
@@ -15,7 +15,7 @@ namespace Torch
|
||||
public static bool TryExtractVersion(this string version, out Version result)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -85,12 +85,7 @@ namespace Torch
|
||||
public ITorchConfig Config { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Version TorchVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of Torch used, with extra data.
|
||||
/// </summary>
|
||||
public string TorchVersionVerbose { get; }
|
||||
public InformationalVersion TorchVersion { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Version GameVersion { get; private set; }
|
||||
@@ -139,10 +134,15 @@ namespace Torch
|
||||
|
||||
Instance = this;
|
||||
|
||||
TorchVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
TorchVersionVerbose = Assembly.GetEntryAssembly()
|
||||
var versionString = Assembly.GetEntryAssembly()
|
||||
.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];
|
||||
|
||||
Managers = new DependencyManager();
|
||||
@@ -326,7 +326,7 @@ namespace Torch
|
||||
#else
|
||||
Log.Info("RELEASE");
|
||||
#endif
|
||||
Log.Info($"Torch Version: {TorchVersionVerbose}");
|
||||
Log.Info($"Torch Version: {TorchVersion}");
|
||||
Log.Info($"Game Version: {GameVersion}");
|
||||
Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
|
||||
Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");
|
||||
|
Reference in New Issue
Block a user