Beispiel #1
0
        public int RunCommand(CKAN.KSP ksp, object raw_options)
        {
            SearchOptions options = (SearchOptions) raw_options;

            // Check the input.
            if (String.IsNullOrWhiteSpace(options.search_term))
            {
                user.RaiseError("No search term?");

                return Exit.BADOPT;
            }

            var matching_mods = PerformSearch(ksp, options.search_term);

            // Show how many matches we have.
            user.RaiseMessage("Found " + matching_mods.Count().ToString() + " mods matching \"" + options.search_term + "\".");

            // Present the results.
            if (!matching_mods.Any())
            {
                return Exit.OK;
            }

            // Print each mod on a separate line.
            foreach (CkanModule mod in matching_mods)
            {
                user.RaiseMessage(mod.identifier);
            }

            return Exit.OK;
        }
Beispiel #2
0
        /// <summary>
        /// Returns whether the given constraint matches the desired version
        /// for the mod we're processing.
        /// </summary>
        private bool ConstraintPasses(string op, CKAN.Version desired_version)
        {
            switch (op)
            {
                case "":
                case "=":
                    return version.IsEqualTo(desired_version);

                case "<":
                    return version.IsLessThan(desired_version);

                case ">":
                    return version.IsGreaterThan(desired_version);

                case "<=":
                    return version.CompareTo(desired_version) <= 0;

                case ">=":
                    return version.CompareTo(desired_version) >= 0;

                default:
                    throw new Kraken(
                        string.Format("Unknown x_netkan_override comparator: {0}", op));
            }
        }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
 public FakeWin32Registry(CKAN.KSP instance,string autostart = "test")
 {
     Instances = new List<Tuple<string, string>>
     {
         new Tuple<string, string>("test", instance.GameDir())
     };
     AutoStartInstance = autostart;
 }
Beispiel #5
0
        public int RunCommand(CKAN.KSP ksp, object rawOptions)
        {
            var options = (CompareOptions)rawOptions;

            var leftVersion = new Version(options.Left);
            var rightVersion = new Version(options.Right);

            ksp.User.RaiseMessage(leftVersion.CompareTo(rightVersion).ToString());

            return 0;
        }
Beispiel #6
0
        // 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
                Registry 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.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;
        }
Beispiel #7
0
        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;
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        /// <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();
        }
Beispiel #10
0
        public int RunCommand(CKAN.KSP ksp, object rawOptions)
        {
            var options = (CompareOptions)rawOptions;

            if (options.Left != null && options.Right != null)
            {
                var leftVersion = new Version(options.Left);
                var rightVersion = new Version(options.Right);

                int compareResult = leftVersion.CompareTo(rightVersion);
                if (compareResult == 0)
                {
                    user.RaiseMessage(
                        "\"{0}\" and \"{1}\" are the same versions.", leftVersion, rightVersion);
                }
                else if (compareResult == -1)
                {
                    user.RaiseMessage(
                        "\"{0}\" is lower than \"{1}\".", leftVersion, rightVersion);
                }
                else if (compareResult == 1)
                {
                    user.RaiseMessage(
                        "\"{0}\" is higher than \"{1}\".", leftVersion, rightVersion);
                }
                else
                {
                    user.RaiseMessage(
                        "Usage: ckan compare version1 version2");
                }
            }
            else
            {
                user.RaiseMessage(
                    "Usage: ckan compare version1 version2");
                return Exit.BADOPT;
            }

            return Exit.OK;
        }
Beispiel #11
0
        /// <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, user)
                : CKAN.Repo.Update(registry_manager, ksp, user, true, repository);

            user.RaiseMessage("Updated information on {0} available modules", updated);
        }
Beispiel #12
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
            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);
        }
Beispiel #13
0
        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;
        }
Beispiel #14
0
        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;
        }
