Skip to content

Commit

Permalink
Strip build from versions
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Aug 22, 2024
1 parent 94a97bb commit 7c9fe57
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 2 additions & 7 deletions Reactor/Patches/ReactorVersionShower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,14 @@ internal static void Initialize()
}));
}

private static string ToStringWithoutBuild(Version version)
{
return $"{version.Major}.{version.Minor}.{version.Patch}{(version.PreRelease == null ? string.Empty : $"-{version.PreRelease}")}";
}

/// <summary>
/// Updates <see cref="Text"/> with reactor version and fires <see cref="TextUpdated"/>.
/// </summary>
public static void UpdateText()
{
if (Text == null) return;
Text.text = "Reactor " + ReactorPlugin.Version;
Text.text += "\nBepInEx " + ToStringWithoutBuild(Paths.BepInExVersion);
Text.text = "Reactor " + Version.Parse(ReactorPlugin.Version).WithoutBuild();
Text.text += "\nBepInEx " + Paths.BepInExVersion.WithoutBuild();
Text.text += "\nMods: " + IL2CPPChainloader.Instance.Plugins.Count;
TextUpdated?.Invoke(Text);
}
Expand Down
19 changes: 19 additions & 0 deletions Reactor/Utilities/Extensions/VersionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using SemanticVersioning;

namespace Reactor.Utilities.Extensions;

/// <summary>
/// Provides extension methods for <see cref="SemanticVersioning.Version"/>.
/// </summary>
public static class VersionExtensions
{
/// <summary>
/// Gets the provided <paramref name="version"/> without the build string (everything after the + symbol like the commit hash is stripped).
/// </summary>
/// <param name="version">The <see cref="SemanticVersioning.Version"/>.</param>
/// <returns>The <paramref name="version"/> without build.</returns>
public static Version WithoutBuild(this Version version)
{
return new Version(version.Major, version.Minor, version.Patch, version.PreRelease);
}
}
2 changes: 1 addition & 1 deletion Reactor/Utilities/ReactorPingTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void Register<T>(Func<bool>? shouldShow) where T : BasePlugin

var metadata = pluginInfo.Metadata;

Register(metadata.Name, metadata.Version.ToString(), metadata.Version.IsPreRelease, shouldShow);
Register(metadata.Name, metadata.Version.WithoutBuild().Clean(), metadata.Version.IsPreRelease, shouldShow);
}

internal static string? GetText()
Expand Down

0 comments on commit 7c9fe57

Please sign in to comment.