Skip to content

Commit

Permalink
Merge #4264 Fix exception when the same module is in multiple repos
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 22, 2024
2 parents 9246150 + d57a514 commit 749fb70
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ All notable changes to this project will be documented in this file.
### Bugfixes

- [GUI] Set focus better on Ctrl+F (#4230 by: HebaruSan)
- [Multiple] Refactor relationship resolver to capture full resolved tree (#4232 by: HebaruSan)
- [Multiple] Refactor relationship resolver to capture full resolved tree (#4232, #4264 by: HebaruSan)
- [GUI] Fix skipping failed dependency downloads (#4235 by: HebaruSan)
- [Core] Fix reporting of wrong download as failed (#4236 by: HebaruSan)
- [Core] Exclude DLLs being upgraded to full modules (#4250 by: HebaruSan)
Expand Down
6 changes: 3 additions & 3 deletions Core/Registry/CompatibilitySorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CompatibilitySorter
/// <param name="dlc">Collection of installed DLCs</param>
public CompatibilitySorter(GameVersionCriteria crit,
IEnumerable<Dictionary<string, AvailableModule>> available,
IDictionary<string, HashSet<AvailableModule>> providers,
IDictionary<string, AvailableModule[]> providers,
IDictionary<string, InstalledModule> installed,
ICollection<string> dlls,
IDictionary<string, ModuleVersion> dlc)
Expand Down Expand Up @@ -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,
IDictionary<string, HashSet<AvailableModule>> providers)
GameVersionCriteria crit,
IDictionary<string, AvailableModule[]> providers)
=> providers
.AsParallel()
.Select(kvp => new KeyValuePair<string, HashSet<AvailableModule>>(
Expand Down
15 changes: 8 additions & 7 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private void EnlistWithTransaction()
// providers[provided] = { provider1, provider2, ... }
// Built by BuildProvidesIndex, makes LatestAvailableWithProvides much faster.
[JsonIgnore]
private Dictionary<string, HashSet<AvailableModule>>? providers;
private Dictionary<string, AvailableModule[]>? providers;

[JsonIgnore]
private IDictionary<string, ModuleVersion>? installedDlc;
Expand Down Expand Up @@ -701,7 +701,7 @@ public string GetAvailableMetadata(string identifier)
/// Generate the providers index so we can find providing modules quicker
/// </summary>
[MemberNotNull(nameof(providers))]
private Dictionary<string, HashSet<AvailableModule>> BuildProvidesIndex()
private Dictionary<string, AvailableModule[]> BuildProvidesIndex()
=> providers = (repoDataMgr?.GetAllAvailableModules(Repositories.Values)
?? Enumerable.Empty<AvailableModule>())
.SelectMany(am => am.AllAvailable()
Expand All @@ -711,7 +711,7 @@ private Dictionary<string, HashSet<AvailableModule>> BuildProvidesIndex()
.GroupBy(tuple => tuple.provided,
tuple => tuple.am)
.ToDictionary(grp => grp.Key,
grp => grp.ToHashSet());
grp => grp.ToArray());

[JsonIgnore]
public Dictionary<string, ModuleTag> Tags
Expand Down Expand Up @@ -770,8 +770,8 @@ private void BuildTagIndex()

public IEnumerable<AvailableModule> AllAvailableByProvides(string identifier)
=> (providers ?? BuildProvidesIndex())
is Dictionary<string, HashSet<AvailableModule>> allProvs
&& allProvs.TryGetValue(identifier, out HashSet<AvailableModule>? provs)
is Dictionary<string, AvailableModule[]> allProvs
&& allProvs.TryGetValue(identifier, out AvailableModule[]? provs)
? provs
: Enumerable.Empty<AvailableModule>();

Expand All @@ -784,13 +784,14 @@ public List<CkanModule> LatestAvailableWithProvides(string ide
ICollection<CkanModule>? installed = null,
ICollection<CkanModule>? toInstall = null)
=> ((providers ?? BuildProvidesIndex())
is Dictionary<string, HashSet<AvailableModule>> allProvs
is Dictionary<string, AvailableModule[]> allProvs
&& Repositories.Values.ToArray() is Repository[] repos
&& allProvs.TryGetValue(identifier, out HashSet<AvailableModule>? provs)
&& allProvs.TryGetValue(identifier, out AvailableModule[]? provs)
// For each AvailableModule, we want the latest one matching our constraints
? provs.Select(am => am.Latest(gameVersion, relationship, installed, toInstall))
.OfType<CkanModule>()
.Where(m => m.ProvidesList.Contains(identifier))
.Distinct()
// Put the most popular one on top
.OrderByDescending(m => repoDataMgr?.GetDownloadCount(repos, m.identifier)
?? 0)
Expand Down
2 changes: 1 addition & 1 deletion Core/Relationships/ResolvedRelationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public override bool Contains(CkanModule mod)

public override bool Unsatisfied()
=> reason is SelectionReason.Depends
&& resolved.Keys.Count(m => !m.IsDLC) == 0;
&& !resolved.Keys.Any(m => !m.IsDLC);

public override bool Unsatisfied(ICollection<CkanModule> installing)
=> reason is SelectionReason.Depends
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/Registry/CompatibilitySorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void Constructor_OverlappingModules_HigherPriorityOverrides(string[] modu
.GetAllAvailableModules(repos)
.GroupBy(am => am.AllAvailable().First().identifier)
.ToDictionary(grp => grp.Key,
grp => grp.ToHashSet());
grp => grp.ToArray());
var installed = new Dictionary<string, InstalledModule>();
var dlls = new Dictionary<string, string>().Keys;
var dlcs = new Dictionary<string, ModuleVersion>();
Expand Down

0 comments on commit 749fb70

Please sign in to comment.