public void Export(IRegistryQuerier registry, Stream stream) { string description = "Saved CFAN mods from " + DateTime.Now.ToLongDateString(); CfanJson metaCfan = CfanGenerator.createEmptyMetaCfanJson("saved-cfan-mods", "Saved CFAN mods", new ModVersion("0.0.0"), "CFAN user", description); metaCfan.modInfo.dependencies = registry.Installed(false).Select(p => new ModDependency(withVersions ? p.Key + " == " + p.Value : p.Key)).ToArray(); string cfanJsonString = JsonConvert.SerializeObject(metaCfan); using (var writer = new StreamWriter(stream)) { writer.Write(cfanJsonString); } }
public static Dictionary <GUIMod, string> ComputeConflictsFromModList(IRegistryQuerier registry, IEnumerable <ModChange> change_set, FactorioVersion ksp_version) { var modules_to_install = new HashSet <string>(); var modules_to_remove = new HashSet <string>(); var options = new RelationshipResolverOptions { without_toomanyprovides_kraken = true, procede_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(); } } var installed = registry.Installed() .Where(pair => pair.Value.CompareTo(new ProvidedVersion("", "0.0.0")) != 0) .Select(pair => pair.Key); //We wish to only check mods that would exist after the changes are made. var mods_to_check = installed.Union(modules_to_install).Except(modules_to_remove).Select(p => new CfanModuleIdAndVersion(p)); var resolver = new RelationshipResolver(mods_to_check.ToList(), options, registry, ksp_version); return(resolver.ConflictList.ToDictionary(item => new GUIMod(item.Key, registry, ksp_version), item => item.Value)); }
private void LoadRelationships(IRegistryQuerier registry) { if (module.depends == null) { module.depends = new List <RelationshipDescriptor>(); } if (module.recommends == null) { module.recommends = new List <RelationshipDescriptor>(); } if (module.suggests == null) { module.suggests = new List <RelationshipDescriptor>(); } ignored.Clear(); // Find installed modules that aren't in the module's relationships ignored.AddRange(registry.Installed(false, false) .Where(kvp => { var ids = new string[] { kvp.Key }; return(!module.depends.Any(rel => rel.ContainsAny(ids)) && !module.recommends.Any(rel => rel.ContainsAny(ids)) && !module.suggests.Any(rel => rel.ContainsAny(ids))); }) .Select(kvp => (RelationshipDescriptor) new ModuleRelationshipDescriptor() { name = kvp.Key, version = kvp.Value, }) ); RelationshipsListView.Items.Clear(); AddGroup(module.depends, DependsGroup, registry); AddGroup(module.recommends, RecommendationsGroup, registry); AddGroup(module.suggests, SuggestionsGroup, registry); AddGroup(ignored, IgnoredGroup, registry); RelationshipsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); GroupToRelationships.Clear(); GroupToRelationships.Add(DependsGroup, module.depends); GroupToRelationships.Add(RecommendationsGroup, module.recommends); GroupToRelationships.Add(SuggestionsGroup, module.suggests); GroupToRelationships.Add(IgnoredGroup, ignored); RelationshipsListView_ItemSelectionChanged(null, null); }
public int RunCommand(CKAN.KSP ksp, object raw_options) { ListOptions options = (ListOptions)raw_options; IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; ExportFileType?exportFileType = null; if (!string.IsNullOrWhiteSpace(options.export)) { exportFileType = GetExportFileType(options.export); if (exportFileType == null) { user.RaiseError("Unknown export format: {0}", options.export); } } if (!(options.porcelain) && exportFileType == null) { user.RaiseMessage("\r\nKSP found at {0}\r\n", ksp.GameDir()); user.RaiseMessage("KSP Version: {0}\r\n", ksp.Version()); user.RaiseMessage("Installed Modules:\r\n"); } if (exportFileType == null) { var installed = new SortedDictionary <string, Version>(registry.Installed()); foreach (KeyValuePair <string, Version> mod in installed) { Version current_version = mod.Value; string bullet = "*"; if (current_version is ProvidesVersion) { // Skip virtuals for now. continue; } else if (current_version is DllVersion) { // Autodetected dll bullet = "-"; } else { try { // Check if upgrades are available, and show appropriately. CkanModule latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria()); log.InfoFormat("Latest {0} is {1}", mod.Key, latest); if (latest == null) { // Not compatible! bullet = "X"; } else if (latest.version.IsEqualTo(current_version)) { // Up to date bullet = "-"; } else if (latest.version.IsGreaterThan(mod.Value)) { // Upgradable bullet = "^"; } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but no longer in the registry", mod.Key); bullet = "?"; } } user.RaiseMessage("{0} {1} {2}", bullet, mod.Key, mod.Value); } } else { var stream = Console.OpenStandardOutput(); new Exporter(exportFileType.Value).Export(registry, stream); stream.Flush(); } if (!(options.porcelain) && exportFileType == null) { user.RaiseMessage("\r\nLegend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown. *: Broken. "); // Broken mods are in a state that CKAN doesn't understand, and therefore can't handle automatically } return(Exit.OK); }
// Uninstalls a module, if it exists. public int RunCommand(CKAN.KSP ksp, object raw_options) { RemoveOptions options = (RemoveOptions)raw_options; // Use one (or more!) regex to select the modules to remove if (options.regex) { log.Debug("Attempting Regex"); // Parse every "module" as a grumpy regex var justins = options.modules.Select(s => new Regex(s)); // Modules that have been selected by one regex List <string> selectedModules = new List <string>(); // Get the list of installed modules IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; var installed = new SortedDictionary <string, Version>(registry.Installed(false)); // Try every regex on every installed module: // if it matches, select for removal foreach (string mod in installed.Keys) { if (justins.Any(re => re.IsMatch(mod))) { selectedModules.Add(mod); } } // Replace the regular expressions with the selected modules // and continue removal as usual options.modules = selectedModules; } if (options.rmall) { log.Debug("Removing all mods"); // Get the list of installed modules IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; var installed = new SortedDictionary <string, Version>(registry.Installed(false)); // Add it to the list that should be uninstalled. options.modules.AddRange(installed.Keys); } if (options.modules != null && options.modules.Count > 0) { try { var installer = ModuleInstaller.GetInstance(ksp, user); installer.UninstallList(options.modules); } catch (ModNotInstalledKraken kraken) { user.RaiseMessage("I can't do that, {0} isn't installed.", kraken.mod); user.RaiseMessage("Try `ckan list` for a list of installed mods."); return(Exit.BADOPT); } } else { user.RaiseMessage("No mod selected, nothing to do"); return(Exit.BADOPT); } return(Exit.OK); }
public static Dictionary<GUIMod, string> ComputeConflictsFromModList(IRegistryQuerier registry, IEnumerable<ModChange> change_set, KSPVersion ksp_version) { var modules_to_install = new HashSet<string>(); var modules_to_remove = new HashSet<string>(); var options = new RelationshipResolverOptions { without_toomanyprovides_kraken = true, procede_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(); } } var installed = registry.Installed() .Where(pair => pair.Value.CompareTo(new ProvidesVersion("")) != 0) .Select(pair => pair.Key); //We wish to only check mods that would exist after the changes are made. var mods_to_check = installed.Union(modules_to_install).Except(modules_to_remove); var resolver = new RelationshipResolver(mods_to_check.ToList(), options, registry, ksp_version); return resolver.ConflictList.ToDictionary(item => new GUIMod(item.Key, registry, ksp_version), item => item.Value); }