Skip to content

Commit

Permalink
Merge #3139 Don't fail modpack export when having unindexed mods inst…
Browse files Browse the repository at this point in the history
…alled
  • Loading branch information
HebaruSan committed Nov 6, 2020
2 parents a1b6d6a + 68835a1 commit f11d8b0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
- [GUI] Print message for unknown install exception (#3164 by: DasSkelett; reviewed: HebaruSan)
- [GUI] Search timer for Linux (#3167 by: HebaruSan; reviewed: DasSkelett)
- [ConsoleUI] ConsoleUI fixes for DLC (#3165 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Don't fail modpack export when having unindexed mods installed (#3139 by: DasSkelett, HebaruSan; reviewed: HebaruSan, DasSkelett)

### Internal

Expand Down
2 changes: 1 addition & 1 deletion Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ IEnumerable<string> FindReverseDependencies(
/// This includes DLLs, which will have a version type of `DllVersion`.
/// This includes Provides if set, which will have a version of `ProvidesVersion`.
/// </summary>
Dictionary<string, ModuleVersion> Installed(bool include_provides = true);
Dictionary<string, ModuleVersion> Installed(bool withProvides = true, bool withDLLs = true);

/// <summary>
/// Returns the InstalledModule, or null if it is not installed.
Expand Down
29 changes: 17 additions & 12 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,20 +905,23 @@ public void ClearDlc()
/// <summary>
/// <see cref = "IRegistryQuerier.Installed" />
/// </summary>
public Dictionary<string, ModuleVersion> Installed(bool withProvides = true)
public Dictionary<string, ModuleVersion> Installed(bool withProvides = true, bool withDLLs = true)
{
var installed = new Dictionary<string, ModuleVersion>();

// 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;
}
Expand Down Expand Up @@ -949,14 +952,16 @@ public InstalledModule InstalledModule(string module)
}

/// <summary>
/// Returns a dictionary of provided (virtual) modules, and a
/// ProvidesVersion indicating what provides them.
/// Find modules provided by currently installed modules
/// </summary>

// TODO: In the future it would be nice to cache this list, and mark it for rebuild
// if our installed modules change.
internal Dictionary<string, ProvidesModuleVersion> Provided()
/// <returns>
/// Dictionary of provided (virtual) modules and a
/// ProvidesVersion indicating what provides them
/// </returns>
internal Dictionary<string, ProvidesModuleVersion> 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<string, ProvidesModuleVersion>();

foreach (var modinfo in installed_modules)
Expand Down Expand Up @@ -1002,7 +1007,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;
Expand Down
15 changes: 13 additions & 2 deletions Core/Registry/RegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,19 @@ public CkanModule GenerateModpack(bool recommends = false, bool with_versions =
download_content_type = "application/zip",
};

List<RelationshipDescriptor> mods = registry.Installed()
.Where(mod => !(mod.Value is ProvidesModuleVersion || mod.Value is UnmanagedModuleVersion))
List<RelationshipDescriptor> 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,
Expand Down
20 changes: 17 additions & 3 deletions GUI/Controls/EditModpack.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -92,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);
Expand All @@ -118,7 +130,9 @@ private void AddGroup(List<RelationshipDescriptor> 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,
Expand Down
10 changes: 0 additions & 10 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f11d8b0

Please sign in to comment.