diff --git a/ConsoleUI/ConsoleCKAN.cs b/ConsoleUI/ConsoleCKAN.cs index 0e34799f13..c8d2dbd38c 100644 --- a/ConsoleUI/ConsoleCKAN.cs +++ b/ConsoleUI/ConsoleCKAN.cs @@ -16,7 +16,7 @@ public class ConsoleCKAN { /// public ConsoleCKAN(GameInstanceManager mgr, string themeName, bool debug) { - if (ConsoleTheme.Themes.TryGetValue(themeName, out ConsoleTheme theme)) + if (ConsoleTheme.Themes.TryGetValue(themeName ?? "default", out ConsoleTheme theme)) { // GameInstanceManager only uses its IUser object to construct game instance objects, // which only use it to inform the user about the creation of the CKAN/ folder. @@ -40,7 +40,7 @@ public ConsoleCKAN(GameInstanceManager mgr, string themeName, bool debug) } } if (manager.CurrentInstance != null) { - new ModListScreen(manager, debug).Run(theme); + new ModListScreen(manager, debug, theme).Run(theme); } new ExitScreen().Run(theme); diff --git a/ConsoleUI/ModListScreen.cs b/ConsoleUI/ModListScreen.cs index 96c11a0de8..cbc5555375 100644 --- a/ConsoleUI/ModListScreen.cs +++ b/ConsoleUI/ModListScreen.cs @@ -17,7 +17,7 @@ public class ModListScreen : ConsoleScreen { /// /// Game instance manager object containing the current instance /// True if debug options should be available, false otherwise - public ModListScreen(GameInstanceManager mgr, bool dbg) + public ModListScreen(GameInstanceManager mgr, bool dbg, ConsoleTheme _theme) { debug = dbg; manager = mgr; @@ -25,7 +25,7 @@ public ModListScreen(GameInstanceManager mgr, bool dbg) moduleList = new ConsoleListBox( 1, 4, -1, -2, - GetAllMods(), + GetAllMods(_theme), new List>() { new ConsoleListBoxColumn() { Header = "", @@ -205,7 +205,7 @@ public ModListScreen(GameInstanceManager mgr, bool dbg) } return true; }); - + moduleList.AddTip("F8", "Mark auto-installed", () => moduleList.Selection != null && !moduleList.Selection.IsDLC && (!registry.InstalledModule(moduleList.Selection.identifier)?.AutoInstalled ?? false) @@ -265,7 +265,7 @@ public ModListScreen(GameInstanceManager mgr, bool dbg) null, new ConsoleMenuOption("Refresh mod list", "F5, Ctrl+R", "Refresh the list of mods", - true, UpdateRegistry), + true, (ConsoleTheme th) => UpdateRegistry(th)), new ConsoleMenuOption("Upgrade all", "Ctrl+U", "Mark all available updates for installation", true, UpgradeAll, null, null, HasAnyUpgradeable()), @@ -328,7 +328,7 @@ protected override string CenterHeader() private bool ImportDownloads(ConsoleTheme theme) { DownloadImportDialog.ImportDownloads(theme, manager.CurrentInstance, manager.Cache, plan); - RefreshList(); + RefreshList(theme); return true; } @@ -393,7 +393,7 @@ private bool ViewSuggestions(ConsoleTheme theme) } } if (needRefresh) { - RefreshList(); + RefreshList(theme); } } else { RaiseError("Installed mods have no unsatisfied recommendations or suggestions."); @@ -414,7 +414,7 @@ private int daysSinceUpdated(string filename) return (DateTime.Now - File.GetLastWriteTime(filename)).Days; } - private bool UpdateRegistry(ConsoleTheme theme) + private bool UpdateRegistry(ConsoleTheme theme, bool showNewModsPrompt = true) { ProgressScreen ps = new ProgressScreen("Updating Registry", "Checking for updates"); LaunchSubScreen(theme, ps, (ConsoleTheme th) => { @@ -447,11 +447,11 @@ private bool UpdateRegistry(ConsoleTheme theme) } } }); - if (recent.Count > 0 && RaiseYesNoDialog(newModPrompt(recent.Count))) { + if (showNewModsPrompt && recent.Count > 0 && RaiseYesNoDialog(newModPrompt(recent.Count))) { searchBox.Clear(); moduleList.FilterString = searchBox.Value = "~n"; } - RefreshList(); + RefreshList(theme); return true; } @@ -481,7 +481,7 @@ private bool SelectInstall(ConsoleTheme theme) if (!prevInst.Equals(manager.CurrentInstance)) { plan.Reset(); registry = RegistryManager.Instance(manager.CurrentInstance).registry; - RefreshList(); + RefreshList(theme); } return true; } @@ -492,17 +492,23 @@ private bool EditAuthTokens(ConsoleTheme theme) return true; } - private void RefreshList() + private void RefreshList(ConsoleTheme theme) { - moduleList.SetData(GetAllMods(true)); + // In the constructor this is called while moduleList is being populated, just do nothing in this case. + // ModListScreen -> moduleList = (GetAllMods ...) -> UpdateRegistry -> RefreshList + moduleList?.SetData(GetAllMods(theme,true)); } private List allMods = null; - private List GetAllMods(bool force = false) + private List GetAllMods(ConsoleTheme theme, bool force = false) { ScanForMods(); if (allMods == null || force) { + if (!registry?.HasAnyAvailable() ?? false) + { + UpdateRegistry(theme, false); + } allMods = new List(registry.CompatibleModules(manager.CurrentInstance.VersionCriteria())); foreach (InstalledModule im in registry.InstalledModules) { CkanModule m = null; @@ -546,7 +552,7 @@ private bool Help(ConsoleTheme theme) private bool ApplyChanges(ConsoleTheme theme) { LaunchSubScreen(theme, new InstallScreen(manager, plan, debug)); - RefreshList(); + RefreshList(theme); return true; } @@ -598,9 +604,9 @@ private long totalInstalledDownloadSize() return total; } - private GameInstanceManager manager; - private IRegistryQuerier registry; - private bool debug; + private GameInstanceManager manager; + private Registry registry; + private bool debug; private ConsoleField searchBox; private ConsoleListBox moduleList; @@ -839,7 +845,7 @@ public enum InstallStatus { /// This mod is installed and not upgradeable or planned to be removed /// Installed, - + /// /// Like Installed, but can be auto-removed if depending mods are removed ///