From 86f1db65b0e4ad0f1f9250eb8f5f426804a8654b Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 2 Jun 2021 02:16:59 -0500 Subject: [PATCH] Switch over to Hive.Versioning (part 2) Notably, this adds a SemVer shim assembly wrapping Hive.Versioning. --- BSIPA.sln | 26 +++++++++ IPA.Injector/IPA.Injector.csproj | 6 +- IPA.Loader/IPA.Loader.csproj | 8 ++- IPA.Loader/Properties/AssemblyInfo.cs | 4 +- Libs/thirdparty/Hive.Versioning.dll | Bin 37888 -> 37888 bytes Libs/thirdparty/Hive.Versioning.pdb | Bin 18860 -> 18860 bytes Libs/thirdparty/Hive.Versioning.xml | 2 +- SemVer/Range.cs | 78 ++++++++++++++++++++++++++ SemVer/SemVer.csproj | 16 ++++++ SemVer/Version.cs | 70 +++++++++++++++++++++++ 10 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 SemVer/Range.cs create mode 100644 SemVer/SemVer.csproj create mode 100644 SemVer/Version.cs diff --git a/BSIPA.sln b/BSIPA.sln index f2a38632..f4997616 100644 --- a/BSIPA.sln +++ b/BSIPA.sln @@ -50,6 +50,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IPA.Loader", "IPA.Loader\IP EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net3-Proxy", "Net3-Proxy\Net3-Proxy.csproj", "{0DEDB099-9A26-4069-A4C1-A76CEB16283B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SemVer", "SemVer\SemVer.csproj", "{B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -224,6 +226,30 @@ Global {0DEDB099-9A26-4069-A4C1-A76CEB16283B}.Verbose|x64.Build.0 = Debug|Any CPU {0DEDB099-9A26-4069-A4C1-A76CEB16283B}.Verbose|x86.ActiveCfg = Debug|Any CPU {0DEDB099-9A26-4069-A4C1-A76CEB16283B}.Verbose|x86.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|x64.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|x64.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|x86.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Debug|x86.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|Any CPU.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|x64.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|x64.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|x86.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Release|x86.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|Any CPU.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|Any CPU.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|x64.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|x64.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|x86.ActiveCfg = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose_Release|x86.Build.0 = Release|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|Any CPU.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|Any CPU.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|x64.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|x64.Build.0 = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|x86.ActiveCfg = Debug|Any CPU + {B25EEC48-A5D0-4A63-BA73-5DD43F7F592A}.Verbose|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj index e7f5169a..f44c7342 100644 --- a/IPA.Injector/IPA.Injector.csproj +++ b/IPA.Injector/IPA.Injector.csproj @@ -81,8 +81,12 @@ - + + + + $(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll + diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index bd4d4609..cfc46967 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -52,9 +52,13 @@ - - + + + + + $(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll + diff --git a/IPA.Loader/Properties/AssemblyInfo.cs b/IPA.Loader/Properties/AssemblyInfo.cs index 456c770b..6f7ebb52 100644 --- a/IPA.Loader/Properties/AssemblyInfo.cs +++ b/IPA.Loader/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -18,6 +19,7 @@ using System.Runtime.InteropServices; // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] +[assembly: CLSCompliant(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("5ad344f0-01a0-4ca8-92e5-9d095737744d")] diff --git a/Libs/thirdparty/Hive.Versioning.dll b/Libs/thirdparty/Hive.Versioning.dll index 93ed807e76d01acf366769e4a7f94121bd92c3ec..25631609ef826f28d8b0b47645f64f715ccd28fe 100644 GIT binary patch delta 2783 zcmY+`dvH|M9S895ee8W~Her*E%>za^leEN8z~~N5VYOhkB|t2J1c)J$&}M)*DMmrZ z2XZ%VT#-V}?Zs_n(rF~xMv1!PCK?fKFf^?bw9(KG?L?Z)ASO&iVbFFQJMHhBd%833 zA2;`NzQ1$Mo^v0YXrCPIle-ScPMLl1dg*=pg)P#9jwD&qS*Js?ijv2{KUH*;;X%!I zpmZ%Dxy|@IRV06+X6`3@fNW*4oL82*UVm6h{mS@w`S<&SK=FPcSOm1>(RuCO`&xJJ z+{1czRsaW7YTHx`->rb3+KN|iS`(qa3!K5qTIt!88L@P$>pQGGfs3B^;9jD4WP_l?;`9s>zmG!9jh9X??{A&nc zJ*v54F!fVZSua$e|4G?^#zhtlBiZ>*1`BLn=pZ^`XY5R zf?RRPMyt97XBP9!$THg1dR*g*V?JdK@GWt(g_LbYh%1h;@gMarbd`h6pD-#7*>e~A z%2{a~t;Un`HmEnd9q%=AJx%ZlMY(dhY#cHQC~Fpa#dy@S9gz_0XJg73^R%F98B-iP z)qhAkG08PbnwECqa}v!zijP!D-Ua{nSm{OSBlW+YR*Z8|sV5}gjUe4l?2GPE3$(it z7K)MDQ00p5pdxKI+J%yyQtcibNvmAD7d>3;4qC14!6cJK-!$pjt380J$3I?ri8xqKA|54*dt7p zVdHDi}|=5kl~683Vj73LW)q5clHV>Dx_kwor~ncNk=imLTY?g~?AgJ*g zYSA;A!gHK4oX==7Qb=++#-Q&BV*ryv=Y5Asb3&JV4(XZ@GLIR9@YS&C9V3^kL}(FL zSSZ3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LnN(LJtQ^#O#1Vx%TiI-(O)sP00GP>(yP{uGDPDp4Q8F)nt3)~I`sVlwHQ_PCqX zM{sEso5DiA=b-vCgzwU;pXVIXh#a zj4MHlsL?DO=CW|asMl;vb2*#;9GX{yUe4wx(8d)vX-$u52`npTp>yp!(Vo^-^?6(p z`qJ319fHnoVX6%2GwLBkgw`3oludt+WftanKhR!8{~D+AQOb^>9!=r|XAI}PwR#f$T(;hqv0v{+O6YvXLDIC)eiOGC<=c-9flQT7%- zaVjxN>crQLB`|At)H49z zMm9`be`EHf^e*NKot|APzl#E)QLdmPT2nn$M$+o?yodg@e(gDpf+}asS-#gj<}fN9 zBH!2R`7P?x8t{yuS!gk3XAn(m!1E#6g_iq9Jfk=xw32Ivs}&L7S;~SDHeoAvkUl~M zS3-ZpH{toCi3q3j5IT!?E_M)8o{w=jttrnr_%^X&oMSnL2Ci293E!kNhL-Osz0xmGoecw)lrf^MUhy0(B3aVKa#{%_= z@eh=xC3!ERsha)%(3M%BhLlSvzRxLr%U>!_p@+-a?kSuSV!strIK$=K+m|uUBqelj zK+Cv{OI$XB0WS$PY)lKgNmmdOdM0pl##L0-APk+tv()i(M0jXJnNvdQcEq0o*D)-# zbj}g|I>v=IaHW#VBOiJS^H72q4CKJZJp5C7i5@LEILcd&A`e^b8@D|ioQGWLs8ob5 ztDX*>459p3%4elq8YQYJC3t!;=EpCp9`$Q8>BA# crGr1Q%Oqbi^Xab@dGL;8)-OMotYzB&02d`*wEzGB diff --git a/Libs/thirdparty/Hive.Versioning.pdb b/Libs/thirdparty/Hive.Versioning.pdb index 846207fb47841cb58cca21bca31489838e56c6dd..c74f836c4731c00f207c694b3de6769e1193c84e 100644 GIT binary patch delta 167 zcmV;Y09gO5lL4%g0g!wY;ebuC0y0xfv#BshbXInJ3V7d_k&rL}c(K9L1RZ_>001Wd z3jhcJ0RWKz006@P001Wd3jhfK0RWh@u?30^AdnStmD=L5t|gl=J6T6+-&C33*2EY< z_p)oxvFq(`A(LAZVv$MhJj!rILt@8hbs)OG>Fl#^Q%V<9U^AsK^VM?y}*K5mMcTzI%TrN-UcZ1k!q9h)#R9ibwVksuS3 VfHe%W{u7iV1TO$43$vCt783e^Jf8pn diff --git a/Libs/thirdparty/Hive.Versioning.xml b/Libs/thirdparty/Hive.Versioning.xml index 8143d72c..8a3c5787 100644 --- a/Libs/thirdparty/Hive.Versioning.xml +++ b/Libs/thirdparty/Hive.Versioning.xml @@ -459,7 +459,7 @@ The first argument. The second argument. - The logical disjunction of and . + The logical conjunction of and . diff --git a/SemVer/Range.cs b/SemVer/Range.cs new file mode 100644 index 00000000..1f7a6f32 --- /dev/null +++ b/SemVer/Range.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Hive.Versioning; +using HVersion = Hive.Versioning.Version; + +namespace SemVer +{ + [Obsolete("Use Hive.Versioning.VersionRange instead.")] + public class Range : IEquatable, IEquatable + { + public VersionRange UnderlyingRange { get; } + + private Range(VersionRange real) => UnderlyingRange = real; + + public Range(string rangeSpec, bool loose = false) : this(new(rangeSpec)) + => _ = loose; // loose is ignored because Hive doesn't have an equivalent + + public static Range ForHiveRange(VersionRange real) => new(real); + + public bool IsSatisfied(Version version) => IsSatisfied(version.UnderlyingVersion); + public bool IsSatisfied(HVersion version) => UnderlyingRange.Matches(version); + public bool IsSatisfied(string versionString, bool loose = false) => IsSatisfied(new Version(versionString, loose)); + + public IEnumerable Satisfying(IEnumerable versions) => versions.Where(IsSatisfied); + public IEnumerable Satisfying(IEnumerable versions, bool loose = false) + => versions.Where(v => IsSatisfied(v, loose)); + public Version? MaxSatisfying(IEnumerable versions) => Satisfying(versions).Max(); + public string? MaxSatisfying(IEnumerable versionStrings, bool loose = false) + => MaxSatisfying(ValidVersions(versionStrings, loose))?.ToString(); + public Range Intersect(Range other) => new(UnderlyingRange & other.UnderlyingRange); // the conjunction is the intersection + public override string ToString() => UnderlyingRange.ToString(); + + public bool Equals(Range? other) => UnderlyingRange.Equals(other?.UnderlyingRange); + public bool Equals(VersionRange? other) => UnderlyingRange.Equals(other); + public override bool Equals(object? obj) + => obj switch + { + Range r => Equals(r), + VersionRange vr => Equals(vr), + _ => false + }; + + public static bool operator ==(Range? a, Range? b) => a?.Equals(b) ?? b is null; + + public static bool operator !=(Range? a, Range? b) => !(a == b); + + public override int GetHashCode() => UnderlyingRange.GetHashCode(); + + public static bool IsSatisfied(string rangeSpec, string versionString, bool loose = false) + => new Range(rangeSpec, loose).IsSatisfied(versionString, loose); + public static IEnumerable Satisfying(string rangeSpec, IEnumerable versions, bool loose = false) + => new Range(rangeSpec, loose).Satisfying(versions, loose); + + public static string? MaxSatisfying(string rangeSpec, IEnumerable versions, bool loose = false) + => new Range(rangeSpec, loose).MaxSatisfying(versions, loose); + + private IEnumerable ValidVersions(IEnumerable versionStrings, bool loose) + { + foreach (string versionString in versionStrings) + { + Version? version = null; + try + { + version = new Version(versionString, loose); + } + catch (ArgumentException) + { + } + + if (version is not null) + { + yield return version; + } + } + } + } +} diff --git a/SemVer/SemVer.csproj b/SemVer/SemVer.csproj new file mode 100644 index 00000000..eb567912 --- /dev/null +++ b/SemVer/SemVer.csproj @@ -0,0 +1,16 @@ + + + + + + net461 + enable + + + + + $(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll + + + + diff --git a/SemVer/Version.cs b/SemVer/Version.cs new file mode 100644 index 00000000..6db9b027 --- /dev/null +++ b/SemVer/Version.cs @@ -0,0 +1,70 @@ +using System; +using System.Linq; +using HVersion = Hive.Versioning.Version; + +namespace SemVer +{ + [Obsolete("Use Hive.Versioning.Version instead.")] + public class Version : IComparable, IComparable, IComparable, IEquatable, IEquatable + { + public HVersion UnderlyingVersion { get; } + + private Version(HVersion real) => UnderlyingVersion = real; + + public static Version ForHiveVersion(HVersion real) => new(real); + + public Version(string input, bool loose = false) : this(new HVersion(input)) + => _ = loose; // specifically unused because Hive has no equivalent (by design) + public Version(int major, int minor, int patch, string? preRelease = null, string? build = null) + : this(new HVersion(major, minor, patch, + preRelease is null ? Enumerable.Empty() : preRelease.Split('.'), + build is null ? Enumerable.Empty() : build.Split('.'))) + { + } + + public int Major => (int)UnderlyingVersion.Major; + public int Minor => (int)UnderlyingVersion.Minor; + public int Patch => (int)UnderlyingVersion.Patch; + public string PreRelease => string.Join(".", UnderlyingVersion.PreReleaseIds); + public string Build => string.Join(".", UnderlyingVersion.BuildIds); + + public Version BaseVersion() => new(new(UnderlyingVersion.Major, UnderlyingVersion.Minor, UnderlyingVersion.Patch)); + public override string ToString() => UnderlyingVersion.ToString(); + public string Clean() => ToString(); // normally this is the other way around kek + public override int GetHashCode() => UnderlyingVersion.GetHashCode(); + public bool Equals(Version? other) => UnderlyingVersion.Equals(other?.UnderlyingVersion); + public bool Equals(HVersion? other) => UnderlyingVersion.Equals(other); + public override bool Equals(object? obj) + => obj switch + { + Version v => Equals(v), + HVersion h => Equals(h), + _ => false + }; + + public int CompareTo(Version? other) => UnderlyingVersion.CompareTo(other?.UnderlyingVersion); + public int CompareTo(HVersion? other) => UnderlyingVersion.CompareTo(other); + public int CompareTo(object? obj) + => obj switch + { + null => 1, + Version v => CompareTo(v), + HVersion h => CompareTo(h), + _ => throw new ArgumentException("Object is not a Version") + }; + + public static bool operator ==(Version? a, Version? b) + => a?.UnderlyingVersion == b?.UnderlyingVersion; + public static bool operator !=(Version? a, Version? b) + => a?.UnderlyingVersion != b?.UnderlyingVersion; + + public static bool operator >(Version? a, Version? b) + => a is null ? b is not null && b.CompareTo(a) < 0 : a.CompareTo(b) > 0; + public static bool operator >=(Version? a, Version? b) + => !(a < b); + public static bool operator <(Version? a, Version? b) + => a is null ? b is not null && b.CompareTo(a) > 0 : a.CompareTo(b) < 0; + public static bool operator <=(Version? a, Version? b) + => !(a > b); + } +}