From 44aa9f64108d495cec2efda02770f5c43ccde752 Mon Sep 17 00:00:00 2001 From: Bepis <36346617+bbepis@users.noreply.github.com> Date: Wed, 2 Dec 2020 23:54:33 +1100 Subject: [PATCH] Allow long-style version parsing for BepInPlugin --- BepInEx.Core/Contract/Attributes.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/BepInEx.Core/Contract/Attributes.cs b/BepInEx.Core/Contract/Attributes.cs index 25ccf6b..eb15914 100644 --- a/BepInEx.Core/Contract/Attributes.cs +++ b/BepInEx.Core/Contract/Attributes.cs @@ -29,18 +29,35 @@ namespace BepInEx /// - /// The specfic version of the plugin. + /// The specific version of the plugin. /// public SemVer.Version Version { get; protected set; } /// The unique identifier of the plugin. Should not change between plugin versions. /// The user friendly name of the plugin. Is able to be changed between versions. - /// The specfic version of the plugin. + /// The specific version of the plugin. public BepInPlugin(string GUID, string Name, string Version) { this.GUID = GUID; this.Name = Name; - this.Version = SemVer.Version.TryParse(Version, out var v) ? v : null; + this.Version = TryParseLongVersion(Version); + } + + private static SemVer.Version TryParseLongVersion(string version) + { + if (SemVer.Version.TryParse(version, out var v)) + return v; + + // no System.Version.TryParse() on .NET 3.5 + try + { + var longVersion = new System.Version(version); + + return new SemVer.Version(longVersion.Major, longVersion.Minor, longVersion.Build); + } + catch { } + + return null; } internal static BepInPlugin FromCecilType(TypeDefinition td) @@ -93,7 +110,7 @@ namespace BepInEx public SemVer.Range VersionRange { get; protected set; } /// - /// Marks this as depenant on another plugin. The other plugin will be loaded before this one. + /// Marks this as dependent on another plugin. The other plugin will be loaded before this one. /// If the other plugin doesn't exist, what happens depends on the parameter. /// /// The GUID of the referenced plugin. @@ -106,7 +123,7 @@ namespace BepInEx } /// - /// Marks this as depenant on another plugin. The other plugin will be loaded before this one. + /// Marks this as dependent on another plugin. The other plugin will be loaded before this one. /// If the other plugin doesn't exist or is of a version not satisfying , this plugin will not load and an error will be logged instead. /// /// The GUID of the referenced plugin.