Browse Source

Switch over to Hive.Versioning (part 2)

Notably, this adds a SemVer shim assembly wrapping Hive.Versioning.
pull/72/head
Anairkoen Schno 3 years ago
parent
commit
86f1db65b0
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
10 changed files with 205 additions and 5 deletions
  1. +26
    -0
      BSIPA.sln
  2. +5
    -1
      IPA.Injector/IPA.Injector.csproj
  3. +6
    -2
      IPA.Loader/IPA.Loader.csproj
  4. +3
    -1
      IPA.Loader/Properties/AssemblyInfo.cs
  5. BIN
      Libs/thirdparty/Hive.Versioning.dll
  6. BIN
      Libs/thirdparty/Hive.Versioning.pdb
  7. +1
    -1
      Libs/thirdparty/Hive.Versioning.xml
  8. +78
    -0
      SemVer/Range.cs
  9. +16
    -0
      SemVer/SemVer.csproj
  10. +70
    -0
      SemVer/Version.cs

+ 26
- 0
BSIPA.sln View File

@ -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


+ 5
- 1
IPA.Injector/IPA.Injector.csproj View File

@ -81,8 +81,12 @@
<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.10.4" />
<PackageReference Include="SemanticVersioning" Version="1.2.2" />
<PackageReference Include="AsyncBridge" Version="0.3.1" />
<ProjectReference Include="..\SemVer\SemVer.csproj" />
<Reference Include="Hive.Versioning" Version="0.1.0">
<HintPath>$(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">


+ 6
- 2
IPA.Loader/IPA.Loader.csproj View File

@ -52,9 +52,13 @@
<PackageReference Include="Lib.Harmony" Version="2.0.2" />
<PackageReference Include="Mono.Cecil" Version="0.10.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Portable.System.ValueTuple" Version="1.0.1" />
<PackageReference Include="SemanticVersioning" Version="1.2.2" />
<PackageReference Include="AsyncBridge" Version="0.3.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<ProjectReference Include="..\SemVer\SemVer.csproj" />
<Reference Include="Hive.Versioning" Version="0.1.0">
<HintPath>$(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>


+ 3
- 1
IPA.Loader/Properties/AssemblyInfo.cs View File

@ -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")]


BIN
Libs/thirdparty/Hive.Versioning.dll View File


BIN
Libs/thirdparty/Hive.Versioning.pdb View File


+ 1
- 1
Libs/thirdparty/Hive.Versioning.xml View File

@ -459,7 +459,7 @@
</summary>
<param name="a">The first argument.</param>
<param name="b">The second argument.</param>
<returns>The logical disjunction of <paramref name="a"/> and <paramref name="b"/>.</returns>
<returns>The logical conjunction of <paramref name="a"/> and <paramref name="b"/>.</returns>
<seealso cref="M:Hive.Versioning.VersionRange.Conjunction(Hive.Versioning.VersionRange)"/>
</member>
<member name="M:Hive.Versioning.VersionRange.Invert">


+ 78
- 0
SemVer/Range.cs View File

@ -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<Range>, IEquatable<VersionRange>
{
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<Version> Satisfying(IEnumerable<Version> versions) => versions.Where(IsSatisfied);
public IEnumerable<string> Satisfying(IEnumerable<string> versions, bool loose = false)
=> versions.Where(v => IsSatisfied(v, loose));
public Version? MaxSatisfying(IEnumerable<Version> versions) => Satisfying(versions).Max();
public string? MaxSatisfying(IEnumerable<string> 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<string> Satisfying(string rangeSpec, IEnumerable<string> versions, bool loose = false)
=> new Range(rangeSpec, loose).Satisfying(versions, loose);
public static string? MaxSatisfying(string rangeSpec, IEnumerable<string> versions, bool loose = false)
=> new Range(rangeSpec, loose).MaxSatisfying(versions, loose);
private IEnumerable<Version> ValidVersions(IEnumerable<string> 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;
}
}
}
}
}

+ 16
- 0
SemVer/SemVer.csproj View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common.props" />
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include="Hive.Versioning" Version="0.1.0">
<HintPath>$(MSBuildThisFileDirectory)..\Libs\thirdparty\Hive.Versioning.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

+ 70
- 0
SemVer/Version.cs View File

@ -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<Version>, IComparable<HVersion>, IComparable, IEquatable<Version>, IEquatable<HVersion>
{
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<string>() : preRelease.Split('.'),
build is null ? Enumerable.Empty<string>() : 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);
}
}

Loading…
Cancel
Save