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); }
/// <summary> /// Updates the repository. /// </summary> /// <param name="ksp">The KSP instance to work on.</param> /// <param name="repository">Repository to update. If null all repositories are used.</param> private void UpdateRepository(CKAN.KSP ksp, string repository = null) { RegistryManager registry_manager = RegistryManager.Instance(ksp); var updated = repository == null ? CKAN.Repo.UpdateAllRepositories(registry_manager, ksp, manager.Cache, user) != CKAN.RepoUpdateResult.Failed : CKAN.Repo.Update(registry_manager, ksp, user, repository); user.RaiseMessage("Updated information on {0} compatible modules", registry_manager.registry.CompatibleModules(ksp.VersionCriteria()).Count()); }
public int RunCommand(CKAN.KSP ksp, object raw_options) { UpgradeOptions options = (UpgradeOptions)raw_options; if (options.ckan_file != null) { options.modules.Add(LoadCkanFromFile(ksp, options.ckan_file).identifier); } if (options.modules.Count == 0 && !options.upgrade_all) { // What? No files specified? User.RaiseMessage("Usage: ckan upgrade Mod [Mod2, ...]"); User.RaiseMessage(" or ckan upgrade --all"); if (AutoUpdate.CanUpdate) { User.RaiseMessage(" or ckan upgrade ckan"); } return(Exit.BADOPT); } if (!options.upgrade_all && options.modules[0] == "ckan" && AutoUpdate.CanUpdate) { User.RaiseMessage("Querying the latest CKAN version"); AutoUpdate.Instance.FetchLatestReleaseInfo(); var latestVersion = AutoUpdate.Instance.LatestVersion; var currentVersion = new ModuleVersion(Meta.GetVersion(VersionFormat.Short)); if (latestVersion.IsGreaterThan(currentVersion)) { User.RaiseMessage("New CKAN version available - " + latestVersion); var releaseNotes = AutoUpdate.Instance.ReleaseNotes; User.RaiseMessage(releaseNotes); User.RaiseMessage("\r\n"); if (User.RaiseYesNoDialog("Proceed with install?")) { User.RaiseMessage("Upgrading CKAN, please wait.."); AutoUpdate.Instance.StartUpdateProcess(false); } } else { User.RaiseMessage("You already have the latest version."); } return(Exit.OK); } User.RaiseMessage("\r\nUpgrading modules...\r\n"); try { if (options.upgrade_all) { var registry = RegistryManager.Instance(ksp).registry; var installed = new Dictionary <string, ModuleVersion>(registry.Installed()); var to_upgrade = new List <CkanModule>(); foreach (KeyValuePair <string, ModuleVersion> mod in installed) { ModuleVersion current_version = mod.Value; if ((current_version is ProvidesModuleVersion) || (current_version is UnmanagedModuleVersion)) { continue; } else { try { // Check if upgrades are available var latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria()); // This may be an unindexed mod. If so, // skip rather than crash. See KSP-CKAN/CKAN#841. if (latest == null) { continue; } if (latest.version.IsGreaterThan(mod.Value)) { // Upgradable log.InfoFormat("New version {0} found for {1}", latest.version, latest.identifier); to_upgrade.Add(latest); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but no longer in the registry", mod.Key); } } } ModuleInstaller.GetInstance(ksp, User).Upgrade(to_upgrade, new NetAsyncModulesDownloader(User)); } else { // TODO: These instances all need to go. Search.AdjustModulesCase(ksp, options.modules); ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncModulesDownloader(User)); } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); return(Exit.ERROR); } catch (InconsistentKraken kraken) { User.RaiseMessage(kraken.ToString()); return(Exit.ERROR); } User.RaiseMessage("\r\nDone!\r\n"); return(Exit.OK); }
private static int Available(CKAN.KSP current_instance, IUser user) { List <CkanModule> available = RegistryManager.Instance(current_instance).registry.Available(current_instance.VersionCriteria()); user.RaiseMessage("Mods available for KSP {0}", current_instance.Version()); user.RaiseMessage(""); var width = user.WindowWidth; foreach (CkanModule module in available) { string entry = String.Format("* {0} ({1}) - {2}", module.identifier, module.version, module.name); user.RaiseMessage(width > 0 ? entry.PadRight(width).Substring(0, width - 1) : entry); } return(Exit.OK); }
public int RunCommand(CKAN.KSP ksp, object raw_options) { ShowOptions options = (ShowOptions)raw_options; if (options.Modname == null) { // empty argument user.RaiseMessage("show <module> - module name argument missing, perhaps you forgot it?"); return(Exit.BADOPT); } // Check installed modules for an exact match. var registry = RegistryManager.Instance(ksp).registry; var installedModuleToShow = registry.InstalledModule(options.Modname); if (installedModuleToShow != null) { // Show the installed module. return(ShowMod(installedModuleToShow)); } // Module was not installed, look for an exact match in the available modules, // either by "name" (the user-friendly display name) or by identifier CkanModule moduleToShow = registry .CompatibleModules(ksp.VersionCriteria()) .SingleOrDefault( mod => mod.name == options.Modname || mod.identifier == options.Modname ); if (moduleToShow == null) { // No exact match found. Try to look for a close match for this KSP version. user.RaiseMessage("{0} not found or installed.", options.Modname); user.RaiseMessage("Looking for close matches in mods compatible with KSP {0}.", ksp.Version()); Search search = new Search(user); var matches = search.PerformSearch(ksp, options.Modname); // Display the results of the search. if (!matches.Any()) { // No matches found. user.RaiseMessage("No close matches found."); return(Exit.BADOPT); } else if (matches.Count() == 1) { // If there is only 1 match, display it. user.RaiseMessage("Found 1 close match: {0}", matches[0].name); user.RaiseMessage(""); moduleToShow = matches[0]; } else { // Display the found close matches. string[] strings_matches = new string[matches.Count]; for (int i = 0; i < matches.Count; i++) { strings_matches[i] = matches[i].name; } int selection = user.RaiseSelectionDialog("Close matches", strings_matches); if (selection < 0) { return(Exit.BADOPT); } // Mark the selection as the one to show. moduleToShow = matches[selection]; } } return(ShowMod(moduleToShow)); }
/// <summary> /// Upgrade an installed module /// </summary> /// <param name="ksp">Game instance from which to remove</param> /// <param name="raw_options">Command line options object</param> /// <returns> /// Exit code for shell environment /// </returns> public int RunCommand(CKAN.KSP ksp, object raw_options) { UpgradeOptions options = (UpgradeOptions)raw_options; if (options.ckan_file != null) { options.modules.Add(MainClass.LoadCkanFromFile(ksp, options.ckan_file).identifier); } if (options.modules.Count == 0 && !options.upgrade_all) { // What? No files specified? User.RaiseMessage("Usage: ckan upgrade Mod [Mod2, ...]"); User.RaiseMessage(" or ckan upgrade --all"); if (AutoUpdate.CanUpdate) { User.RaiseMessage(" or ckan upgrade ckan"); } return(Exit.BADOPT); } if (!options.upgrade_all && options.modules[0] == "ckan" && AutoUpdate.CanUpdate) { User.RaiseMessage("Querying the latest CKAN version"); AutoUpdate.Instance.FetchLatestReleaseInfo(); var latestVersion = AutoUpdate.Instance.latestUpdate.Version; var currentVersion = new ModuleVersion(Meta.GetVersion(VersionFormat.Short)); if (latestVersion.IsGreaterThan(currentVersion)) { User.RaiseMessage("New CKAN version available - " + latestVersion); var releaseNotes = AutoUpdate.Instance.latestUpdate.ReleaseNotes; User.RaiseMessage(releaseNotes); User.RaiseMessage("\r\n"); if (User.RaiseYesNoDialog("Proceed with install?")) { User.RaiseMessage("Upgrading CKAN, please wait.."); AutoUpdate.Instance.StartUpdateProcess(false); } } else { User.RaiseMessage("You already have the latest version."); } return(Exit.OK); } User.RaiseMessage("\r\nUpgrading modules...\r\n"); try { HashSet <string> possibleConfigOnlyDirs = null; var regMgr = RegistryManager.Instance(ksp); var registry = regMgr.registry; if (options.upgrade_all) { var installed = new Dictionary <string, ModuleVersion>(registry.Installed()); var to_upgrade = new List <CkanModule>(); foreach (KeyValuePair <string, ModuleVersion> mod in installed) { ModuleVersion current_version = mod.Value; if ((current_version is ProvidesModuleVersion) || (current_version is UnmanagedModuleVersion)) { continue; } else { try { // Check if upgrades are available var latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria()); // This may be an unindexed mod. If so, // skip rather than crash. See KSP-CKAN/CKAN#841. if (latest == null || latest.IsDLC) { continue; } if (latest.version.IsGreaterThan(mod.Value)) { // Upgradable log.InfoFormat("New version {0} found for {1}", latest.version, latest.identifier); to_upgrade.Add(latest); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but no longer in the registry", mod.Key); } } } ModuleInstaller.GetInstance(ksp, manager.Cache, User).Upgrade(to_upgrade, new NetAsyncModulesDownloader(User, manager.Cache), ref possibleConfigOnlyDirs, regMgr); } else { // TODO: These instances all need to go. Search.AdjustModulesCase(ksp, options.modules); ModuleInstaller.GetInstance(ksp, manager.Cache, User).Upgrade(options.modules, new NetAsyncModulesDownloader(User, manager.Cache), ref possibleConfigOnlyDirs, regMgr); } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); return(Exit.ERROR); } catch (InconsistentKraken kraken) { User.RaiseMessage(kraken.ToString()); return(Exit.ERROR); } catch (ModuleIsDLCKraken kraken) { User.RaiseMessage($"CKAN can't upgrade expansion '{kraken.module.name}' for you."); var res = kraken?.module?.resources; var storePagesMsg = new Uri[] { res?.store, res?.steamstore } .Where(u => u != null) .Aggregate("", (a, b) => $"{a}\r\n- {b}"); if (!string.IsNullOrEmpty(storePagesMsg)) { User.RaiseMessage($"To upgrade this expansion, download any updates from the store page from which you purchased it:\r\n{storePagesMsg}"); } return(Exit.ERROR); } User.RaiseMessage("\r\nDone!\r\n"); return(Exit.OK); }
public int RunCommand(CKAN.KSP ksp, object raw_options) { ReplaceOptions options = (ReplaceOptions)raw_options; if (options.ckan_file != null) { options.modules.Add(MainClass.LoadCkanFromFile(ksp, options.ckan_file).identifier); } if (options.modules.Count == 0 && !options.replace_all) { // What? No mods specified? User.RaiseMessage("Usage: ckan replace Mod [Mod2, ...]"); User.RaiseMessage(" or ckan replace --all"); return(Exit.BADOPT); } // Prepare options. Can these all be done in the new() somehow? var replace_ops = new RelationshipResolverOptions { with_all_suggests = options.with_all_suggests, with_suggests = options.with_suggests, with_recommends = !options.no_recommends, allow_incompatible = options.allow_incompatible }; var registry = RegistryManager.Instance(ksp).registry; var to_replace = new List <ModuleReplacement>(); if (options.replace_all) { log.Debug("Running Replace all"); var installed = new Dictionary <string, ModuleVersion>(registry.Installed()); foreach (KeyValuePair <string, ModuleVersion> mod in installed) { ModuleVersion current_version = mod.Value; if ((current_version is ProvidesModuleVersion) || (current_version is UnmanagedModuleVersion)) { continue; } else { try { log.DebugFormat("Testing {0} {1} for possible replacement", mod.Key, mod.Value); // Check if replacement is available ModuleReplacement replacement = registry.GetReplacement(mod.Key, ksp.VersionCriteria()); if (replacement != null) { // Replaceable log.InfoFormat("Replacement {0} {1} found for {2} {3}", replacement.ReplaceWith.identifier, replacement.ReplaceWith.version, replacement.ToReplace.identifier, replacement.ToReplace.version); to_replace.Add(replacement); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but it or its replacement is not in the registry", mod.Key); } } } } else { foreach (string mod in options.modules) { try { log.DebugFormat("Checking that {0} is installed", mod); CkanModule modToReplace = registry.GetInstalledVersion(mod); if (modToReplace != null) { log.DebugFormat("Testing {0} {1} for possible replacement", modToReplace.identifier, modToReplace.version); try { // Check if replacement is available ModuleReplacement replacement = registry.GetReplacement(modToReplace.identifier, ksp.VersionCriteria()); if (replacement != null) { // Replaceable log.InfoFormat("Replacement {0} {1} found for {2} {3}", replacement.ReplaceWith.identifier, replacement.ReplaceWith.version, replacement.ToReplace.identifier, replacement.ToReplace.version); to_replace.Add(replacement); } if (modToReplace.replaced_by != null) { log.InfoFormat("Attempt to replace {0} failed, replacement {1} is not compatible", mod, modToReplace.replaced_by.name); } else { log.InfoFormat("Mod {0} has no replacement defined for the current version {1}", modToReplace.identifier, modToReplace.version); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but its replacement {1} is not in the registry", mod, modToReplace.replaced_by.name); } } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); } } } if (to_replace.Count() != 0) { User.RaiseMessage("\r\nReplacing modules...\r\n"); foreach (ModuleReplacement r in to_replace) { User.RaiseMessage("Replacement {0} {1} found for {2} {3}", r.ReplaceWith.identifier, r.ReplaceWith.version, r.ToReplace.identifier, r.ToReplace.version); } bool ok = User.RaiseYesNoDialog("\r\nContinue?"); if (!ok) { User.RaiseMessage("Replacements canceled at user request."); return(Exit.ERROR); } // TODO: These instances all need to go. try { ModuleInstaller.GetInstance(ksp, manager.Cache, User).Replace(to_replace, replace_ops, new NetAsyncModulesDownloader(User)); User.RaiseMessage("\r\nDone!\r\n"); } catch (DependencyNotSatisfiedKraken ex) { User.RaiseMessage("Dependencies not satisfied for replacement, {0} requires {1} {2} but it is not listed in the index, or not available for your version of KSP.", ex.parent, ex.module, ex.version); } } else { User.RaiseMessage("No replacements found."); return(Exit.OK); } return(Exit.OK); }