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

Ignore manually installed duplicates of installed modules #4257

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions Core/Registry/CompatibilitySorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class CompatibilitySorter
/// <param name="dlc">Collection of installed DLCs</param>
public CompatibilitySorter(GameVersionCriteria crit,
IEnumerable<Dictionary<string, AvailableModule>> available,
Dictionary<string, HashSet<AvailableModule>> providers,
Dictionary<string, InstalledModule> installed,
IDictionary<string, HashSet<AvailableModule>> providers,
IDictionary<string, InstalledModule> installed,
ICollection<string> dlls,
IDictionary<string, ModuleVersion> dlc)
{
Expand Down Expand Up @@ -103,9 +103,9 @@ public ICollection<CkanModule> LatestIncompatible
}
}

private readonly Dictionary<string, InstalledModule> installed;
private readonly ICollection<string> dlls;
private readonly IDictionary<string, ModuleVersion> dlc;
private readonly IDictionary<string, InstalledModule> installed;
private readonly ICollection<string> dlls;
private readonly IDictionary<string, ModuleVersion> dlc;

private List<CkanModule>? latestCompatible;
private List<CkanModule>? latestIncompatible;
Expand All @@ -119,8 +119,8 @@ public ICollection<CkanModule> LatestIncompatible
/// Mapping from identifiers to compatible mods providing those identifiers
/// </returns>
private static Dictionary<string, HashSet<AvailableModule>> CompatibleProviders(
GameVersionCriteria crit,
Dictionary<string, HashSet<AvailableModule>> providers)
GameVersionCriteria crit,
IDictionary<string, HashSet<AvailableModule>> providers)
=> providers
.AsParallel()
.Select(kvp => new KeyValuePair<string, HashSet<AvailableModule>>(
Expand Down
27 changes: 15 additions & 12 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class Registry : IEnlistmentNotification, IRegistryQuerier

[JsonProperty]
[JsonConverter(typeof(JsonParallelDictionaryConverter<InstalledModule>))]
private readonly Dictionary<string, InstalledModule> installed_modules;
private readonly IDictionary<string, InstalledModule> installed_modules;

// filename (case insensitive on Windows) => module
[JsonProperty]
private Dictionary<string, string> installed_files;
private IDictionary<string, string> installed_files;

/// <summary>
/// Returns all the activated registries.
Expand All @@ -55,9 +55,8 @@ public class Registry : IEnlistmentNotification, IRegistryQuerier
/// </summary>
[JsonIgnore]
public ReadOnlyDictionary<string, Repository> Repositories
=> repositories is not null
? new ReadOnlyDictionary<string, Repository>(repositories)
: new ReadOnlyDictionary<string, Repository>(new Dictionary<string, Repository>());
=> new ReadOnlyDictionary<string, Repository>(repositories
?? new SortedDictionary<string, Repository>());

/// <summary>
/// Wrapper around assignment to this.repositories that invalidates
Expand Down Expand Up @@ -342,9 +341,9 @@ private Registry(RepositoryDataManager? repoData)
}

public Registry(RepositoryDataManager? repoData,
Dictionary<string, InstalledModule> installed_modules,
IDictionary<string, InstalledModule> installed_modules,
Dictionary<string, string> installed_dlls,
Dictionary<string, string> installed_files,
IDictionary<string, string> installed_files,
SortedDictionary<string, Repository> repositories)
: this(repoData)
{
Expand Down Expand Up @@ -857,8 +856,9 @@ public void RegisterModule(CkanModule mod,
installed_files[file] = mod.identifier;
}

// Make sure mod-owned files aren't in the manually installed DLL dict
installed_dlls.RemoveWhere(kvp => relativeFiles.Contains(kvp.Value));
// Make sure this mod and its files aren't in the manually installed DLL dict
installed_dlls.RemoveWhere(kvp => kvp.Key == mod.identifier
|| relativeFiles.Contains(kvp.Value));

// Finally register our module proper
installed_modules.Add(mod.identifier,
Expand Down Expand Up @@ -916,9 +916,12 @@ public void DeregisterModule(GameInstance inst, string identifier)
/// Does nothing if we already have this data.
/// </summary>
/// <param name="dlls">Mapping from identifier to relative path</param>
public bool SetDlls(Dictionary<string, string> dlls)
public bool SetDlls(IDictionary<string, string> dlls)
{
var unregistered = dlls.Where(kvp => !installed_files.ContainsKey(kvp.Value))
var instIdents = InstalledModules.Select(im => im.identifier)
.ToHashSet();
var unregistered = dlls.Where(kvp => !instIdents.Contains(kvp.Key)
&& !installed_files.ContainsKey(kvp.Value))
.ToDictionary();
if (!unregistered.DictionaryEquals(installed_dlls))
{
Expand All @@ -930,7 +933,7 @@ public bool SetDlls(Dictionary<string, string> dlls)
return false;
}

public bool SetDlcs(Dictionary<string, ModuleVersion> dlcs)
public bool SetDlcs(IDictionary<string, ModuleVersion> dlcs)
{
var installed = InstalledDlc;
if (!dlcs.DictionaryEquals(installed))
Expand Down