private TreeNode findDependencyShallow(IRegistryQuerier registry, RelationshipDescriptor relDescr, RelationshipType relationship, KspVersionCriteria crit) { // Maybe it's a DLC? if (relDescr.MatchesAny( registry.InstalledModules.Select(im => im.Module), new HashSet <string>(registry.InstalledDlls), registry.InstalledDlc)) { return(nonModuleNode(relDescr, null, relationship)); } // Find modules that satisfy this dependency List <CkanModule> dependencyModules = relDescr.LatestAvailableWithProvides(registry, crit); if (dependencyModules.Count == 0) { // Nothing found, don't return a node return(null); } else if (dependencyModules.Count == 1 && relDescr.ContainsAny(new string[] { dependencyModules[0].identifier })) { // Only one exact match module, return a simple node return(indexedNode(registry, dependencyModules[0], relationship, crit != null)); } else { // Several found or not same id, return a "provides" node return(providesNode(relDescr.ToString(), relationship, dependencyModules.Select(dep => indexedNode(registry, dep, relationship, crit != null)) )); } }
public override bool Equals(RelationshipDescriptor other) { AnyOfRelationshipDescriptor anyRel = other as AnyOfRelationshipDescriptor; return(anyRel != null && (any_of?.SequenceEqual(anyRel.any_of) ?? anyRel.any_of == null)); }
/// <summary> /// <see cref="IRegistryQuerier.LatestAvailableWithProvides" /> /// </summary> public List <CkanModule> LatestAvailableWithProvides( string identifier, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null, IEnumerable <CkanModule> toInstall = null) { if (providers.TryGetValue(identifier, out HashSet <AvailableModule> provs)) { // For each AvailableModule, we want the latest one matching our constraints return(provs .Select(am => am.Latest( ksp_version, relationship_descriptor, InstalledModules.Select(im => im.Module), toInstall )) .Where(m => m?.ProvidesList?.Contains(identifier) ?? false) .ToList()); } else { // Nothing provides this, return empty list return(new List <CkanModule>()); } }
/// <summary> /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy. /// </summary> /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param> /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param> /// <param name="installed">Modules that are already installed</param> /// <param name="toInstall">Modules that are planned to be installed</param> /// <returns></returns> public CkanModule Latest( GameVersionCriteria ksp_version = null, RelationshipDescriptor relationship = null, IEnumerable <CkanModule> installed = null, IEnumerable <CkanModule> toInstall = null ) { log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count); IEnumerable <CkanModule> modules = module_version.Values.Reverse(); if (relationship != null) { modules = modules.Where(relationship.WithinBounds); } if (ksp_version != null) { modules = modules.Where(m => m.IsCompatibleKSP(ksp_version)); } if (installed != null) { modules = modules.Where(m => DependsAndConflictsOK(m, installed)); } if (toInstall != null) { modules = modules.Where(m => DependsAndConflictsOK(m, toInstall)); } return(modules.FirstOrDefault()); }
public void VersionWithinBounds_vs_AutoDetectedMod(string version) { var rd = new CKAN.RelationshipDescriptor { version = new CKAN.Version(version) }; Assert.True(rd.version_within_bounds(autodetected)); }
public void VersionWithinBounds_ExactFalse(string version, string other_version, bool expected) { var rd = new CKAN.RelationshipDescriptor { version = new CKAN.Version(version) }; Assert.AreEqual(expected, rd.version_within_bounds(new CKAN.Version(other_version))); }
public void VersionWithinBounds_MinMax_vs_AutoDetectedMod(string min, string max) { var rd = new CKAN.RelationshipDescriptor { min_version = new CKAN.Version(min), max_version = new CKAN.Version(max) }; Assert.True(rd.version_within_bounds(autodetected)); }
public void VersionWithinBounds_MinMax(string min, string max, string compare_to, bool expected) { var rd = new CKAN.RelationshipDescriptor { min_version = new CKAN.Version(min), max_version = new CKAN.Version(max) }; Assert.AreEqual(expected, rd.version_within_bounds(new CKAN.Version(compare_to))); }
private TreeNode nonModuleNode(RelationshipDescriptor relDescr, ModuleVersion version, RelationshipType relationship) { int icon = (int)relationship + 1; return(new TreeNode($"{relDescr} {version}", icon, icon) { Name = relDescr.ToString(), ToolTipText = relationship.ToString() }); }
public override bool Equals(RelationshipDescriptor other) { ModuleRelationshipDescriptor modRel = other as ModuleRelationshipDescriptor; return(modRel != null && name == modRel.name && version == modRel.version && min_version == modRel.min_version && max_version == modRel.max_version); }
/// <summary> /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy. /// </summary> /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param> /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param> /// <returns></returns> public CkanModule Latest(KspVersionCriteria ksp_version = null, RelationshipDescriptor relationship = null) { var available_versions = new List <Version>(module_version.Keys); CkanModule module; log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count); log.DebugFormat("Choosing between {0} available versions", available_versions.Count); // Uh oh, nothing available. Maybe this existed once, but not any longer. if (available_versions.Count == 0) { return(null); } // No restrictions? Great, we can just pick the first one! if (ksp_version == null && relationship == null) { module = module_version[available_versions.First()]; log.DebugFormat("No KSP version restriction, {0} is most recent", module); return(module); } // If there's no relationship to satisfy, we can just pick the first that is // compatible with our version of KSP. if (relationship == null) { // Time to check if there's anything that we can satisfy. var version = available_versions.FirstOrDefault(v => module_version[v].IsCompatibleKSP(ksp_version)); if (version != null) { return(module_version[version]); } log.DebugFormat("No version of {0} is compatible with KSP {1}", module_version[available_versions[0]].identifier, ksp_version); return(null); } // If we're here, then we have a relationship to satisfy, so things get more complex. if (ksp_version == null) { var version = available_versions.FirstOrDefault(relationship.version_within_bounds); return(version == null ? null : module_version[version]); } else { var version = available_versions.FirstOrDefault(v => relationship.version_within_bounds(v) && module_version[v].IsCompatibleKSP(ksp_version)); return(version == null ? null : module_version[version]); } }
private TreeNode nonindexedNode(RelationshipDescriptor relDescr, RelationshipType relationship) { // Completely nonexistent dependency, e.g. "AJE" int icon = (int)relationship + 1; return(new TreeNode(string.Format(Properties.Resources.ModInfoNotIndexed, relDescr.ToString()), icon, icon) { Name = relDescr.ToString(), ToolTipText = relationship.ToString(), ForeColor = Color.Red }); }
private TreeNode nonindexedNode(RelationshipDescriptor relDescr, RelationshipType relationship) { // Completely nonexistent dependency, e.g. "AJE" int icon = (int)relationship + 1; return(new TreeNode(relDescr.ToString() + " (not indexed)", icon, icon) { Name = relDescr.ToString(), ToolTipText = relationship.ToString(), ForeColor = Color.Red }); }
/// <summary> /// <see cref = "IRegistryQuerier.LatestAvailable" /> /// </summary> // TODO: Consider making this internal, because practically everything should // be calling LatestAvailableWithProvides() public CkanModule LatestAvailable( string module, KSPVersion ksp_version, RelationshipDescriptor relationship_descriptor = null) { log.DebugFormat("Finding latest available for {0}", module); // TODO: Check user's stability tolerance (stable, unstable, testing, etc) try { return(available_modules[module].Latest(ksp_version, relationship_descriptor)); } catch (KeyNotFoundException) { throw new ModuleNotFoundKraken(module); } }
/// <summary> /// <see cref="IRegistryQuerier.LatestAvailable" /> /// </summary> public CkanModule LatestAvailable( string module, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null) { // TODO: Consider making this internal, because practically everything should // be calling LatestAvailableWithProvides() log.DebugFormat("Finding latest available for {0}", module); // TODO: Check user's stability tolerance (stable, unstable, testing, etc) try { return(available_modules[module].Latest(ksp_version, relationship_descriptor)); } catch (KeyNotFoundException) { throw new ModuleNotFoundKraken(module); } }
/// <summary> /// <see cref="IRegistryQuerier.LatestAvailableWithProvides" /> /// </summary> public List <CkanModule> LatestAvailableWithProvides( string module, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null) { HashSet <AvailableModule> provs; if (providers.TryGetValue(module, out provs)) { // For each AvailableModule, we want the latest one matching our constraints return(provs.Select(am => am.Latest(ksp_version, relationship_descriptor)) .Where(m => m?.ProvidesList?.Contains(module) ?? false) .ToList()); } else { // Nothing provides this, return empty list return(new List <CkanModule>()); } }
/// <summary> /// Find the identifiers that could satisfy this relationship. /// Handles the different types of relationships. /// </summary> /// <param name="rel">Relationship to satisfy</param> /// <returns> /// The identifier for a ModuleRelationshipDescriptor, /// multiple for AnyOfRelationshipDescriptor, /// nothing otherwise. /// </returns> private IEnumerable <string> RelationshipIdentifiers(RelationshipDescriptor rel) { var modRel = rel as ModuleRelationshipDescriptor; if (modRel != null) { yield return(modRel.name); } else { var anyRel = rel as AnyOfRelationshipDescriptor; if (anyRel != null) { foreach (RelationshipDescriptor subRel in anyRel.any_of) { foreach (string name in RelationshipIdentifiers(subRel)) { yield return(name); } } } } }
public abstract bool Same(RelationshipDescriptor other);
public void VersionWithinBounds_Null(string version) { var rd = new CKAN.RelationshipDescriptor(); Assert.True(rd.version_within_bounds(new CKAN.Version(version))); }
/// <summary> /// Returns the latest version of a module that can be installed for /// the given KSP version. This is a *private* method that assumes /// the `available_for_current_version` list has been correctly /// calculated. Not for direct public consumption. ;) /// </summary> private List <CkanModule> LatestAvailableWithProvides(string module, KSPVersion ksp_version, IEnumerable <CkanModule> available_for_current_version, RelationshipDescriptor relationship_descriptor = null) { log.DebugFormat("Finding latest available with provides for {0}", module); // TODO: Check user's stability tolerance (stable, unstable, testing, etc) var modules = new List <CkanModule>(); try { // If we can find the module requested for our KSP, use that. CkanModule mod = LatestAvailable(module, ksp_version, relationship_descriptor); if (mod != null) { modules.Add(mod); } } catch (ModuleNotFoundKraken) { // It's cool if we can't find it, though. } // Walk through all our available modules, and see if anything // provides what we need. // Get our candidate module. We can assume this is non-null, as // if it *is* null then available_for_current_version is corrupted, // and something is terribly wrong. foreach (CkanModule candidate in available_for_current_version) { // Find everything this module provides (for our version of KSP) List <string> provides = candidate.provides; // If the module has provides, and any of them are what we're looking // for, the add it to our list. if (provides != null && provides.Any(provided => provided == module)) { modules.Add(candidate); } } return(modules); }
/// <summary> /// <see cref = "IRegistryQuerier.LatestAvailableWithProvides" /> /// </summary> public List <CkanModule> LatestAvailableWithProvides(string module, KSPVersion ksp_version, RelationshipDescriptor relationship_descriptor = null) { // This public interface calculates a cache of modules which // are compatible with the current version of KSP, and then // calls the private version below for heavy lifting. return(LatestAvailableWithProvides(module, ksp_version, available_modules.Values.Select(pair => pair.Latest(ksp_version)).Where(mod => mod != null).ToArray(), relationship_descriptor)); }
public void VersionWithinBounds_AllNull() { var rd = new CKAN.RelationshipDescriptor(); Assert.True(rd.version_within_bounds(null)); }