Skip to content

Commit

Permalink
Check compatibility of providing modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 13, 2020
1 parent 6914c3a commit c28eef9
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Core/Registry/CompatibilitySorter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using log4net;
using CKAN.Extensions;
using CKAN.Versioning;

namespace CKAN
Expand Down Expand Up @@ -30,7 +31,7 @@ Dictionary<string, UnmanagedModuleVersion> dlc
CompatibleVersions = crit;
this.dlls = dlls;
this.dlc = dlc;
PartitionModules(available, providers);
PartitionModules(available, CompatibleProviders(crit, providers));
}

/// <summary>
Expand Down Expand Up @@ -64,11 +65,39 @@ public readonly SortedDictionary<string, AvailableModule> Incompatible
private readonly HashSet<string> dlls;
private readonly Dictionary<string, UnmanagedModuleVersion> dlc;

/// <summary>
/// Filter the provides mapping by compatibility
/// </summary>
/// <param name="crit">Versions to be considered compatible</param>
/// <param name="providers">Mapping from identifiers to mods providing those identifiers</param>
/// <returns>
/// Mapping from identifiers to compatible mods providing those identifiers
/// </returns>
private Dictionary<string, HashSet<AvailableModule>> CompatibleProviders(KspVersionCriteria crit, Dictionary<string, HashSet<AvailableModule>> providers)
{
var compat = new Dictionary<string, HashSet<AvailableModule>>();
foreach (var kvp in providers)
{
// Find providing modules that are compatible with crit
var compatAvail = kvp.Value.Where(avm =>
avm.AllAvailable().Any(ckm =>
ckm.ProvidesList.Contains(kvp.Key) && ckm.IsCompatibleKSP(crit))
).ToHashSet();
// Add compatible providers to mapping, if any
if (compatAvail.Any())
{
compat.Add(kvp.Key, compatAvail);
}
}
return compat;
}

/// <summary>
/// Split the given mods into compatible and incompatible.
/// Handles all levels of dependencies.
/// </summary>
/// <param name="available">All mods available from registry</param>
/// <param name="providers">Mapping from identifiers to mods providing those identifiers</param>
private void PartitionModules(Dictionary<string, AvailableModule> available, Dictionary<string, HashSet<AvailableModule>> providers)
{
// First get the ones that are trivially [in]compatible.
Expand Down Expand Up @@ -106,9 +135,9 @@ private void PartitionModules(Dictionary<string, AvailableModule> available, Dic
/// Move an indeterminate module to Compatible or Incompatible
/// based on its dependencies.
/// </summary>
/// <param name="indeterminate">The collection of indeterminate modules</param>
/// <param name="identifier">Identifier of the module to check</param>
/// <param name="am">The module to check</param>
/// <param name="providers">Mapping from identifiers to mods providing those identifiers</param>
private void CheckDepends(string identifier, AvailableModule am, Dictionary<string, HashSet<AvailableModule>> providers)
{
Investigating.Push(identifier);
Expand Down

0 comments on commit c28eef9

Please sign in to comment.