From 4c051f9fe1e8a296cf5cfc6c01c81f181fb8d44a Mon Sep 17 00:00:00 2001 From: js6pak Date: Tue, 20 Aug 2024 20:48:27 +0200 Subject: [PATCH] Strip build from versions --- Reactor/Patches/ReactorVersionShower.cs | 9 ++------- .../Utilities/Extensions/VersionExtensions.cs | 19 +++++++++++++++++++ Reactor/Utilities/ReactorPingTracker.cs | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 Reactor/Utilities/Extensions/VersionExtensions.cs diff --git a/Reactor/Patches/ReactorVersionShower.cs b/Reactor/Patches/ReactorVersionShower.cs index 6ed8f2a..16c47df 100644 --- a/Reactor/Patches/ReactorVersionShower.cs +++ b/Reactor/Patches/ReactorVersionShower.cs @@ -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}")}"; - } - /// /// Updates with reactor version and fires . /// 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); } diff --git a/Reactor/Utilities/Extensions/VersionExtensions.cs b/Reactor/Utilities/Extensions/VersionExtensions.cs new file mode 100644 index 0000000..947dd80 --- /dev/null +++ b/Reactor/Utilities/Extensions/VersionExtensions.cs @@ -0,0 +1,19 @@ +using SemanticVersioning; + +namespace Reactor.Utilities.Extensions; + +/// +/// Provides extension methods for . +/// +public static class VersionExtensions +{ + /// + /// Gets the provided without the build string (everything after the + symbol like the commit hash is stripped). + /// + /// The . + /// The without build. + public static Version WithoutBuild(this Version version) + { + return new Version(version.Major, version.Minor, version.Patch, version.PreRelease); + } +} diff --git a/Reactor/Utilities/ReactorPingTracker.cs b/Reactor/Utilities/ReactorPingTracker.cs index beb8325..0c6d29d 100644 --- a/Reactor/Utilities/ReactorPingTracker.cs +++ b/Reactor/Utilities/ReactorPingTracker.cs @@ -82,7 +82,7 @@ public static void Register(Func? 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()