Skip to content

Commit

Permalink
Merge pull request #369 from Sewer56/module-issue-v2
Browse files Browse the repository at this point in the history
Added: Improved Diagnostics (ModuleIssue) Reporting
  • Loading branch information
Aragas authored Nov 12, 2024
2 parents 3e8490a + 47de52a commit 338239e
Show file tree
Hide file tree
Showing 22 changed files with 2,323 additions and 1,642 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<VersionOverride>0</VersionOverride>
<Version>5.0.$(VersionOverride)</Version>
<Version>6.0.$(VersionOverride)</Version>
</PropertyGroup>

<!--GitHub Actions-->
Expand Down
228 changes: 107 additions & 121 deletions src/Bannerlord.ModuleManager.Models/ApplicationVersion.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
// <auto-generated>
// This code file has automatically been added by the "Bannerlord.ModuleManager.Source" NuGet package (https://www.nuget.org/packages/Bannerlord.ModuleManager.Source).
// Please see https://github.com/BUTR/Bannerlord.ModuleManager for more information.
//
// IMPORTANT:
// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references.
// Consider migrating to PackageReferences instead:
// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
// Migrating brings the following benefits:
// * The "Bannerlord.ModuleManager.Source" folder and the "ApplicationVersion.cs" file don't appear in your project.
// * The added file is immutable and can therefore not be modified by coincidence.
// * Updating/Uninstalling the package will work flawlessly.
// </auto-generated>

#region License
#region License
// MIT License
//
// Copyright (c) Bannerlord's Unofficial Tools & Resources
Expand Down Expand Up @@ -41,133 +27,133 @@
#pragma warning disable
#endif

