Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix max version column for wildcard compat #4142

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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