Skip to content

Commit

Permalink
Refresh registry when loading an instance with empty registry in Cons…
Browse files Browse the repository at this point in the history
…oleUI
  • Loading branch information
DasSkelett committed Mar 5, 2021
1 parent 38b9cf3 commit 91c2071
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ConsoleUI/ConsoleCKAN.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConsoleCKAN {
/// </summary>
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.
Expand All @@ -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);
Expand Down
42 changes: 24 additions & 18 deletions ConsoleUI/ModListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class ModListScreen : ConsoleScreen {
/// </summary>
/// <param name="mgr">Game instance manager object containing the current instance</param>
/// <param name="dbg">True if debug options should be available, false otherwise</param>
public ModListScreen(GameInstanceManager mgr, bool dbg)
public ModListScreen(GameInstanceManager mgr, bool dbg, ConsoleTheme _theme)
{
debug = dbg;
manager = mgr;
registry = RegistryManager.Instance(manager.CurrentInstance).registry;

moduleList = new ConsoleListBox<CkanModule>(
1, 4, -1, -2,
GetAllMods(),
GetAllMods(_theme),
new List<ConsoleListBoxColumn<CkanModule>>() {
new ConsoleListBoxColumn<CkanModule>() {
Header = "",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -393,7 +393,7 @@ private bool ViewSuggestions(ConsoleTheme theme)
}
}
if (needRefresh) {
RefreshList();
RefreshList(theme);
}
} else {
RaiseError("Installed mods have no unsatisfied recommendations or suggestions.");
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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<CkanModule> allMods = null;

private List<CkanModule> GetAllMods(bool force = false)
private List<CkanModule> GetAllMods(ConsoleTheme theme, bool force = false)
{
ScanForMods();
if (allMods == null || force) {
if (!registry?.HasAnyAvailable() ?? false)
{
UpdateRegistry(theme, false);
}
allMods = new List<CkanModule>(registry.CompatibleModules(manager.CurrentInstance.VersionCriteria()));
foreach (InstalledModule im in registry.InstalledModules) {
CkanModule m = null;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<CkanModule> moduleList;
Expand Down Expand Up @@ -839,7 +845,7 @@ public enum InstallStatus {
/// This mod is installed and not upgradeable or planned to be removed
/// </summary>
Installed,

/// <summary>
/// Like Installed, but can be auto-removed if depending mods are removed
/// </summary>
Expand Down

0 comments on commit 91c2071

Please sign in to comment.