From 88874766e0a401c264491fb67cb5392d56cfb39b Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Tue, 30 Aug 2022 12:27:15 +0000 Subject: [PATCH] Highlight incompatible mods recursively --- Core/Registry/IRegistryQuerier.cs | 8 ++++++++ Core/Registry/Registry.cs | 14 ++++++++++++++ GUI/Controls/ModInfo.cs | 14 ++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Core/Registry/IRegistryQuerier.cs b/Core/Registry/IRegistryQuerier.cs index 3d2e1f91d8..c8426f7968 100644 --- a/Core/Registry/IRegistryQuerier.cs +++ b/Core/Registry/IRegistryQuerier.cs @@ -125,6 +125,14 @@ IEnumerable FindReverseDependencies( /// If set to false will not check for provided versions. /// The version of the mod or null if not found ModuleVersion InstalledVersion(string identifier, bool with_provides = true); + + /// + /// Check whether any versions of this mod are installable (including dependencies) on the given game versions + /// + /// Identifier of mod + /// Game versions + /// true if any version is recursively compatible, false otherwise + bool IdentifierCompatible(string identifier, GameVersionCriteria crit); } /// diff --git a/Core/Registry/Registry.cs b/Core/Registry/Registry.cs index dae8a277b5..e03a701fb5 100644 --- a/Core/Registry/Registry.cs +++ b/Core/Registry/Registry.cs @@ -537,6 +537,20 @@ public IEnumerable IncompatibleModules(GameVersionCriteria ksp_versi return sorter.Incompatible.Values.Select(avail => avail.Latest(null)).ToList(); } + /// + /// Check whether any versions of this mod are installable (including dependencies) on the given game versions. + /// Quicker than checking CompatibleModules for one identifier. + /// + /// Identifier of mod + /// Game versions + /// true if any version is recursively compatible, false otherwise + public bool IdentifierCompatible(string identifier, GameVersionCriteria crit) + { + // Set up our compatibility partition + SetCompatibleVersion(crit); + return sorter.Compatible.ContainsKey(identifier); + } + /// /// /// diff --git a/GUI/Controls/ModInfo.cs b/GUI/Controls/ModInfo.cs index 11484c6bec..55a0107d5c 100644 --- a/GUI/Controls/ModInfo.cs +++ b/GUI/Controls/ModInfo.cs @@ -585,7 +585,7 @@ private TreeNode findDependencyShallow(IRegistryQuerier registry, RelationshipDe out CkanModule matched)) { return matched != null - ? indexedNode(registry, matched, relationship, true) + ? indexedNode(registry, matched, relationship, crit) : nonModuleNode(relDescr, null, relationship); } @@ -603,13 +603,13 @@ private TreeNode findDependencyShallow(IRegistryQuerier registry, RelationshipDe && relDescr.ContainsAny(new string[] { dependencyModules[0].identifier })) { // Only one exact match module, return a simple node - return indexedNode(registry, dependencyModules[0], relationship, crit != null); + return indexedNode(registry, dependencyModules[0], relationship, crit); } else { // Several found or not same id, return a "provides" node return providesNode(relDescr.ToString(), relationship, - dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit != null)) + dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit)) ); } } @@ -623,11 +623,11 @@ private IEnumerable ReverseRelationships(IRegistryQuerier registry, Tr compat.SelectMany(otherMod => GetModRelationships(otherMod, relationship) .Where(r => r.MatchesAny(toFind, null, null)) - .Select(r => indexedNode(registry, otherMod, relationship, true))) + .Select(r => indexedNode(registry, otherMod, relationship, crit))) .Concat(incompat.SelectMany(otherMod => GetModRelationships(otherMod, relationship) .Where(r => r.MatchesAny(toFind, null, null)) - .Select(r => indexedNode(registry, otherMod, relationship, false))))); + .Select(r => indexedNode(registry, otherMod, relationship, crit))))); } private TreeNode providesNode(string identifier, RelationshipType relationship, IEnumerable children) @@ -641,9 +641,11 @@ private TreeNode providesNode(string identifier, RelationshipType relationship, }; } - private TreeNode indexedNode(IRegistryQuerier registry, CkanModule module, RelationshipType relationship, bool compatible) + private TreeNode indexedNode(IRegistryQuerier registry, CkanModule module, RelationshipType relationship, GameVersionCriteria crit) { int icon = (int)relationship + 1; + bool compatible = crit == null ? false + : registry.IdentifierCompatible(module.identifier, crit); string suffix = compatible ? "" : $" ({registry.CompatibleGameVersions(manager.CurrentInstance.game, module.identifier)})"; return new TreeNode($"{module.name} {module.version}{suffix}", icon, icon)