From 5214fd7bb7b5b0fb335a047ea438d3751f77a0dc Mon Sep 17 00:00:00 2001 From: DasSkelett Date: Tue, 11 Aug 2020 18:48:01 +0200 Subject: [PATCH 1/2] Don't fail modpack export with unindexed mods --- GUI/Controls/EditModpack.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GUI/Controls/EditModpack.cs b/GUI/Controls/EditModpack.cs index 8d457c8637..4e1534ed6f 100644 --- a/GUI/Controls/EditModpack.cs +++ b/GUI/Controls/EditModpack.cs @@ -1,10 +1,8 @@ using System; -using System.IO; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; -using System.Text.RegularExpressions; using Autofac; using CKAN.Versioning; using CKAN.GameVersionProviders; @@ -118,7 +116,9 @@ private void AddGroup(List relationships, ListViewGroup { (r as ModuleRelationshipDescriptor)?.name, (r as ModuleRelationshipDescriptor)?.version?.ToString(), - registry.LatestAvailable((r as ModuleRelationshipDescriptor)?.name, null, null)?.@abstract + registry.InstalledModules.First( + im => im.identifier == (r as ModuleRelationshipDescriptor)?.name + )?.Module.@abstract }) { Tag = r, From 68835a12af540f3a5f4ce256da2132773578c349 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Fri, 2 Oct 2020 14:44:03 -0500 Subject: [PATCH 2/2] Put unindexed mods in Ignored modpack group --- Core/Registry/IRegistryQuerier.cs | 2 +- Core/Registry/Registry.cs | 29 +++++++++++++++++------------ Core/Registry/RegistryManager.cs | 15 +++++++++++++-- GUI/Controls/EditModpack.cs | 14 ++++++++++++++ GUI/Main/Main.cs | 10 ---------- 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Core/Registry/IRegistryQuerier.cs b/Core/Registry/IRegistryQuerier.cs index 796cc71f33..121ceb75e7 100644 --- a/Core/Registry/IRegistryQuerier.cs +++ b/Core/Registry/IRegistryQuerier.cs @@ -116,7 +116,7 @@ IEnumerable FindReverseDependencies( /// This includes DLLs, which will have a version type of `DllVersion`. /// This includes Provides if set, which will have a version of `ProvidesVersion`. /// - Dictionary Installed(bool include_provides = true); + Dictionary Installed(bool withProvides = true, bool withDLLs = true); /// /// Returns the InstalledModule, or null if it is not installed. diff --git a/Core/Registry/Registry.cs b/Core/Registry/Registry.cs index 7c33961cd6..eadf5bc249 100644 --- a/Core/Registry/Registry.cs +++ b/Core/Registry/Registry.cs @@ -904,20 +904,23 @@ public void ClearDlc() /// /// /// - public Dictionary Installed(bool withProvides = true) + public Dictionary Installed(bool withProvides = true, bool withDLLs = true) { var installed = new Dictionary(); - // Index our DLLs, as much as we dislike them. - foreach (var dllinfo in installed_dlls) + if (withDLLs) { - installed[dllinfo.Key] = new UnmanagedModuleVersion(null); + // Index our DLLs, as much as we dislike them. + foreach (var dllinfo in installed_dlls) + { + installed[dllinfo.Key] = new UnmanagedModuleVersion(null); + } } // Index our provides list, so users can see virtual packages if (withProvides) { - foreach (var provided in Provided()) + foreach (var provided in ProvidedByInstalled()) { installed[provided.Key] = provided.Value; } @@ -948,14 +951,16 @@ public InstalledModule InstalledModule(string module) } /// - /// Returns a dictionary of provided (virtual) modules, and a - /// ProvidesVersion indicating what provides them. + /// Find modules provided by currently installed modules /// - - // TODO: In the future it would be nice to cache this list, and mark it for rebuild - // if our installed modules change. - internal Dictionary Provided() + /// + /// Dictionary of provided (virtual) modules and a + /// ProvidesVersion indicating what provides them + /// + internal Dictionary ProvidedByInstalled() { + // TODO: In the future it would be nice to cache this list, and mark it for rebuild + // if our installed modules change. var installed = new Dictionary(); foreach (var modinfo in installed_modules) @@ -1001,7 +1006,7 @@ public ModuleVersion InstalledVersion(string modIdentifier, bool with_provides=t // withProvides is false. if (!with_provides) return null; - var provided = Provided(); + var provided = ProvidedByInstalled(); ProvidesModuleVersion version; return provided.TryGetValue(modIdentifier, out version) ? version : null; diff --git a/Core/Registry/RegistryManager.cs b/Core/Registry/RegistryManager.cs index f88b19eed9..bccb0bac37 100644 --- a/Core/Registry/RegistryManager.cs +++ b/Core/Registry/RegistryManager.cs @@ -449,8 +449,19 @@ public CkanModule GenerateModpack(bool recommends = false, bool with_versions = download_content_type = "application/zip", }; - List mods = registry.Installed() - .Where(mod => !(mod.Value is ProvidesModuleVersion || mod.Value is UnmanagedModuleVersion)) + List mods = registry.Installed(false, false) + .Where(kvp => { + // Skip unavailable modules (custom .ckan files) + try + { + var avail = registry.LatestAvailable(kvp.Key, null, null); + return true; + } + catch + { + return false; + } + }) .Select(kvp => (RelationshipDescriptor) new ModuleRelationshipDescriptor() { name = kvp.Key, diff --git a/GUI/Controls/EditModpack.cs b/GUI/Controls/EditModpack.cs index 4e1534ed6f..3776c001fd 100644 --- a/GUI/Controls/EditModpack.cs +++ b/GUI/Controls/EditModpack.cs @@ -90,6 +90,20 @@ private void LoadRelationships(IRegistryQuerier registry) } ignored.Clear(); + // Find installed modules that aren't in the module's relationships + ignored.AddRange(registry.Installed(false, false) + .Where(kvp => { + var ids = new string[] { kvp.Key }; + return !module.depends.Any(rel => rel.ContainsAny(ids)) + && !module.recommends.Any(rel => rel.ContainsAny(ids)) + && !module.suggests.Any(rel => rel.ContainsAny(ids)); + }) + .Select(kvp => (RelationshipDescriptor) new ModuleRelationshipDescriptor() + { + name = kvp.Key, + version = kvp.Value, + }) + ); RelationshipsListView.Items.Clear(); AddGroup(module.depends, DependsGroup, registry); AddGroup(module.recommends, RecommendationsGroup, registry); diff --git a/GUI/Main/Main.cs b/GUI/Main/Main.cs index 7d09994666..266d54802f 100644 --- a/GUI/Main/Main.cs +++ b/GUI/Main/Main.cs @@ -521,16 +521,6 @@ private void installFromckanToolStripMenuItem_Click(object sender, EventArgs e) continue; } - // Don't add metapacakges to the registry - if (!module.IsMetapackage) - { - // Remove this version of the module in the registry, if it exists. - registry_manager.registry.RemoveAvailable(module); - - // Sneakily add our version in... - registry_manager.registry.AddAvailable(module); - } - if (module.IsDLC) { currentUser.RaiseError(Properties.Resources.MainCantInstallDLC, module);