Beispiel #15
0
        /// <summary>
        /// Scans the ksp instance. Detects installed mods to mark as auto-detected and checks the consistency
        /// </summary>
        /// <param name="ksp_instance">The instance to scan</param>
        /// <param name="user"></param>
        /// <param name="next_command">Changes the output message if set.</param>
        /// <returns>Exit.OK if instance is consistent, Exit.ERROR otherwise </returns>
        private static int Scan(CKAN.KSP ksp_instance, IUser user, string next_command=null)
        {
            try
            {
                ksp_instance.ScanGameData();
                return Exit.OK;
            }
            catch (InconsistentKraken kraken)
            {

                if (next_command==null)
                {
                    user.RaiseError(kraken.InconsistenciesPretty);
                    user.RaiseError("The repo has not been saved.");
                }
                else
                {
                    user.RaiseMessage("Preliminary scanning shows that the install is in a inconsistent state.");
                    user.RaiseMessage("Use ckan.exe scan for more details");
                    user.RaiseMessage("Proceeding with {0} in case it fixes it.\n", next_command);
                }

                return Exit.ERROR;
            }
        }
Beispiel #16
0
        internal static CkanModule LoadCkanFromFile(CKAN.KSP current_instance, string ckan_file)
        {
            CkanModule module = CkanModule.FromFile(ckan_file);

            // We'll need to make some registry changes to do this.
            RegistryManager registry_manager = RegistryManager.Instance(current_instance);

            // Remove this version of the module in the registry, if it exists.
            registry_manager.registry.RemoveAvailable(module);

            // Sneakily add our version in...
            registry_manager.registry.AddAvailable(module);

            return module;
        }
Beispiel #17
0
 public Repair(CKAN.KSP current_instance,IUser user)
 {
     CurrentInstance = current_instance;
     User = user;
 }
Beispiel #18
0
 private static int Clean(CKAN.KSP current_instance)
 {
     current_instance.CleanCache();
     return Exit.OK;
 }
