Skip to content

Commit 74d9999

Browse files
committed
Add informational version type
1 parent 1be1c93 commit 74d9999

6 files changed

Lines changed: 67 additions & 14 deletions

File tree

‎Torch.API/ITorchBase.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public interface ITorchBase
6565
/// <summary>
6666
/// The binary version of the current instance.
6767
/// </summary>
68-
Version TorchVersion { get; }
68+
InformationalVersion TorchVersion { get; }
6969

7070
/// <summary>
7171
/// Invoke an action on the game thread.

‎Torch.API/InformationalVersion.cs‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Torch.API
8+
{
9+
/// <summary>
10+
/// Version in the form v#.#.#.#-info
11+
/// </summary>
12+
public class InformationalVersion
13+
{
14+
public Version Version { get; set; }
15+
public string[] Information { get; set; }
16+
17+
public static bool TryParse(string input, out InformationalVersion version)
18+
{
19+
version = default(InformationalVersion);
20+
var trim = input.TrimStart('v');
21+
var info = trim.Split('-');
22+
if (!Version.TryParse(info[0], out Version result))
23+
return false;
24+
25+
version = new InformationalVersion { Version = result };
26+
27+
if (info.Length > 1)
28+
version.Information = info.Skip(1).ToArray();
29+
30+
return true;
31+
}
32+
33+
/// <inheritdoc />
34+
public override string ToString()
35+
{
36+
if (Information == null || Information.Length == 0)
37+
return $"v{Version}";
38+
39+
return $"v{Version}-{string.Join("-", Information)}";
40+
}
41+
42+
public static explicit operator InformationalVersion(Version v)
43+
{
44+
return new InformationalVersion { Version = v };
45+
}
46+
47+
public static implicit operator Version(InformationalVersion v)
48+
{
49+
return v.Version;
50+
}
51+
}
52+
}

‎Torch.API/Torch.API.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<Link>Properties\AssemblyVersion.cs</Link>
161161
</Compile>
162162
<Compile Include="ConnectionState.cs" />
163+
<Compile Include="InformationalVersion.cs" />
163164
<Compile Include="ITorchConfig.cs" />
164165
<Compile Include="Managers\DependencyManagerExtensions.cs" />
165166
<Compile Include="Managers\DependencyProviderExtensions.cs" />

‎Torch.Server/Views/ConfigControl.xaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<DataTemplate DataType="managers:WorldViewModel">
2525
<StackPanel>
2626
<StackPanel Orientation="Horizontal">
27-
<Label Content="Name: " Padding="0"/>
28-
<Label Content="{Binding Checkpoint.SessionName}" FontStyle="Oblique" Padding="0"/>
27+
<Label Content="{Binding Checkpoint.SessionName}" FontWeight="Bold" Padding="0"/>
28+
<Label Content="{Binding WorldPath}" Padding="5,0,0,0"/>
2929
</StackPanel>
3030
<StackPanel Orientation="Horizontal">
3131
<Label Content="Last saved: " Padding="0"/>

‎Torch/Extensions/StringExtensions.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class StringExtensions
1515
public static bool TryExtractVersion(this string version, out Version result)
1616
{
1717
result = null;
18-
var match = Regex.Match(version, @"(\d+\.)?(\d+\.)?(\d+)");
18+
var match = Regex.Match(version, @"(\d+\.)?(\d+\.)?(\d+\.)?(\d+)");
1919
return match.Success && Version.TryParse(match.Value, out result);
2020
}
2121
}

‎Torch/TorchBase.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ static TorchBase()
8585
public ITorchConfig Config { get; protected set; }
8686

8787
/// <inheritdoc />
88-
public Version TorchVersion { get; }
89-
90-
/// <summary>
91-
/// The version of Torch used, with extra data.
92-
/// </summary>
93-
public string TorchVersionVerbose { get; }
88+
public InformationalVersion TorchVersion { get; }
9489

9590
/// <inheritdoc />
9691
public Version GameVersion { get; private set; }
@@ -139,10 +134,15 @@ protected TorchBase()
139134

140135
Instance = this;
141136

142-
TorchVersion = Assembly.GetExecutingAssembly().GetName().Version;
143-
TorchVersionVerbose = Assembly.GetEntryAssembly()
137+
var versionString = Assembly.GetEntryAssembly()
144138
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
145-
?.InformationalVersion ?? TorchVersion.ToString();
139+
.InformationalVersion;
140+
141+
if (!InformationalVersion.TryParse(versionString, out InformationalVersion version))
142+
throw new TypeLoadException("Unable to parse the Torch version from the assembly.");
143+
144+
TorchVersion = version;
145+
146146
RunArgs = new string[0];
147147

148148
Managers = new DependencyManager();
@@ -326,7 +326,7 @@ public virtual void Init()
326326
#else
327327
Log.Info("RELEASE");
328328
#endif
329-
Log.Info($"Torch Version: {TorchVersionVerbose}");
329+
Log.Info($"Torch Version: {TorchVersion}");
330330
Log.Info($"Game Version: {GameVersion}");
331331
Log.Info($"Executing assembly: {Assembly.GetEntryAssembly().FullName}");
332332
Log.Info($"Executing directory: {AppDomain.CurrentDomain.BaseDirectory}");

0 commit comments

Comments
 (0)