public int RunCommand(CKAN.KSP ksp, object raw_options) { UpdateOptions options = (UpdateOptions) raw_options; List<CkanModule> available_prior = null; user.RaiseMessage("Downloading updates..."); if (options.list_changes) { // Get a list of available modules prior to the update. var registry = RegistryManager.Instance(ksp).registry; available_prior = registry.Available(ksp.VersionCriteria()); } // If no repository is selected, select all. if (options.repo == null) { options.update_all = true; } try { if (options.update_all) { UpdateRepository(ksp); } else { UpdateRepository(ksp, options.repo); } } catch (MissingCertificateKraken kraken) { // Handling the kraken means we have prettier output. user.RaiseMessage(kraken.ToString()); return Exit.ERROR; } if (options.list_changes) { var registry = RegistryManager.Instance(ksp).registry; PrintChanges(available_prior, registry.Available(ksp.VersionCriteria())); } return Exit.OK; }
public int RunCommand(CKAN.KSP ksp, object raw_options) { IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; List<CkanModule> available = registry.Available(ksp.VersionCriteria()); user.RaiseMessage("Mods available for KSP {0}", ksp.Version()); user.RaiseMessage(""); foreach (CkanModule module in available) { user.RaiseMessage(String.Format("* {0} ({1}) - {2}", module.identifier, module.version, module.name)); } return Exit.OK; }
/// <summary> /// Searches for the term in the list of available modules for the ksp instance. Looks in name, identifier and description fields. /// </summary> /// <returns>List of mathcing modules.</returns> /// <param name="ksp">The KSP instance to perform the search for.</param> /// <param name="term">The search term. Case insensitive.</param> public List<CkanModule> PerformSearch(CKAN.KSP ksp, string term) { var registry = RegistryManager.Instance(ksp).registry; return registry .Available(ksp.VersionCriteria()) .Where((module) => { // Extract the description. This is an optional field and may be null. string modDesc = string.Empty; if (!string.IsNullOrEmpty(module.description)) { modDesc = module.description; } // Look for a match in each string. return module.name.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1 || module.identifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1 || modDesc.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1; }).ToList(); }
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"); User.RaiseMessage(" or ckan upgrade ckan"); return Exit.BADOPT; } if (!options.upgrade_all && options.modules[0] == "ckan") { User.RaiseMessage("Querying the latest CKAN version"); AutoUpdate.Instance.FetchLatestReleaseInfo(); var latestVersion = AutoUpdate.Instance.LatestVersion; var currentVersion = new Version(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, Version>(registry.Installed()); var to_upgrade = new List<CkanModule>(); foreach (KeyValuePair<string, Version> mod in installed) { Version current_version = mod.Value; if ((current_version is ProvidesVersion) || (current_version is DllVersion)) { 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. ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncModulesDownloader(User)); } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); return Exit.ERROR; } User.RaiseMessage("\r\nDone!\r\n"); return Exit.OK; }
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; }