diff --git a/ConsoleUI/DependencyScreen.cs b/ConsoleUI/DependencyScreen.cs
index f98982776..21f6b404d 100644
--- a/ConsoleUI/DependencyScreen.cs
+++ b/ConsoleUI/DependencyScreen.cs
@@ -2,6 +2,11 @@
using System.Linq;
using System.ComponentModel;
using System.Collections.Generic;
+
+using CKAN.Versioning;
+#if NETFRAMEWORK
+using CKAN.Extensions;
+#endif
using CKAN.ConsoleUI.Toolkit;
namespace CKAN.ConsoleUI {
@@ -16,31 +21,26 @@ public class DependencyScreen : ConsoleScreen {
/// Initialize the screen
///
/// Game instance manager containing instances
- /// Registry of the current instance for finding mods
+ /// Registry of the current instance for finding mods
/// Plan of mods to add and remove
/// Mods that the user saw and did not select, in this pass or a previous pass
/// True if debug options should be available, false otherwise
- public DependencyScreen(GameInstanceManager mgr, Registry registry, ChangePlan cp, HashSet rej, bool dbg) : base()
+ public DependencyScreen(GameInstanceManager mgr, Registry reg, ChangePlan cp, HashSet rej, bool dbg) : base()
{
- debug = dbg;
- manager = mgr;
- plan = cp;
- this.registry = registry;
- installer = new ModuleInstaller(manager.CurrentInstance, manager.Cache, this);
- rejected = rej;
-
- AddObject(new ConsoleLabel(
- 1, 2, -1,
- () => Properties.Resources.RecommendationsLabel
- ));
-
- HashSet sourceModules = new HashSet();
- sourceModules.UnionWith(plan.Install);
- sourceModules.UnionWith(new HashSet(
- ReplacementIdentifiers(plan.Replace)
- .Select(id => registry.InstalledModule(id).Module)
- ));
- generateList(sourceModules);
+ debug = dbg;
+ manager = mgr;
+ plan = cp;
+ registry = reg;
+ rejected = rej;
+
+ AddObject(new ConsoleLabel(1, 2, -1,
+ () => Properties.Resources.RecommendationsLabel));
+
+ generateList(new ModuleInstaller(manager.CurrentInstance, manager.Cache, this),
+ plan.Install
+ .Concat(ReplacementModules(plan.Replace,
+ manager.CurrentInstance.VersionCriteria()))
+ .ToHashSet());
dependencyList = new ConsoleListBox(
1, 4, -1, -2,
@@ -49,17 +49,17 @@ public DependencyScreen(GameInstanceManager mgr, Registry registry, ChangePlan c
new ConsoleListBoxColumn() {
Header = Properties.Resources.RecommendationsInstallHeader,
Width = 7,
- Renderer = (Dependency d) => StatusSymbol(d.module)
+ Renderer = (Dependency d) => StatusSymbol(d.module),
},
new ConsoleListBoxColumn() {
Header = Properties.Resources.RecommendationsNameHeader,
Width = null,
- Renderer = (Dependency d) => d.module.ToString()
+ Renderer = (Dependency d) => d.module.ToString(),
},
new ConsoleListBoxColumn() {
Header = Properties.Resources.RecommendationsSourcesHeader,
Width = 42,
- Renderer = (Dependency d) => string.Join(", ", d.dependents)
+ Renderer = (Dependency d) => string.Join(", ", d.dependents),
}
},
1, 0, ListSortDirection.Descending
@@ -89,10 +89,9 @@ public DependencyScreen(GameInstanceManager mgr, Registry registry, ChangePlan c
dependencyList.AddTip(Properties.Resources.Enter, Properties.Resources.Details);
dependencyList.AddBinding(Keys.Enter, (object sender, ConsoleTheme theme) => {
if (dependencyList.Selection != null) {
- LaunchSubScreen(theme, new ModInfoScreen(
- manager, registry, plan,
- dependencyList.Selection.module,
- debug));
+ LaunchSubScreen(theme, new ModInfoScreen(manager, reg, plan,
+ dependencyList.Selection.module,
+ debug));
}
return true;
});
@@ -102,9 +101,7 @@ public DependencyScreen(GameInstanceManager mgr, Registry registry, ChangePlan c
AddTip(Properties.Resources.Esc, Properties.Resources.Cancel);
AddBinding(Keys.Escape, (object sender, ConsoleTheme theme) => {
// Add everything to rejected
- foreach (var kvp in dependencies) {
- rejected.Add(kvp.Key.identifier);
- }
+ rejected.UnionWith(dependencies.Keys.Select(m => m.identifier));
return false;
});
@@ -131,21 +128,15 @@ public DependencyScreen(GameInstanceManager mgr, Registry registry, ChangePlan c
///
/// Put description in top center
///
- protected override string CenterHeader()
- {
- return Properties.Resources.RecommendationsTitle;
- }
+ protected override string CenterHeader() => Properties.Resources.RecommendationsTitle;
///
/// Return whether there are any options to show.
/// ModListScreen uses this to avoid showing this screen when empty.
///
- public bool HaveOptions()
- {
- return dependencies.Count > 0;
- }
+ public bool HaveOptions() => dependencies.Count > 0;
- private void generateList(HashSet inst)
+ private void generateList(ModuleInstaller installer, HashSet inst)
{
if (installer.FindRecommendations(
inst, new List(inst), registry as Registry,
@@ -153,66 +144,53 @@ private void generateList(HashSet inst)
out Dictionary> suggestions,
out Dictionary> supporters
)) {
- foreach (var kvp in recommendations) {
- dependencies.Add(kvp.Key, new Dependency() {
- module = kvp.Key,
- defaultInstall = kvp.Value.Item1,
- dependents = kvp.Value.Item2.OrderBy(d => d).ToList()
+ foreach ((CkanModule mod, Tuple> checkedAndDependents) in recommendations) {
+ dependencies.Add(mod, new Dependency() {
+ module = mod,
+ dependents = checkedAndDependents.Item2.OrderBy(d => d).ToList()
});
- if (kvp.Value.Item1) {
- accepted.Add(kvp.Key);
- }
}
- foreach (var kvp in suggestions) {
- dependencies.Add(kvp.Key, new Dependency() {
- module = kvp.Key,
- defaultInstall = false,
- dependents = kvp.Value.OrderBy(d => d).ToList()
+ foreach ((CkanModule mod, List dependents) in suggestions) {
+ dependencies.Add(mod, new Dependency() {
+ module = mod,
+ dependents = dependents.OrderBy(d => d).ToList()
});
}
- foreach (var kvp in supporters) {
- dependencies.Add(kvp.Key, new Dependency() {
- module = kvp.Key,
- defaultInstall = false,
- dependents = kvp.Value.OrderBy(d => d).ToList()
+ foreach ((CkanModule mod, HashSet dependents) in supporters) {
+ dependencies.Add(mod, new Dependency() {
+ module = mod,
+ dependents = dependents.OrderBy(d => d).ToList()
});
}
+ // Check the default checkboxes
+ accepted.UnionWith(recommendations.Where(kvp => kvp.Value.Item1)
+ .Select(kvp => kvp.Key));
}
}
- private IEnumerable ReplacementIdentifiers(IEnumerable 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 ReplacementModules(IEnumerable replaced_identifiers,
+ GameVersionCriteria crit)
+ => replaced_identifiers.Select(replaced => registry.GetReplacement(replaced, crit))
+ .Where(repl => repl != null)
+ .Select(repl => repl.ReplaceWith);
private string StatusSymbol(CkanModule mod)
- {
- return accepted.Contains(mod)
- ? installing
- : notinstalled;
- }
+ => accepted.Contains(mod) ? installing
+ : notinstalled;
private readonly HashSet accepted = new HashSet();
private readonly HashSet rejected;
private readonly IRegistryQuerier registry;
private readonly GameInstanceManager manager;
- private readonly ModuleInstaller installer;
private readonly ChangePlan plan;
private readonly bool debug;
private readonly Dictionary dependencies = new Dictionary();
private readonly ConsoleListBox dependencyList;
- private static readonly string notinstalled = " ";
- private static readonly string installing = "+";
+ private const string notinstalled = " ";
+ private const string installing = "+";
}
///
@@ -221,14 +199,9 @@ private string StatusSymbol(CkanModule mod)
public class Dependency {
///
- /// Identifier of mod
- ///
- public CkanModule module;
-
- ///
- /// True if we default to installing, false otherwise
+ /// The mod
///
- public bool defaultInstall;
+ public CkanModule module;
///
/// List of mods that recommended or suggested this mod
diff --git a/Core/Repositories/RepositoryData.cs b/Core/Repositories/RepositoryData.cs
index e6ef66240..3b4e11ef7 100644
--- a/Core/Repositories/RepositoryData.cs
+++ b/Core/Repositories/RepositoryData.cs
@@ -372,7 +372,7 @@ private static CkanModule ProcessRegistryMetadataFromJSON(string metadata, strin
}
// If we haven't handled our exception, then it really was exceptional.
- if (handled == false)
+ if (!handled)
{
if (exception == null)
{