Пример #1
0
        /// <summary>
        /// Shows information about the mod.
        /// </summary>
        /// <returns>Success status.</returns>
        /// <param name="module">The module to show.</param>
        private int ShowMod(InstalledModule module, ShowOptions opts)
        {
            // Display the basic info.
            int return_value = ShowMod(module.Module, opts);

            if (!opts.without_files && !module.Module.IsDLC)
            {
                // Display InstalledModule specific information.
                ICollection <string> files = module.Files as ICollection <string>;
                if (files == null)
                {
                    throw new InvalidCastException();
                }

                user.RaiseMessage("");
                user.RaiseMessage("Showing {0} installed files:", files.Count);
                foreach (string file in files)
                {
                    user.RaiseMessage("  - {0}", file);
                }
            }

            return(return_value);
        }
Пример #2
0
        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
            CfanModule moduleToShow = ksp.Registry
                                      .Available(ksp.Version())
                                      .SingleOrDefault(
                mod => mod.title == 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 <CfanModule> 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].title);
                    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].title;
                    }

                    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));
        }
Пример #3
0
Файл: Main.cs Проект: pjf/CKAN
        // TODO: We should have a command (probably this one) that shows
        // info about uninstalled modules.
        private static int Show(ShowOptions options, CKAN.KSP current_instance, IUser user)
        {
            if (options.Modname == null)
            {
                // empty argument
                user.RaiseMessage("show <module> - module name argument missing, perhaps you forgot it?");
                return Exit.BADOPT;
            }

            RegistryManager registry_manager = RegistryManager.Instance(current_instance);
            InstalledModule module = registry_manager.registry.InstalledModule(options.Modname);

            if (module == null)
            {
                user.RaiseMessage("{0} not installed.", options.Modname);
                user.RaiseMessage("Try `ckan list` to show installed modules");
                return Exit.BADOPT;
            }

            // TODO: Print *lots* of information out; I should never have to dig through JSON

            #region Abstract and description
            if (!string.IsNullOrEmpty(module.Module.@abstract))
                user.RaiseMessage("{0}: {1}", module.Module.name, module.Module.@abstract);
            else
                user.RaiseMessage("{0}", module.Module.name);

            if (!string.IsNullOrEmpty(module.Module.description))
                user.RaiseMessage("\n{0}\n", module.Module.description);
            #endregion

            #region General info (author, version...)
            user.RaiseMessage("\nModule info:");
            user.RaiseMessage("- version:\t{0}", module.Module.version);
            user.RaiseMessage("- authors:\t{0}", string.Join(", ", module.Module.author));
            user.RaiseMessage("- status:\t{0}", module.Module.release_status);
            user.RaiseMessage("- license:\t{0}", module.Module.license); 
            #endregion

            #region Relationships
            if (module.Module.depends != null && module.Module.depends.Count > 0)
            {
                user.RaiseMessage("\nDepends:");
                foreach (RelationshipDescriptor dep in module.Module.depends)
                    user.RaiseMessage("- {0}", RelationshipToPrintableString(dep));
            }

            if (module.Module.recommends != null && module.Module.recommends.Count > 0)
            {
                user.RaiseMessage("\nRecommends:");
                foreach (RelationshipDescriptor dep in module.Module.recommends)
                    user.RaiseMessage("- {0}", RelationshipToPrintableString(dep));
            }

            if (module.Module.suggests != null && module.Module.suggests.Count > 0)
            {
                user.RaiseMessage("\nSuggests:");
                foreach (RelationshipDescriptor dep in module.Module.suggests)
                    user.RaiseMessage("- {0}", RelationshipToPrintableString(dep));
            }

            if (module.Module.ProvidesList != null && module.Module.ProvidesList.Count > 0)
            {
                user.RaiseMessage("\nProvides:");
                foreach (string prov in module.Module.ProvidesList)
                    user.RaiseMessage("- {0}", prov);
            } 
            #endregion

            user.RaiseMessage("\nResources:");
            if (module.Module.resources.bugtracker != null) user.RaiseMessage("- bugtracker: {0}", module.Module.resources.bugtracker.ToString());
            if (module.Module.resources.homepage != null) user.RaiseMessage("- homepage: {0}", module.Module.resources.homepage.ToString());
            if (module.Module.resources.kerbalstuff != null) user.RaiseMessage("- kerbalstuff: {0}", module.Module.resources.kerbalstuff.ToString());
            if (module.Module.resources.repository != null) user.RaiseMessage("- repository: {0}", module.Module.resources.repository.ToString());
            

            ICollection<string> files = module.Files as ICollection<string>;
            if (files == null) throw new InvalidCastException();

            user.RaiseMessage("\nShowing {0} installed files:", files.Count);
            foreach (string file in files)
            {
                user.RaiseMessage("- {0}", file);
            }

            return Exit.OK;
        }