namespace Bannerlord.ModuleManager
{
using global::System;
namespace Bannerlord.ModuleManager;

using System;

#if !BANNERLORDBUTRMODULEMANAGER_PUBLIC
internal
#else
public
public
# endif
record ApplicationVersion : IComparable<ApplicationVersion>
record ApplicationVersion : IComparable<ApplicationVersion>
{
public static ApplicationVersion Empty { get; } = new();

public ApplicationVersionType ApplicationVersionType { get; set; }
public int Major { get; set; }
public int Minor { get; set; }
public int Revision { get; set; }
public int ChangeSet { get; set; }

public ApplicationVersion() { }
public ApplicationVersion(ApplicationVersionType applicationVersionType, int major, int minor, int revision, int changeSet)
{
public static ApplicationVersion Empty { get; } = new();
ApplicationVersionType = applicationVersionType;
Major = major;
Minor = minor;
Revision = revision;
ChangeSet = changeSet;
}

public ApplicationVersionType ApplicationVersionType { get; set; }
public int Major { get; set; }
public int Minor { get; set; }
public int Revision { get; set; }
public int ChangeSet { get; set; }
public bool IsSame(ApplicationVersion? other) =>
Major == other?.Major && Minor == other.Minor && Revision == other.Revision;

public ApplicationVersion() { }
public ApplicationVersion(ApplicationVersionType applicationVersionType, int major, int minor, int revision, int changeSet)
{
ApplicationVersionType = applicationVersionType;
Major = major;
Minor = minor;
Revision = revision;
ChangeSet = changeSet;
}
public bool IsSameWithChangeSet(ApplicationVersion? other) =>
Major == other?.Major && Minor == other.Minor && Revision == other.Revision && ChangeSet == other.ChangeSet;

public bool IsSame(ApplicationVersion? other) =>
Major == other?.Major && Minor == other.Minor && Revision == other.Revision;
public override string ToString() => $"{GetPrefix(ApplicationVersionType)}{Major}.{Minor}.{Revision}.{ChangeSet}";

public bool IsSameWithChangeSet(ApplicationVersion? other) =>
Major == other?.Major && Minor == other.Minor && Revision == other.Revision && ChangeSet == other.ChangeSet;
public int CompareTo(ApplicationVersion? other) => ApplicationVersionComparer.CompareStandard(this, other);

public override string ToString() => $"{GetPrefix(ApplicationVersionType)}{Major}.{Minor}.{Revision}.{ChangeSet}";
public static bool operator <(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) < 0;
public static bool operator >(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) > 0;
public static bool operator <=(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) <= 0;
public static bool operator >=(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) >= 0;

public int CompareTo(ApplicationVersion? other) => ApplicationVersionComparer.CompareStandard(this, other);
public static char GetPrefix(ApplicationVersionType applicationVersionType) => applicationVersionType switch
{
ApplicationVersionType.Alpha => 'a',
ApplicationVersionType.Beta => 'b',
ApplicationVersionType.EarlyAccess => 'e',
ApplicationVersionType.Release => 'v',
ApplicationVersionType.Development => 'd',
_ => 'i'
};

public static ApplicationVersionType FromPrefix(char applicationVersionType) => applicationVersionType switch
{
'a' => ApplicationVersionType.Alpha,
'b' => ApplicationVersionType.Beta,
'e' => ApplicationVersionType.EarlyAccess,
'v' => ApplicationVersionType.Release,
'd' => ApplicationVersionType.Development,
_ => ApplicationVersionType.Invalid
};

public static bool operator <(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) < 0;
public static bool operator >(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) > 0;
public static bool operator <=(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) <= 0;
public static bool operator >=(ApplicationVersion left, ApplicationVersion right) => left.CompareTo(right) >= 0;
public static bool TryParse(string? versionAsString, out ApplicationVersion version) => TryParse(versionAsString, out version, true);

public static char GetPrefix(ApplicationVersionType applicationVersionType) => applicationVersionType switch
public static bool TryParse(string? versionAsString, out ApplicationVersion version, bool asMin)
{
var major = asMin ? 0 : int.MaxValue;
var minor = asMin ? 0 : int.MaxValue;
var revision = asMin ? 0 : int.MaxValue;
var changeSet = asMin ? 0 : int.MaxValue;
var skipCheck = false;
version = Empty;
if (versionAsString is null)
return false;

var array = versionAsString.Split('.');
if (array.Length != 3 && array.Length != 4 && array[0].Length == 0)
return false;

var applicationVersionType = FromPrefix(array[0][0]);
if (!skipCheck && !int.TryParse(array[0].Substring(1), out major))
{
ApplicationVersionType.Alpha => 'a',
ApplicationVersionType.Beta => 'b',
ApplicationVersionType.EarlyAccess => 'e',
ApplicationVersionType.Release => 'v',
ApplicationVersionType.Development => 'd',
_ => 'i'
};

public static ApplicationVersionType FromPrefix(char applicationVersionType) => applicationVersionType switch
if (array[0].Substring(1) != "*") return false;
major = int.MinValue;
minor = int.MinValue;
revision = int.MinValue;
changeSet = int.MinValue;
skipCheck = true;
}
if (!skipCheck && !int.TryParse(array[1], out minor))
{
'a' => ApplicationVersionType.Alpha,
'b' => ApplicationVersionType.Beta,
'e' => ApplicationVersionType.EarlyAccess,
'v' => ApplicationVersionType.Release,
'd' => ApplicationVersionType.Development,
_ => ApplicationVersionType.Invalid
};

public static bool TryParse(string? versionAsString, out ApplicationVersion version) => TryParse(versionAsString, out version, true);
if (array[1] != "*") return false;
minor = asMin ? 0 : int.MaxValue;
revision = asMin ? 0 : int.MaxValue;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}
if (!skipCheck && !int.TryParse(array[2], out revision))
{
if (array[2] != "*") return false;
revision = asMin ? 0 : int.MaxValue;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}

public static bool TryParse(string? versionAsString, out ApplicationVersion version, bool asMin)
if (!skipCheck && array.Length == 4 && !int.TryParse(array[3], out changeSet))
{
var major = asMin ? 0 : int.MaxValue;
var minor = asMin ? 0 : int.MaxValue;
var revision = asMin ? 0 : int.MaxValue;
var changeSet = asMin ? 0 : int.MaxValue;
var skipCheck = false;
version = Empty;
if (versionAsString is null)
return false;

var array = versionAsString.Split('.');
if (array.Length != 3 && array.Length != 4 && array[0].Length == 0)
return false;

var applicationVersionType = FromPrefix(array[0][0]);
if (!skipCheck && !int.TryParse(array[0].Substring(1), out major))
{
if (array[0].Substring(1) != "*") return false;
major = int.MinValue;
minor = int.MinValue;
revision = int.MinValue;
changeSet = int.MinValue;
skipCheck = true;
}
if (!skipCheck && !int.TryParse(array[1], out minor))
{
if (array[1] != "*") return false;
minor = asMin ? 0 : int.MaxValue;
revision = asMin ? 0 : int.MaxValue;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}
if (!skipCheck && !int.TryParse(array[2], out revision))
{
if (array[2] != "*") return false;
revision = asMin ? 0 : int.MaxValue;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}

if (!skipCheck && array.Length == 4 && !int.TryParse(array[3], out changeSet))
{
if (array[3] != "*") return false;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}

version = new ApplicationVersion
{
ApplicationVersionType = applicationVersionType,
Major = major,
Minor = minor,
Revision = revision,
ChangeSet = changeSet
};

return true;
if (array[3] != "*") return false;
changeSet = asMin ? 0 : int.MaxValue;
skipCheck = true;
}

version = new ApplicationVersion
{
ApplicationVersionType = applicationVersionType,
Major = major,
Minor = minor,
Revision = revision,
ChangeSet = changeSet
};

return true;
}
}

