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 afe87ef
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 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,25 @@ 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?.LastOrDefault()
?? module_version.Values.Select(m => m.LatestCompatibleGameVersion())
.Max();
}
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))
?? module_version.Values.Select(m => m.LatestCompatibleGameVersion())
.Max();
}

/// <summary>
Expand Down

0 comments on commit afe87ef

Please sign in to comment.