Пример #4
0
        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);
            }

            // Look for the module in the registry.
            List <CkanModule> modules = ksp.Registry.Available(ksp.Version());
            CkanModule        module  = null;

            foreach (CkanModule mod in modules)
            {
                if (mod.name == options.Modname)
                {
                    module = mod;
                }
            }

            if (module == null)
            {
                // No exact match found. Try to look for a close match.
                user.RaiseMessage("{0} not found.", options.Modname);
                user.RaiseMessage("Looking for close matches.");

                Search            search  = new Search(user);
                List <CkanModule> matches = search.PerformSearch(ksp, options.Modname);

                if (matches.Count == 0)
                {
                    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("");

                    module = 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;
                    }

                    string message = "Close matches";

                    int selection = user.RaiseSelectionDialog(message, strings_matches);

                    if (selection < 0)
                    {
                        return(Exit.BADOPT);
                    }

                    // Mark the selection as the one to show.
                    module = matches[selection];
                }
            }

            // Is the selected module already installed?
            InstalledModule installed_module = ksp.Registry.InstalledModule(module.identifier);

            if (installed_module != null)
            {
                ShowMod(installed_module);
            }
            else
            {
                ShowMod(module);
            }

            return(Exit.OK);
        }
Пример #5
0
        public int RunCommand(CKAN.GameInstance ksp, object raw_options)
        {
            ShowOptions options = (ShowOptions)raw_options;

            if (options.modules == null || options.modules.Count < 1)
            {
                // empty argument
                user.RaiseMessage("show <module> - module name argument missing, perhaps you forgot it?");
                return(Exit.BADOPT);
            }

            int combined_exit_code = Exit.OK;
            // Check installed modules for an exact match.
            var registry = RegistryManager.Instance(ksp).registry;

            foreach (string modName in options.modules)
            {
                var installedModuleToShow = registry.InstalledModule(modName);
                if (installedModuleToShow != null)
                {
                    // Show the installed module.
                    combined_exit_code = CombineExitCodes(
                        combined_exit_code,
                        ShowMod(installedModuleToShow)
                        );
                    if (options.with_versions)
                    {
                        ShowVersionTable(ksp, registry.AvailableByIdentifier(installedModuleToShow.identifier).ToList());
                    }
                    user.RaiseMessage("");
                    continue;
                }

                // 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 == modName ||
                    mod.identifier == modName
                    );
                if (moduleToShow == null)
                {
                    // No exact match found. Try to look for a close match for this KSP version.
                    user.RaiseMessage(
                        "{0} not installed or compatible with {1} {2}.",
                        modName,
                        ksp.game.ShortName,
                        string.Join(", ", ksp.VersionCriteria().Versions.Select(v => v.ToString()))
                        );
                    user.RaiseMessage("Looking for close matches in compatible mods...");

                    Search search  = new Search(user);
                    var    matches = search.PerformSearch(ksp, modName);

                    // Display the results of the search.
                    if (!matches.Any())
                    {
                        // No matches found.
                        user.RaiseMessage("No close matches found.");
                        combined_exit_code = CombineExitCodes(combined_exit_code, Exit.BADOPT);
                        user.RaiseMessage("");
                        continue;
                    }
                    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.
                        int selection = user.RaiseSelectionDialog(
                            "Close matches:",
                            matches.Select(m => m.name).ToArray()
                            );
                        user.RaiseMessage("");
                        if (selection < 0)
                        {
                            combined_exit_code = CombineExitCodes(combined_exit_code, Exit.BADOPT);
                            continue;
                        }

                        // Mark the selection as the one to show.
                        moduleToShow = matches[selection];
                    }
                }

                combined_exit_code = CombineExitCodes(
                    combined_exit_code,
                    ShowMod(moduleToShow)
                    );
                if (options.with_versions)
                {
                    ShowVersionTable(ksp, registry.AvailableByIdentifier(moduleToShow.identifier).ToList());
                }
                user.RaiseMessage("");
            }
            return(combined_exit_code);
        }
