// Uninstalls a module, if it exists. public int RunCommand(CKAN.KSP ksp, object raw_options) { RemoveOptions options = (RemoveOptions)raw_options; 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); }
// 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) { // 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); }
// Uninstalls a module, if it exists. private static int Remove(RemoveOptions options, CKAN.KSP current_instance, IUser user) { if (options.modules != null && options.modules.Count > 0) { try { var installer = ModuleInstaller.GetInstance(current_instance, user); installer.UninstallList(options.modules); return Exit.OK; } 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; } }
// Uninstalls a module, if it exists. private static int Remove(RemoveOptions options) { if (options.Modname != null && options.Modname.Length > 0) { try { var installer = ModuleInstaller.Instance; installer.UninstallList(options.Modname); return(Exit.OK); } catch (ModNotInstalledKraken kraken) { User.WriteLine("I can't do that, {0} isn't installed.", kraken.mod); User.WriteLine("Try `ckan list` for a list of installed mods."); return(Exit.BADOPT); } } else { User.WriteLine("No mod selected, nothing to do"); return(Exit.BADOPT); } }
/// <summary> /// Uninstalls a module, if it exists. /// </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.GameInstance ksp, object raw_options) { RemoveOptions options = (RemoveOptions)raw_options; RegistryManager regMgr = RegistryManager.Instance(ksp); // 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 // Try every regex on every installed module: // if it matches, select for removal foreach (string mod in regMgr.registry.InstalledModules.Select(mod => mod.identifier)) { 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.rmall) { log.Debug("Removing all mods"); // Add the list of installed modules to the list that should be uninstalled options.modules.AddRange( regMgr.registry.InstalledModules .Where(mod => !mod.Module.IsDLC) .Select(mod => mod.identifier) ); } if (options.modules != null && options.modules.Count > 0) { try { HashSet <string> possibleConfigOnlyDirs = null; var installer = ModuleInstaller.GetInstance(ksp, manager.Cache, user); Search.AdjustModulesCase(ksp, options.modules); installer.UninstallList(options.modules, ref possibleConfigOnlyDirs, regMgr); user.RaiseMessage(""); } 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); } catch (ModuleIsDLCKraken kraken) { user.RaiseMessage($"CKAN can't remove 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 remove this expansion, follow the instructions for the store page from which you purchased it:\r\n{storePagesMsg}"); } return(Exit.BADOPT); } catch (CancelledActionKraken k) { user.RaiseMessage("Remove aborted: {0}", k.Message); return(Exit.ERROR); } } else { user.RaiseMessage("No mod selected, nothing to do"); return(Exit.BADOPT); } return(Exit.OK); }
/// <summary> /// Uninstalls a module, if it exists. /// </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) { 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 IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; // Try every regex on every installed module: // if it matches, select for removal foreach (string mod in registry.InstalledModules.Select(mod => mod.identifier)) { 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.rmall) { log.Debug("Removing all mods"); // Add the list of installed modules to the list that should be uninstalled IRegistryQuerier registry = RegistryManager.Instance(ksp).registry; options.modules.AddRange( registry.InstalledModules.Select(mod => mod.identifier) ); } if (options.modules != null && options.modules.Count > 0) { try { var installer = ModuleInstaller.GetInstance(ksp, manager.Cache, user); Search.AdjustModulesCase(ksp, options.modules); 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); }