Esempio n. 1
0
        public static Dictionary <GUIMod, string> ComputeConflictsFromModList(IRegistryQuerier registry,
                                                                              IEnumerable <ModChange> change_set, KspVersionCriteria ksp_version)
        {
            var modules_to_install = new HashSet <string>();
            var modules_to_remove  = new HashSet <string>();
            var options            = new RelationshipResolverOptions
            {
                without_toomanyprovides_kraken = true,
                proceed_with_inconsistencies   = true,
                without_enforce_consistency    = true,
                with_recommends = false
            };

            foreach (var change in change_set)
            {
                switch (change.ChangeType)
                {
                case GUIModChangeType.None:
                    break;

                case GUIModChangeType.Install:
                    modules_to_install.Add(change.Mod.Identifier);
                    break;

                case GUIModChangeType.Remove:
                    modules_to_remove.Add(change.Mod.Identifier);
                    break;

                case GUIModChangeType.Update:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            // Only check mods that would exist after the changes are made.
            IEnumerable <CkanModule> installed = registry.InstalledModules.Where(
                im => !modules_to_remove.Contains(im.Module.identifier)
                ).Select(im => im.Module);

            // Convert ONLY modules_to_install with CkanModule.FromIDandVersion,
            // because it may not find already-installed modules.
            IEnumerable <CkanModule> mods_to_check = installed.Union(
                modules_to_install.Except(modules_to_remove).Select(
                    name => CkanModule.FromIDandVersion(registry, name, ksp_version)
                    )
                );
            var resolver = new RelationshipResolver(
                mods_to_check,
                change_set.Where(ch => ch.ChangeType == GUIModChangeType.Remove)
                .Select(ch => ch.Mod.ToModule()),
                options, registry, ksp_version
                );

            return(resolver.ConflictList.ToDictionary(item => new GUIMod(item.Key, registry, ksp_version),
                                                      item => item.Value));
        }
Esempio n. 2
0
 /// <summary>
 /// Attempts to convert the module_names to ckan modules via  CkanModule.FromIDandVersion and then calls RelationshipResolver.ctor(IEnumerable{CkanModule}, Registry, KSPVersion)"/>
 /// </summary>
 /// <param name="module_names"></param>
 /// <param name="options"></param>
 /// <param name="registry"></param>
 /// <param name="kspversion"></param>
 public RelationshipResolver(IEnumerable <string> module_names, RelationshipResolverOptions options, IRegistryQuerier registry,
                             KspVersion kspversion) :
     this(module_names.Select(name => CkanModule.FromIDandVersion(registry, name, kspversion)).ToList(),
          options,
          registry,
          kspversion)
 {
     // Does nothing, just calls the other overloaded constructor
 }
Esempio n. 3
0
 public RelationshipResolver(ICollection <string> moduleNames, RelationshipResolverOptions options, Registry registry,
                             KSPVersion kspversion) :
     this(moduleNames.Select(name => CkanModule.FromIDandVersion(registry, name, kspversion)).ToList(),
          options,
          registry,
          kspversion)
 {
     // Does nothing, just calles the other overloaded constructor
 }
Esempio n. 4
0
        /// <summary>
        /// Creates a new resolver that will find a way to install all the modules specified.
        /// </summary>
        public RelationshipResolver(ICollection <string> modules, RelationshipResolverOptions options, Registry registry, KSPVersion kspversion)
        {
            this.registry   = registry;
            this.kspversion = kspversion;

            // Start by figuring out what versions we're installing, and then
            // adding them to the list. This *must* be pre-populated with all
            // user-specified modules, as they may be supplying things that provide
            // virtual packages.

            var user_requested_mods = new List <CkanModule>();

            log.DebugFormat("Processing relationships for {0} modules", modules.Count);

            foreach (string module in modules)
            {
                // Throws ModuleNotFoundKraken if it can't be found
                CkanModule mod = CkanModule.FromIDandVersion(registry, module, kspversion);

                log.DebugFormat("Preparing to resolve relationships for {0} {1}", mod.identifier, mod.version);

                foreach (CkanModule listed_mod in modlist.Values.Where(listed_mod => listed_mod.ConflictsWith(mod)))
                {
                    throw new InconsistentKraken(string.Format("{0} conflicts with {1}, can't install both.", mod, listed_mod));
                }

                user_requested_mods.Add(mod);
                Add(mod);
            }

            // Now that we've already pre-populated modlist, we can resolve
            // the rest of our dependencies.

            foreach (CkanModule module in user_requested_mods)
            {
                log.InfoFormat("Resolving relationships for {0}", module.identifier);
                Resolve(module, options);
            }

            var final_modules = new List <Module>(modlist.Values);

            final_modules.AddRange(registry.InstalledModules.Select(x => x.Module));

            if (!options.without_enforce_consistency)
            {
                // Finally, let's do a sanity check that our solution is actually sane.
                SanityChecker.EnforceConsistency(
                    final_modules,
                    registry.InstalledDlls
                    );
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Translate mods from identifiers in its default or identifier=version format into CkanModules,
 /// optionally falling back to incompatible modules if no compatibles could be found.
 /// </summary>
 /// <param name="name">The identifier or identifier=version of the module</param>
 /// <param name="options">If options.allow_incompatible is set, fall back to searching incompatible modules if no compatible has been found</param>
 /// <param name="registry">CKAN registry object for current game instance</param>
 /// <param name="GameVersion">The current KSP version criteria to consider</param>
 /// <returns>A CkanModule</returns>
 private static CkanModule TranslateModule(string name, RelationshipResolverOptions options, IRegistryQuerier registry, GameVersionCriteria GameVersion)
 {
     if (options.allow_incompatible)
     {
         try
         {
             return(CkanModule.FromIDandVersion(registry, name, GameVersion));
         }
         catch (ModuleNotFoundKraken)
         {
             // No versions found matching our game version, so
             // look for incompatible versions.
             return(CkanModule.FromIDandVersion(registry, name, null));
         }
     }
     else
     {
         return(CkanModule.FromIDandVersion(registry, name, GameVersion));
     }
 }