Пример #6
0
        /// <summary>
        /// Shows information about the mod.
        /// </summary>
        /// <returns>Success status.</returns>
        /// <param name="module">The module to show.</param>
        private int ShowMod(CkanModule module, ShowOptions opts)
        {
            if (!opts.without_description)
            {
                #region Abstract and description
                if (!string.IsNullOrEmpty(module.@abstract))
                {
                    user.RaiseMessage("{0}: {1}", module.name, module.@abstract);
                }
                else
                {
                    user.RaiseMessage("{0}", module.name);
                }

                if (!string.IsNullOrEmpty(module.description))
                {
                    user.RaiseMessage("");
                    user.RaiseMessage("{0}", module.description);
                }
                #endregion
            }

            if (!opts.without_module_info)
            {
                #region General info (author, version...)
                user.RaiseMessage("");
                user.RaiseMessage("Module info:");
                user.RaiseMessage("  Version:\t{0}", module.version);

                if (module.author != null)
                {
                    user.RaiseMessage("  Authors:\t{0}", string.Join(", ", module.author));
                }
                else
                {
                    // Did you know that authors are optional in the spec?
                    // You do now. #673.
                    user.RaiseMessage("  Authors:\tUNKNOWN");
                }

                if (module.release_status != null)
                {
                    user.RaiseMessage("  Status:\t{0}", module.release_status);
                }
                user.RaiseMessage("  License:\t{0}", string.Join(", ", module.license));
                if (module.Tags != null && module.Tags.Count > 0)
                {
                    // Need an extra space before the tab to line up with other fields
                    user.RaiseMessage("  Tags: \t{0}", string.Join(", ", module.Tags));
                }
                if (module.localizations != null && module.localizations.Length > 0)
                {
                    user.RaiseMessage("  Languages:\t{0}", string.Join(", ", module.localizations.OrderBy(l => l)));
                }
                #endregion
            }

            if (!opts.without_relationships)
            {
                #region Relationships
                if (module.depends != null && module.depends.Count > 0)
                {
                    user.RaiseMessage("");
                    user.RaiseMessage("Depends:");
                    foreach (RelationshipDescriptor dep in module.depends)
                    {
                        user.RaiseMessage("  - {0}", RelationshipToPrintableString(dep));
                    }
                }

                if (module.recommends != null && module.recommends.Count > 0)
                {
                    user.RaiseMessage("");
                    user.RaiseMessage("Recommends:");
                    foreach (RelationshipDescriptor dep in module.recommends)
                    {
                        user.RaiseMessage("  - {0}", RelationshipToPrintableString(dep));
                    }
                }

                if (module.suggests != null && module.suggests.Count > 0)
                {
                    user.RaiseMessage("");
                    user.RaiseMessage("Suggests:");
                    foreach (RelationshipDescriptor dep in module.suggests)
                    {
                        user.RaiseMessage("  - {0}", RelationshipToPrintableString(dep));
                    }
                }

                if (module.provides != null && module.provides.Count > 0)
                {
                    user.RaiseMessage("");
                    user.RaiseMessage("Provides:");
                    foreach (string prov in module.provides)
                    {
                        user.RaiseMessage("  - {0}", prov);
                    }
                }
                #endregion
            }

            if (!opts.without_resources && module.resources != null)
            {
                user.RaiseMessage("");
                user.RaiseMessage("Resources:");
                if (module.resources.homepage != null)
                {
                    user.RaiseMessage("  Home page:\t{0}", Uri.EscapeUriString(module.resources.homepage.ToString()));
                }
                if (module.resources.manual != null)
                {
                    user.RaiseMessage("  Manual:\t{0}", Uri.EscapeUriString(module.resources.manual.ToString()));
                }
                if (module.resources.spacedock != null)
                {
                    user.RaiseMessage("  SpaceDock:\t{0}", Uri.EscapeUriString(module.resources.spacedock.ToString()));
                }
                if (module.resources.repository != null)
                {
                    user.RaiseMessage("  Repository:\t{0}", Uri.EscapeUriString(module.resources.repository.ToString()));
                }
                if (module.resources.bugtracker != null)
                {
                    user.RaiseMessage("  Bug tracker:\t{0}", Uri.EscapeUriString(module.resources.bugtracker.ToString()));
                }
                if (module.resources.curse != null)
                {
                    user.RaiseMessage("  Curse:\t{0}", Uri.EscapeUriString(module.resources.curse.ToString()));
                }
                if (module.resources.store != null)
                {
                    user.RaiseMessage("  Store:\t{0}", Uri.EscapeUriString(module.resources.store.ToString()));
                }
                if (module.resources.steamstore != null)
                {
                    user.RaiseMessage("  Steam store:\t{0}", Uri.EscapeUriString(module.resources.steamstore.ToString()));
                }
                if (module.resources.remoteAvc != null)
                {
                    user.RaiseMessage("  Version file:\t{0}", Uri.EscapeUriString(module.resources.remoteAvc.ToString()));
                }
            }

            if (!opts.without_files && !module.IsDLC)
            {
                // Compute the CKAN filename.
                string file_uri_hash = NetFileCache.CreateURLHash(module.download);
                string file_name     = CkanModule.StandardName(module.identifier, module.version);

                user.RaiseMessage("");
                user.RaiseMessage("Filename: {0}", file_uri_hash + "-" + file_name);
            }

            return(Exit.OK);
        }