Skip to content

Commit

Permalink
Fix max version column for wildcard compat
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 5, 2024
1 parent a37eca5 commit df67878
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions Core/Repositories/AvailableModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Newtonsoft.Json.Serialization;

using CKAN.Versioning;
using CKAN.Extensions;

namespace CKAN
{
Expand Down Expand Up @@ -195,26 +196,21 @@ private static bool DependsAndConflictsOK(CkanModule module, ICollection<CkanMod
/// </summary>
public GameVersion LatestCompatibleGameVersion(List<GameVersion> realVersions)
{
// Cheat slightly for performance:
// Find the CkanModule with the highest ksp_version_max,
// then get the real latest compatible of just that one mod
GameVersion best = null;
CkanModule bestMod = null;
foreach (var mod in module_version.Values)
var ranges = module_version.Values
.Select(m => new GameVersionRange(m.EarliestCompatibleGameVersion(),
m.LatestCompatibleGameVersion()))
.Memoize();
if (ranges.Any(r => r.Upper.Value.IsAny))
{
var v = mod.LatestCompatibleGameVersion();
if (v.IsAny)
{
// Can't get later than Any, so stop
return mod.LatestCompatibleRealGameVersion(realVersions);
}
else if (best == null || best < v)
{
best = v;
bestMod = mod;
}
// Can't get later than Any, so no need for more complex logic
return realVersions.Last();
}
return bestMod.LatestCompatibleRealGameVersion(realVersions);
// Find the range with the highest upper bound
var bestRange = ranges.Distinct()
.Aggregate((best, r) => r.Upper == GameVersionBound.Highest(best.Upper, r.Upper)
? r
: best);
return realVersions.LastOrDefault(v => bestRange.Contains(v));
}

/// <summary>
Expand Down

0 comments on commit df67878

Please sign in to comment.