Skip to content

Commit

Permalink
Exclude DLLs being upgraded to full modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 6, 2024
1 parent 2895a45 commit e996806
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 9 additions & 3 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ public RelationshipResolver(IEnumerable<CkanModule> modulesToInstall,
}

var toInst = modulesToInstall.ToArray();
resolved = new ResolvedRelationshipsTree(toInst, registry,
// DLLs that we are upgrading to full modules should be excluded
dlls = registry.InstalledDlls
.Except(modulesToInstall.Select(m => m.identifier))
.ToHashSet();
resolved = new ResolvedRelationshipsTree(toInst, registry, dlls,
installed_modules, versionCrit,
options.OptionalHandling());
if (!options.proceed_with_inconsistencies)
Expand Down Expand Up @@ -127,7 +131,7 @@ private void AddModulesToInstall(CkanModule[] modules)
{
// Check that our solution is actually sane
SanityChecker.EnforceConsistency(modlist.Values.Concat(installed_modules),
registry.InstalledDlls,
dlls,
registry.InstalledDlc);
}
catch (BadRelationshipsKraken k) when (options.without_enforce_consistency)
Expand Down Expand Up @@ -276,7 +280,7 @@ private void ResolveStanza(List<RelationshipDescriptor>? stanza,

// If it's already installed, skip.
if (descriptor.MatchesAny(installed_modules,
registry.InstalledDlls,
dlls,
registry.InstalledDlc,
out CkanModule? installedCandidate))
{
Expand Down Expand Up @@ -649,6 +653,8 @@ private void AddReason(CkanModule module, SelectionReason reason)
private readonly Dictionary<CkanModule, List<SelectionReason>> reasons =
new Dictionary<CkanModule, List<SelectionReason>>();

private readonly HashSet<string> dlls;

/// <summary>
/// Depends relationships with suppress_recommendations=true,
/// to be applied to all recommendations and suggestions
Expand Down
3 changes: 2 additions & 1 deletion Core/Relationships/ResolvedRelationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ public ResolvedByNew(CkanModule source,
ICollection<CkanModule> definitelyInstalling,
ICollection<CkanModule> allInstalling,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels,
RelationshipCache relationshipCache)
: this(source, relationship, reason,
providers.ToDictionary(prov => prov,
prov => ResolvedRelationshipsTree.ResolveModule(
prov, definitelyInstalling, allInstalling, registry, installed, crit,
prov, definitelyInstalling, allInstalling, registry, dlls, installed, crit,
relationship.suppress_recommendations
? optRels & ~OptionalRelationships.Recommendations
& ~OptionalRelationships.Suggestions
Expand Down
21 changes: 13 additions & 8 deletions Core/Relationships/ResolvedRelationshipsTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,33 @@ public class ResolvedRelationshipsTree
{
public ResolvedRelationshipsTree(ICollection<CkanModule> modules,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels)
{
resolved = ResolveManyCached(modules, registry, installed, crit, optRels, relationshipCache).ToArray();
resolved = ResolveManyCached(modules, registry, dlls, installed, crit, optRels, relationshipCache).ToArray();
}

public static IEnumerable<ResolvedRelationship> ResolveModule(CkanModule module,
ICollection<CkanModule> definitelyInstalling,
ICollection<CkanModule> allInstalling,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels,
RelationshipCache relationshipCache)
=> ResolveRelationships(module, module.depends, new SelectionReason.Depends(module),
definitelyInstalling, allInstalling, registry, installed, crit, optRels, relationshipCache)
definitelyInstalling, allInstalling, registry, dlls, installed, crit, optRels, relationshipCache)
.Concat((optRels & OptionalRelationships.Recommendations) == 0
? Enumerable.Empty<ResolvedRelationship>()
: ResolveRelationships(module, module.recommends, new SelectionReason.Recommended(module, 0),
definitelyInstalling, allInstalling, registry, installed, crit, optRels, relationshipCache))
definitelyInstalling, allInstalling, registry, dlls, installed, crit, optRels, relationshipCache))
.Concat((optRels & OptionalRelationships.Suggestions) == 0
? Enumerable.Empty<ResolvedRelationship>()
: ResolveRelationships(module, module.suggests, new SelectionReason.Suggested(module),
definitelyInstalling, allInstalling, registry, installed, crit, optRels, relationshipCache));
definitelyInstalling, allInstalling, registry, dlls, installed, crit, optRels, relationshipCache));

public IEnumerable<ResolvedRelationship[]> Unsatisfied()
=> resolved.SelectMany(UnsatisfiedFrom);
Expand Down Expand Up @@ -102,11 +104,12 @@ public override string ToString()

private static IEnumerable<ResolvedRelationship> ResolveManyCached(ICollection<CkanModule> modules,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels,
RelationshipCache relationshipCache)
=> modules.SelectMany(m => ResolveModule(m, modules, modules, registry, installed, crit, optRels,
=> modules.SelectMany(m => ResolveModule(m, modules, modules, registry, dlls, installed, crit, optRels,
relationshipCache));

private static IEnumerable<ResolvedRelationship> ResolveRelationships(CkanModule module,
Expand All @@ -115,12 +118,13 @@ private static IEnumerable<ResolvedRelationship> ResolveRelationships(CkanModule
ICollection<CkanModule> definitelyInstalling,
ICollection<CkanModule> allInstalling,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels,
RelationshipCache relationshipCache)
=> relationships?.Select(dep => Resolve(module, dep, reason,
definitelyInstalling, allInstalling, registry, installed,
definitelyInstalling, allInstalling, registry, dlls, installed,
crit, optRels, relationshipCache))
?? Enumerable.Empty<ResolvedRelationship>();

Expand All @@ -130,14 +134,15 @@ private static ResolvedRelationship Resolve(CkanModule source,
ICollection<CkanModule> definitelyInstalling,
ICollection<CkanModule> allInstalling,
IRegistryQuerier registry,
ICollection<string> dlls,
ICollection<CkanModule> installed,
GameVersionCriteria crit,
OptionalRelationships optRels,
RelationshipCache relationshipCache)
=> relationshipCache.TryGetValue(relationship,
out ResolvedRelationship? cachedRel)
? cachedRel.WithSource(source, reason)
: relationship.MatchesAny(installed, registry.InstalledDlls, registry.InstalledDlc,
: relationship.MatchesAny(installed, dlls, registry.InstalledDlc,
out CkanModule? installedMatch)
? relationshipCache.GetOrAdd(
relationship,
Expand All @@ -156,7 +161,7 @@ private static ResolvedRelationship Resolve(CkanModule source,
installed, definitelyInstalling),
definitelyInstalling,
allInstalling.Append(source).ToArray(),
registry, installed, crit, optRels,
registry, dlls, installed, crit, optRels,
relationshipCache));

private readonly ResolvedRelationship[] resolved;
Expand Down

0 comments on commit e996806

Please sign in to comment.