private IEnumerable <string> ReplacementIdentifiers(IEnumerable <string> replaced_identifiers) { foreach (string replaced in replaced_identifiers) { ModuleReplacement repl = registry.GetReplacement( replaced, manager.CurrentInstance.VersionCriteria() ); if (repl != null) { yield return(repl.ReplaceWith.identifier); } } }
private IEnumerable <ModuleReplacement> AllReplacements(IEnumerable <string> identifiers) { IRegistryQuerier registry = RegistryManager.Instance(manager.CurrentInstance).registry; foreach (string id in identifiers) { ModuleReplacement repl = registry.GetReplacement( id, manager.CurrentInstance.VersionCriteria() ); if (repl != null) { yield return(repl); } } }
private async Task CreateReplacements() { var moduleReplacement = new ModuleReplacement() { Name = "yaml-js", Link = "https://www.npmjs.com/package/yaml-js" }; await _db.ModuleReplacements.AddAsync(moduleReplacement); var replacements = new Faker <ModuleReplacement>() .RuleFor(m => m.Name, f => f.Hacker.Adjective()) .RuleFor(m => m.Link, f => f.Internet.Url()); var replacementCount = _options.FakesOptions.ReplacementsCount(); await _db.ModuleReplacements.AddRangeAsync(replacements.GenerateForever().Take(replacementCount)); await _db.SaveChangesAsync(); }
public async Task <Module> CreateModule(string token, string name, string description, string githubLink, IReadOnlyCollection <ModuleReplacement> replacements, bool isCore) { var account = await GetAccountFromToken(token); var module = new Module() { Name = name, Description = description, IsCore = isCore, PublishedDateTime = DateTime.Now, LastUpdatedDateTime = DateTime.Now, AuthorId = account.Id, GithubLink = githubLink, }; await _applicationDbContext.Modules.AddAsync(module); foreach (var r in replacements) { var replacement = new ModuleReplacement() { Link = r.Link, Name = r.Name, }; await _applicationDbContext.ModuleReplacements.AddAsync(replacement); var moduleModuleReplacementRelation = new ModuleModuleReplacementRelation() { Module = module, ModuleReplacement = replacement, }; await _applicationDbContext.ModuleModuleReplacementRelations.AddAsync(moduleModuleReplacementRelation); } await _applicationDbContext.SaveChangesAsync(); return(module); }
private int addVersionDisplay() { int boxLeft = Console.WindowWidth / 2 + 1, boxTop = 3; const int boxRight = -1, boxH = 5; if (ChangePlan.IsAnyAvailable(registry, mod.identifier)) { List <CkanModule> avail = registry.AllAvailable(mod.identifier); CkanModule inst = registry.GetInstalledVersion(mod.identifier); CkanModule latest = registry.LatestAvailable(mod.identifier, null); bool installed = registry.IsInstalled(mod.identifier, false); bool latestIsInstalled = inst?.Equals(latest) ?? false; List <CkanModule> others = avail; others.Remove(inst); others.Remove(latest); if (installed) { DateTime?instTime = InstalledOn(mod.identifier); if (latestIsInstalled) { ModuleReplacement mr = registry.GetReplacement( mod.identifier, manager.CurrentInstance.VersionCriteria() ); if (mr != null) { // Show replaced_by addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => $"Replaced by {mr.ReplaceWith.identifier}", () => ConsoleTheme.Current.AlertFrameFg, false, new List <CkanModule>() { mr.ReplaceWith } ); boxTop += boxH; addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => $"Installed {instTime?.ToString("d") ?? "manually"}", () => ConsoleTheme.Current.ActiveFrameFg, true, new List <CkanModule>() { inst } ); boxTop += boxH; } else { addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => $"Latest/Installed {instTime?.ToString("d") ?? "manually"}", () => ConsoleTheme.Current.ActiveFrameFg, true, new List <CkanModule>() { inst } ); boxTop += boxH; } } else { addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => "Latest Version", () => ConsoleTheme.Current.AlertFrameFg, false, new List <CkanModule>() { latest } ); boxTop += boxH; addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => $"Installed {instTime?.ToString("d") ?? "manually"}", () => ConsoleTheme.Current.ActiveFrameFg, true, new List <CkanModule>() { inst } ); boxTop += boxH; } } else { addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => "Latest Version", () => ConsoleTheme.Current.NormalFrameFg, false, new List <CkanModule>() { latest } ); boxTop += boxH; } if (others.Count > 0) { addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => "Other Versions", () => ConsoleTheme.Current.NormalFrameFg, false, others ); boxTop += boxH; } } else { DateTime?instTime = InstalledOn(mod.identifier); // Mod is no longer indexed, but we can generate a display // of the old info about it from when we installed it addVersionBox( boxLeft, boxTop, boxRight, boxTop + boxH - 1, () => $"UNAVAILABLE/Installed {instTime?.ToString("d") ?? "manually"}", () => ConsoleTheme.Current.AlertFrameFg, true, new List <CkanModule>() { mod } ); boxTop += boxH; } return(boxTop - 1); }
public int RunCommand(CKAN.GameInstance 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, ModuleVersion>(registry.Installed()); foreach (KeyValuePair <string, ModuleVersion> mod in installed) { ModuleVersion current_version = mod.Value; string modInfo = string.Format("{0} {1}", mod.Key, mod.Value); string bullet = "*"; if (current_version is ProvidesModuleVersion) { // Skip virtuals for now. continue; } else if (current_version is UnmanagedModuleVersion) { // Autodetected dll bullet = "A"; } else { try { // Check if upgrades are available, and show appropriately. log.DebugFormat("Check if upgrades are available for {0}", mod.Key); CkanModule latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria()); CkanModule current = registry.GetInstalledVersion(mod.Key); InstalledModule inst = registry.InstalledModule(mod.Key); if (latest == null) { // Not compatible! log.InfoFormat("Latest {0} is not compatible", mod.Key); bullet = "X"; if (current == null) { log.DebugFormat(" {0} installed version not found in registry", mod.Key); } // Check if mod is replaceable if (current.replaced_by != null) { ModuleReplacement replacement = registry.GetReplacement(mod.Key, ksp.VersionCriteria()); if (replacement != null) { // Replaceable! bullet = ">"; modInfo = string.Format("{0} > {1} {2}", modInfo, replacement.ReplaceWith.name, replacement.ReplaceWith.version); } } } else if (latest.version.IsEqualTo(current_version)) { // Up to date log.InfoFormat("Latest {0} is {1}", mod.Key, latest.version); bullet = (inst?.AutoInstalled ?? false) ? "+" : "-"; // Check if mod is replaceable if (current.replaced_by != null) { ModuleReplacement replacement = registry.GetReplacement(latest.identifier, ksp.VersionCriteria()); if (replacement != null) { // Replaceable! bullet = ">"; modInfo = string.Format("{0} > {1} {2}", modInfo, replacement.ReplaceWith.name, replacement.ReplaceWith.version); } } } 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}", bullet, modInfo); } } 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. +:Auto-installed. X: Incompatible. ^: Upgradable. >: Replaceable\r\n A: Autodetected. ?: Unknown. *: Broken. "); // Broken mods are in a state that CKAN doesn't understand, and therefore can't handle automatically } return(Exit.OK); }
public int RunCommand(CKAN.GameInstance ksp, object raw_options) { ReplaceOptions options = (ReplaceOptions)raw_options; if (options.ckan_file != null) { options.modules.Add(MainClass.LoadCkanFromFile(ksp, options.ckan_file).identifier); } if (options.modules.Count == 0 && !options.replace_all) { // What? No mods specified? User.RaiseMessage("Usage: ckan replace Mod [Mod2, ...]"); User.RaiseMessage(" or ckan replace --all"); return(Exit.BADOPT); } // Prepare options. Can these all be done in the new() somehow? var replace_ops = new RelationshipResolverOptions { with_all_suggests = options.with_all_suggests, with_suggests = options.with_suggests, with_recommends = !options.no_recommends, allow_incompatible = options.allow_incompatible }; var regMgr = RegistryManager.Instance(ksp); var registry = regMgr.registry; var to_replace = new List <ModuleReplacement>(); if (options.replace_all) { log.Debug("Running Replace all"); var installed = new Dictionary <string, ModuleVersion>(registry.Installed()); foreach (KeyValuePair <string, ModuleVersion> mod in installed) { ModuleVersion current_version = mod.Value; if ((current_version is ProvidesModuleVersion) || (current_version is UnmanagedModuleVersion)) { continue; } else { try { log.DebugFormat("Testing {0} {1} for possible replacement", mod.Key, mod.Value); // Check if replacement is available ModuleReplacement replacement = registry.GetReplacement(mod.Key, ksp.VersionCriteria()); if (replacement != null) { // Replaceable log.InfoFormat("Replacement {0} {1} found for {2} {3}", replacement.ReplaceWith.identifier, replacement.ReplaceWith.version, replacement.ToReplace.identifier, replacement.ToReplace.version); to_replace.Add(replacement); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but it or its replacement is not in the registry", mod.Key); } } } } else { foreach (string mod in options.modules) { try { log.DebugFormat("Checking that {0} is installed", mod); CkanModule modToReplace = registry.GetInstalledVersion(mod); if (modToReplace != null) { log.DebugFormat("Testing {0} {1} for possible replacement", modToReplace.identifier, modToReplace.version); try { // Check if replacement is available ModuleReplacement replacement = registry.GetReplacement(modToReplace.identifier, ksp.VersionCriteria()); if (replacement != null) { // Replaceable log.InfoFormat("Replacement {0} {1} found for {2} {3}", replacement.ReplaceWith.identifier, replacement.ReplaceWith.version, replacement.ToReplace.identifier, replacement.ToReplace.version); to_replace.Add(replacement); } if (modToReplace.replaced_by != null) { log.InfoFormat("Attempt to replace {0} failed, replacement {1} is not compatible", mod, modToReplace.replaced_by.name); } else { log.InfoFormat("Mod {0} has no replacement defined for the current version {1}", modToReplace.identifier, modToReplace.version); } } catch (ModuleNotFoundKraken) { log.InfoFormat("{0} is installed, but its replacement {1} is not in the registry", mod, modToReplace.replaced_by.name); } } } catch (ModuleNotFoundKraken kraken) { User.RaiseMessage("Module {0} not found", kraken.module); } } } if (to_replace.Count() != 0) { User.RaiseMessage("\r\nReplacing modules...\r\n"); foreach (ModuleReplacement r in to_replace) { User.RaiseMessage("Replacement {0} {1} found for {2} {3}", r.ReplaceWith.identifier, r.ReplaceWith.version, r.ToReplace.identifier, r.ToReplace.version); } bool ok = User.RaiseYesNoDialog("Continue?"); if (!ok) { User.RaiseMessage("Replacements canceled at user request."); return(Exit.ERROR); } // TODO: These instances all need to go. try { HashSet <string> possibleConfigOnlyDirs = null; new ModuleInstaller(ksp, manager.Cache, User).Replace(to_replace, replace_ops, new NetAsyncModulesDownloader(User, manager.Cache), ref possibleConfigOnlyDirs, regMgr); User.RaiseMessage(""); } catch (DependencyNotSatisfiedKraken ex) { User.RaiseMessage("Dependencies not satisfied for replacement, {0} requires {1} {2} but it is not listed in the index, or not available for your version of KSP.", ex.parent, ex.module, ex.version); } } else { User.RaiseMessage("No replacements found."); return(Exit.OK); } return(Exit.OK); }