From c28eef95373bc03cedd0d972f1a742e215510053 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Thu, 13 Feb 2020 10:56:39 -0600 Subject: [PATCH] Check compatibility of providing modules --- Core/Registry/CompatibilitySorter.cs | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Core/Registry/CompatibilitySorter.cs b/Core/Registry/CompatibilitySorter.cs index 8bf20f1e59..43ae86f6df 100644 --- a/Core/Registry/CompatibilitySorter.cs +++ b/Core/Registry/CompatibilitySorter.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using log4net; +using CKAN.Extensions; using CKAN.Versioning; namespace CKAN @@ -30,7 +31,7 @@ Dictionary dlc CompatibleVersions = crit; this.dlls = dlls; this.dlc = dlc; - PartitionModules(available, providers); + PartitionModules(available, CompatibleProviders(crit, providers)); } /// @@ -64,11 +65,39 @@ public readonly SortedDictionary Incompatible private readonly HashSet dlls; private readonly Dictionary dlc; + /// + /// Filter the provides mapping by compatibility + /// + /// Versions to be considered compatible + /// Mapping from identifiers to mods providing those identifiers + /// + /// Mapping from identifiers to compatible mods providing those identifiers + /// + private Dictionary> CompatibleProviders(KspVersionCriteria crit, Dictionary> providers) + { + var compat = new Dictionary>(); + foreach (var kvp in providers) + { + // Find providing modules that are compatible with crit + var compatAvail = kvp.Value.Where(avm => + avm.AllAvailable().Any(ckm => + ckm.ProvidesList.Contains(kvp.Key) && ckm.IsCompatibleKSP(crit)) + ).ToHashSet(); + // Add compatible providers to mapping, if any + if (compatAvail.Any()) + { + compat.Add(kvp.Key, compatAvail); + } + } + return compat; + } + /// /// Split the given mods into compatible and incompatible. /// Handles all levels of dependencies. /// /// All mods available from registry + /// Mapping from identifiers to mods providing those identifiers private void PartitionModules(Dictionary available, Dictionary> providers) { // First get the ones that are trivially [in]compatible. @@ -106,9 +135,9 @@ private void PartitionModules(Dictionary available, Dic /// Move an indeterminate module to Compatible or Incompatible /// based on its dependencies. /// - /// The collection of indeterminate modules /// Identifier of the module to check /// The module to check + /// Mapping from identifiers to mods providing those identifiers private void CheckDepends(string identifier, AvailableModule am, Dictionary> providers) { Investigating.Push(identifier);