Skip to content

Commit

Permalink
Ignore manually installed duplicates of installed modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 11, 2024
1 parent 3d0e428 commit 7ab6c32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
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

0 comments on commit 7ab6c32

Please sign in to comment.