#nullable restore
#if !BANNERLORDBUTRMODULEMANAGER_ENABLE_WARNING
#pragma warning restore
Expand Down
78 changes: 32 additions & 46 deletions src/Bannerlord.ModuleManager.Models/ApplicationVersionComparer.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
// <auto-generated>
// This code file has automatically been added by the "Bannerlord.ModuleManager.Source" NuGet package (https://www.nuget.org/packages/Bannerlord.ModuleManager.Source).
// Please see https://github.com/BUTR/Bannerlord.ModuleManager for more information.
//
// IMPORTANT:
// DO NOT DELETE THIS FILE if you are using a "packages.config" file to manage your NuGet references.
// Consider migrating to PackageReferences instead:
// https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
// Migrating brings the following benefits:
// * The "Bannerlord.ModuleManager.Source" folder and the "ApplicationVersionComparer.cs" file don't appear in your project.
// * The added file is immutable and can therefore not be modified by coincidence.
// * Updating/Uninstalling the package will work flawlessly.
// </auto-generated>

#region License
#region License
// MIT License
//
// Copyright (c) Bannerlord's Unofficial Tools & Resources
Expand Down Expand Up @@ -41,54 +27,54 @@
#pragma warning disable
#endif

namespace Bannerlord.ModuleManager
{
using global::System.Collections;
using global::System.Collections.Generic;
namespace Bannerlord.ModuleManager;

using System.Collections;
using System.Collections.Generic;

#if !BANNERLORDBUTRMODULEMANAGER_PUBLIC
internal
#else
public
public
# endif
class ApplicationVersionComparer : IComparer<ApplicationVersion?>, IComparer
{
/// <inheritdoc/>
public int Compare(object? x, object? y) => Compare(x as ApplicationVersion, y as ApplicationVersion);
class ApplicationVersionComparer : IComparer<ApplicationVersion?>, IComparer
{
/// <inheritdoc/>
public int Compare(object? x, object? y) => Compare(x as ApplicationVersion, y as ApplicationVersion);

/// <inheritdoc/>
public virtual int Compare(ApplicationVersion? x, ApplicationVersion? y) => CompareStandard(x, y);
/// <inheritdoc/>
public virtual int Compare(ApplicationVersion? x, ApplicationVersion? y) => CompareStandard(x, y);

public static int CompareStandard(ApplicationVersion? x, ApplicationVersion? y)
{
if (x is null && y is null)
return 0;
public static int CompareStandard(ApplicationVersion? x, ApplicationVersion? y)
{
if (x is null && y is null)
return 0;

if (x is null)
return -1;
if (x is null)
return -1;

if (y is null)
return 1;
if (y is null)
return 1;

var versionTypeComparison = x.ApplicationVersionType.CompareTo(y.ApplicationVersionType);
if (versionTypeComparison != 0) return versionTypeComparison;
var versionTypeComparison = x.ApplicationVersionType.CompareTo(y.ApplicationVersionType);
if (versionTypeComparison != 0) return versionTypeComparison;

var majorComparison = x.Major.CompareTo(y.Major);
if (majorComparison != 0) return majorComparison;
var majorComparison = x.Major.CompareTo(y.Major);
if (majorComparison != 0) return majorComparison;

var minorComparison = x.Minor.CompareTo(y.Minor);
if (minorComparison != 0) return minorComparison;
var minorComparison = x.Minor.CompareTo(y.Minor);
if (minorComparison != 0) return minorComparison;

var revisionComparison = x.Revision.CompareTo(y.Revision);
if (revisionComparison != 0) return revisionComparison;
var revisionComparison = x.Revision.CompareTo(y.Revision);
if (revisionComparison != 0) return revisionComparison;

var changeSetComparison = x.ChangeSet.CompareTo(y.ChangeSet);
if (changeSetComparison != 0) return changeSetComparison;
var changeSetComparison = x.ChangeSet.CompareTo(y.ChangeSet);
if (changeSetComparison != 0) return changeSetComparison;

return 0;
}
return 0;
}
}

#nullable restore
#if !BANNERLORDBUTRMODULEMANAGER_ENABLE_WARNING
#pragma warning restore
Expand Down
Loading

0 comments on commit 338239e

Please sign in to comment.