/// <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) { List<CkanModule> matching_mods = new List<CkanModule>(); // Get a list of available mods. List<CkanModule> available_mods = ksp.Registry.Available(ksp.Version()); // Look for the search term in the list. foreach (CkanModule mod in available_mods) { // Extract the description. This is an optional field and may be null. string mod_description = String.Empty; if (!String.IsNullOrEmpty(mod.description)) { mod_description = mod.description; } // Look for a match in each string. if (mod.name.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1 || mod.identifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1 || mod_description.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1) { matching_mods.Add(mod); } } return matching_mods; }
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. available_prior = ksp.Registry.Available(ksp.Version()); } // 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) { PrintChanges(available_prior, ksp.Registry.Available(ksp.Version())); } 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; }
public int RunCommand(CKAN.KSP ksp, object raw_options) { ListOptions options = (ListOptions) raw_options; Registry 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("\nKSP found at {0}\n", ksp.GameDir()); user.RaiseMessage("KSP Version: {0}\n", ksp.Version()); user.RaiseMessage("Installed Modules:\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.Version()); 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("\nLegend: -: Up to date. X: Incompatible. ^: Upgradable. ?: Unknown "); } 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. InstalledModule installedModuleToShow = ksp.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 = ksp.Registry .Available(ksp.Version()) .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 available mods for KSP {0}.", ksp.Version()); Search search = new Search(user); List<CkanModule> matches = search.PerformSearch(ksp, options.Modname); // Display the results of the search. if (matches.Count == 0) { // 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); }
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"); var latestVersion = AutoUpdate.FetchLatestCkanVersion(); var currentVersion = new Version(Meta.Version()); if (latestVersion.IsGreaterThan(currentVersion)) { User.RaiseMessage("New CKAN version available - " + latestVersion); var releaseNotes = AutoUpdate.FetchLatestCkanVersionReleaseNotes(); User.RaiseMessage(releaseNotes); User.RaiseMessage("\n"); if (User.RaiseYesNoDialog("Proceed with install?")) { User.RaiseMessage("Upgrading CKAN, please wait.."); AutoUpdate.StartUpdateProcess(false); } } else { User.RaiseMessage("You already have the latest version."); } return Exit.OK; } User.RaiseMessage("\nUpgrading modules...\n"); try { if (options.upgrade_all) { var installed = new Dictionary<string, Version>(ksp.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 CkanModule latest = ksp.Registry.LatestAvailable(mod.Key, ksp.Version()); // 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 NetAsyncDownloader(User)); } else { // TODO: These instances all need to go. ModuleInstaller.GetInstance(ksp, User).Upgrade(options.modules, new NetAsyncDownloader(User)); } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); return Exit.ERROR; } User.RaiseMessage("\nDone!\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.Version()); 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; }