Beispiel #19
0
        public int RunCommand(CKAN.KSP ksp, object raw_options)
        {
            InstallOptions options = (InstallOptions) raw_options;

            if (options.ckan_files != null)
            {
                // Oooh! We're installing from a CKAN file.
                foreach (string ckan_file in options.ckan_files)
                {
                    Uri ckan_uri;

                    // Check if the argument if a wellformatted Uri.
                    if (!Uri.IsWellFormedUriString(ckan_file, UriKind.Absolute))
                    {
                        // Assume it is a local file, check if the file exists.
                        if (File.Exists(ckan_file))
                        {
                            // Get the full path of the file.
                            ckan_uri = new Uri(Path.GetFullPath(ckan_file));
                        }
                        else
                        {
                            // We have no further ideas as what we can do with this Uri, tell the user.
                            user.RaiseError("Can not find file \"{0}\".", ckan_file);
                            user.RaiseError("Exiting.");
                            return Exit.ERROR;
                        }
                    }
                    else
                    {
                        ckan_uri = new Uri(ckan_file);
                    }

                    string filename = String.Empty;

                    // If it is a local file, we already know the filename. If it is remote, create a temporary file and download the remote resource.
                    if (ckan_uri.IsFile)
                    {
                        log.InfoFormat("Installing from local CKAN file \"{0}\"", filename);
                        filename = ckan_uri.LocalPath;
                    }
                    else
                    {
                        log.InfoFormat("Installing from remote CKAN file \"{0}\"", ckan_uri);
                        filename = Net.Download(ckan_uri, null, user);

                        log.DebugFormat("Temporary file for \"{0}\" is at \"{1}\".", ckan_uri, filename);
                    }

                    // Parse the JSON file.
                    options.modules.Add(LoadCkanFromFile(ksp, filename).identifier);
                }

                // At times RunCommand() calls itself recursively - in this case we do
                // not want to be doing this again, so "consume" the option
                options.ckan_files = null;
            }

            if (options.modules.Count == 0)
            {
                // What? No files specified?
                user.RaiseMessage(
                    "Usage: ckan install [--with-suggests] [--with-all-suggests] [--no-recommends] [--headless] Mod [Mod2, ...]");
                return Exit.BADOPT;
            }

            // Prepare options. Can these all be done in the new() somehow?
            var install_ops = new RelationshipResolverOptions
            {
                with_all_suggests = options.with_all_suggests,
                with_suggests = options.with_suggests,
                with_recommends = !options.no_recommends
            };

            if (user.Headless)
            {
                install_ops.without_toomanyprovides_kraken = true;
                install_ops.without_enforce_consistency = true;
            }

            // Install everything requested. :)
            try
            {
                var installer = ModuleInstaller.GetInstance(ksp, user);
                installer.InstallList(options.modules, install_ops);
            }
            catch (ModuleNotFoundKraken ex)
            {
                user.RaiseMessage("Module {0} required, but not listed in index, or not available for your version of KSP", ex.module);
                user.RaiseMessage("If you're lucky, you can do a `ckan update` and try again.");
                user.RaiseMessage("Try `ckan install --no-recommends` to skip installation of recommended modules");
                return Exit.ERROR;
            }
            catch (BadMetadataKraken ex)
            {
                user.RaiseMessage("Bad metadata detected for module {0}", ex.module);
                user.RaiseMessage(ex.Message);
                return Exit.ERROR;
            }
            catch (TooManyModsProvideKraken ex)
            {
                // Request the user selects one of the mods.
                string[] mods = new string[ex.modules.Count];

                for (int i = 0; i < ex.modules.Count; i++)
                {
                    mods[i] = String.Format("{0} ({1})", ex.modules[i].identifier, ex.modules[i].name);
                }

                string message = String.Format("Too many mods provide {0}. Please pick from the following:\r\n", ex.requested);

                int result;

                try
                {
                    result = user.RaiseSelectionDialog(message, mods);
                }
                catch (Kraken e)
                {
                    user.RaiseMessage(e.Message);

                    return Exit.ERROR;
                }

                if (result < 0)
                {
                    user.RaiseMessage(String.Empty); // Looks tidier.

                    return Exit.ERROR;
                }

                // Add the module to the list.
                options.modules.Add(ex.modules[result].identifier);

                return (new Install(user).RunCommand(ksp, options));
            }
            catch (FileExistsKraken ex)
            {
                if (ex.owningModule != null)
                {
                    user.RaiseMessage(
                        "\r\nOh no! We tried to overwrite a file owned by another mod!\r\n"+
                        "Please try a `ckan update` and try again.\r\n\r\n"+
                        "If this problem re-occurs, then it maybe a packaging bug.\r\n"+
                        "Please report it at:\r\n\r\n" +
                        "https://github.com/KSP-CKAN/NetKAN/issues/new\r\n\r\n" +
                        "Please including the following information in your report:\r\n\r\n" +
                        "File           : {0}\r\n" +
                        "Installing Mod : {1}\r\n" +
                        "Owning Mod     : {2}\r\n" +
                        "CKAN Version   : {3}\r\n",
                        ex.filename, ex.installingModule, ex.owningModule,
                        Meta.Version()
                    );
                }
                else
                {
                    user.RaiseMessage(
                        "\r\n\r\nOh no!\r\n\r\n"+
                        "It looks like you're trying to install a mod which is already installed,\r\n"+
                        "or which conflicts with another mod which is already installed.\r\n\r\n"+
                        "As a safety feature, the CKAN will *never* overwrite or alter a file\r\n"+
                        "that it did not install itself.\r\n\r\n"+
                        "If you wish to install {0} via the CKAN,\r\n"+
                        "then please manually uninstall the mod which owns:\r\n\r\n"+
                        "{1}\r\n\r\n"+"and try again.\r\n",
                        ex.installingModule, ex.filename
                    );
                }

                user.RaiseMessage("Your GameData has been returned to its original state.\r\n");
                return Exit.ERROR;
            }
            catch (InconsistentKraken ex)
            {
                // The prettiest Kraken formats itself for us.
                user.RaiseMessage(ex.InconsistenciesPretty);
                user.RaiseMessage("Install canceled. Your files have been returned to their initial state.");
                return Exit.ERROR;
            }
            catch (CancelledActionKraken)
            {
                user.RaiseMessage("Installation canceled at user request.");
                return Exit.ERROR;
            }
            catch (MissingCertificateKraken kraken)
            {
                // Another very pretty kraken.
                user.RaiseMessage(kraken.ToString());
                return Exit.ERROR;
            }
            catch (DownloadErrorsKraken)
            {
                user.RaiseMessage("One or more files failed to download, stopped.");
                return Exit.ERROR;
            }
            catch (DirectoryNotFoundKraken kraken)
            {
                user.RaiseMessage("\r\n{0}", kraken.Message);
                return Exit.ERROR;
            }

            return Exit.OK;
        }
Beispiel #20
0
        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;
        }