Skip to content

Commit

Permalink
Trivial coding style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 17, 2024
1 parent e8cb3de commit 95e3cf6
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Cmdline/Action/Prompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private string[] GetInstIdentifiers(string prefix)
CKAN.GameInstance inst = MainClass.GetGameInstance(manager);
var registry = RegistryManager.Instance(inst, repoData).registry;
return registry.Installed(false, false)
.Select(kvp => kvp.Key)
.Keys
.Where(ident => ident.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)
&& !registry.GetInstalledVersion(ident).IsDLC)
.ToArray();
Expand All @@ -214,7 +214,7 @@ private static bool WantsGameInstances(TypeInfo ti)

private string[] GetGameInstances(string prefix)
=> manager.Instances
.Select(kvp => kvp.Key)
.Keys
.Where(ident => ident.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase))
.ToArray();

Expand Down
28 changes: 19 additions & 9 deletions Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
/// <param name="user">IUser object for output</param>
/// <param name="instance">Game instance to use</param>
/// <param name="modules">List of modules to upgrade</param>
private void UpgradeModules(GameInstanceManager manager, IUser user, CKAN.GameInstance instance, bool ConfirmPrompt, List<CkanModule> modules)
private void UpgradeModules(GameInstanceManager manager,
IUser user,
CKAN.GameInstance instance,
bool ConfirmPrompt,
List<CkanModule> modules)
{
UpgradeModules(manager, user, instance, repoData,
UpgradeModules(
manager, user, instance, repoData,
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string> possibleConfigOnlyDirs) =>
installer.Upgrade(modules, downloader,
ref possibleConfigOnlyDirs, regMgr, true, true, ConfirmPrompt),
Expand All @@ -210,9 +215,13 @@ private void UpgradeModules(GameInstanceManager manager, IUser user, CKAN.GameIn
/// <param name="user">IUser object for output</param>
/// <param name="instance">Game instance to use</param>
/// <param name="identsAndVersions">List of identifier[=version] to upgrade</param>
private void UpgradeModules(GameInstanceManager manager, IUser user, CKAN.GameInstance instance, List<string> identsAndVersions)
private void UpgradeModules(GameInstanceManager manager,
IUser user,
CKAN.GameInstance instance,
List<string> identsAndVersions)
{
UpgradeModules(manager, user, instance, repoData,
UpgradeModules(
manager, user, instance, repoData,
(ModuleInstaller installer, NetAsyncModulesDownloader downloader, RegistryManager regMgr, ref HashSet<string> possibleConfigOnlyDirs) =>
installer.Upgrade(
identsAndVersions.Select(arg => CkanModule.FromIDandVersion(
Expand Down Expand Up @@ -241,11 +250,12 @@ private void UpgradeModules(GameInstanceManager manager, IUser user, CKAN.GameIn
/// <param name="instance">Game instance to use</param>
/// <param name="attemptUpgradeCallback">Function to call to try to perform the actual upgrade, may throw TooManyModsProvideKraken</param>
/// <param name="addUserChoiceCallback">Function to call when the user has requested a new module added to the change set in response to TooManyModsProvideKraken</param>
private void UpgradeModules(
GameInstanceManager manager, IUser user, CKAN.GameInstance instance,
RepositoryDataManager repoData,
AttemptUpgradeAction attemptUpgradeCallback,
Action<CkanModule> addUserChoiceCallback)
private void UpgradeModules(GameInstanceManager manager,
IUser user,
CKAN.GameInstance instance,
RepositoryDataManager repoData,
AttemptUpgradeAction attemptUpgradeCallback,
Action<CkanModule> addUserChoiceCallback)
{
using (TransactionScope transact = CkanTransaction.CreateTransactionScope()) {
var installer = new ModuleInstaller(instance, manager.Cache, user);
Expand Down
5 changes: 3 additions & 2 deletions ConsoleUI/InstallScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ public override void Run(ConsoleTheme theme, Action<ConsoleTheme> process = null
// Reset this so we stop unless an exception sets it to true
retry = false;

RegistryManager regMgr = RegistryManager.Instance(manager.CurrentInstance, repoData);
var regMgr = RegistryManager.Instance(manager.CurrentInstance, repoData);
var registry = regMgr.registry;

// GUI prompts user to choose recs/sugs,
// CmdLine assumes recs and ignores sugs
if (plan.Install.Count > 0) {
// Track previously rejected optional dependencies and don't prompt for them again.
DependencyScreen ds = new DependencyScreen(manager, regMgr.registry, plan, rejected, debug);
DependencyScreen ds = new DependencyScreen(manager, registry, plan, rejected, debug);
if (ds.HaveOptions()) {
LaunchSubScreen(theme, ds);
}
Expand Down
21 changes: 12 additions & 9 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,13 @@ private void labelMenuItem_Click(object sender, EventArgs e)

private void editLabelsToolStripMenuItem_Click(object sender, EventArgs e)
{
EditLabelsDialog eld = new EditLabelsDialog(Main.Instance.currentUser, Main.Instance.Manager, mainModList.ModuleLabels);
var eld = new EditLabelsDialog(Main.Instance.currentUser, Main.Instance.Manager, mainModList.ModuleLabels);
eld.ShowDialog(this);
eld.Dispose();
mainModList.ModuleLabels.Save(ModuleLabelList.DefaultPath);
var inst = Main.Instance.CurrentInstance;
var registry = RegistryManager.Instance(inst, repoData).registry;
foreach (GUIMod module in mainModList.Modules)
foreach (var module in mainModList.Modules)
{
mainModList.ReapplyLabels(module, Conflicts?.ContainsKey(module) ?? false, inst.Name, inst.game, registry);
}
Expand Down Expand Up @@ -1271,6 +1271,8 @@ private void _UpdateFilters()
var inst = Main.Instance.CurrentInstance;
var registry = RegistryManager.Instance(inst, repoData).registry;
ModGrid.Rows.Clear();
var instName = inst.Name;
var instGame = inst.game;
rows.AsParallel().ForAll(row =>
row.Visible = mainModList.IsVisible((GUIMod)row.Tag,
inst.Name, inst.game, registry));
Expand Down Expand Up @@ -1300,7 +1302,8 @@ private bool _UpdateModsList(Dictionary<string, bool> old_modules = null)
{
log.Info("Updating the mod list");

var regMgr = RegistryManager.Instance(Main.Instance.CurrentInstance, repoData);
var inst = Main.Instance.CurrentInstance;
var regMgr = RegistryManager.Instance(inst, repoData);
IRegistryQuerier registry = regMgr.registry;

repoData.Prepopulate(
Expand All @@ -1318,7 +1321,7 @@ private bool _UpdateModsList(Dictionary<string, bool> old_modules = null)
regMgr.ScanUnmanagedFiles();

RaiseMessage?.Invoke(Properties.Resources.MainModListLoadingInstalled);
var versionCriteria = Main.Instance.CurrentInstance.VersionCriteria();
var versionCriteria = inst.VersionCriteria();

var installedIdents = registry.InstalledModules
.Select(im => im.identifier)
Expand Down Expand Up @@ -1385,11 +1388,11 @@ private bool _UpdateModsList(Dictionary<string, bool> old_modules = null)
RaiseMessage?.Invoke(Properties.Resources.MainModListPopulatingList);
// Update our mod listing
mainModList.ConstructModList(gui_mods,
Main.Instance.CurrentInstance.Name,
Main.Instance.CurrentInstance.game,
inst.Name,
inst.game,
ChangeSet);

UpdateChangeSetAndConflicts(Main.Instance.CurrentInstance, registry);
UpdateChangeSetAndConflicts(inst, registry);

RaiseMessage?.Invoke(Properties.Resources.MainModListUpdatingFilters);

Expand Down Expand Up @@ -1663,10 +1666,10 @@ private int VersionPieceCompare(bool definedA, int valA, bool definedB, int valB
? (definedB ? valA.CompareTo(valB) : -1)
: (definedB ? 1 : 0);

public void ResetFilterAndSelectModOnList(string key)
public void ResetFilterAndSelectModOnList(CkanModule module)
{
EditModSearches.Clear();
FocusMod(key, true);
FocusMod(module.identifier, true);
}

public GUIMod SelectedModule =>
Expand Down
2 changes: 2 additions & 0 deletions GUI/Controls/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public ModInfo()
{
InitializeComponent();
Contents.OnDownloadClick += gmod => OnDownloadClick?.Invoke(gmod);
Relationships.ModuleDoubleClicked += mod => ModuleDoubleClicked?.Invoke(mod);
}

public GUIMod SelectedModule
Expand Down Expand Up @@ -54,6 +55,7 @@ public void RefreshModContentsTree()

public event Action<GUIMod> OnDownloadClick;
public event Action<SavedSearch, bool> OnChangeFilter;
public event Action<CkanModule> ModuleDoubleClicked;

protected override void OnResize(EventArgs e)
{
Expand Down
7 changes: 3 additions & 4 deletions GUI/Controls/ModInfoTabs/Contents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public GUIMod SelectedModule
{
set
{
var module = value?.ToModule();
if (value != selectedModule)
{
selectedModule = value;
Expand Down Expand Up @@ -93,7 +92,7 @@ private void _UpdateModContentsTree(CkanModule module, bool force = false)
ContentsPreviewTree.Enabled = true;
ContentsPreviewTree.Nodes.Clear();
var rootNode = ContentsPreviewTree.Nodes.Add("", module.ToString(), "folderZip", "folderZip");
if (!Main.Instance.Manager.Cache.IsMaybeCachedZip(module))
if (!manager.Cache.IsMaybeCachedZip(module))
{
NotCachedLabel.Text = Properties.Resources.ModInfoNotCached;
ContentsDownloadButton.Enabled = true;
Expand All @@ -103,7 +102,7 @@ private void _UpdateModContentsTree(CkanModule module, bool force = false)
else
{
rootNode.Text = Path.GetFileName(
Main.Instance.Manager.Cache.GetCachedFilename(module));
manager.Cache.GetCachedFilename(module));
NotCachedLabel.Text = Properties.Resources.ModInfoCached;
ContentsDownloadButton.Enabled = false;
ContentsOpenButton.Enabled = true;
Expand All @@ -114,7 +113,7 @@ private void _UpdateModContentsTree(CkanModule module, bool force = false)
{
var paths = new ModuleInstaller(
manager.CurrentInstance,
Main.Instance.Manager.Cache,
manager.Cache,
Main.Instance.currentUser)
.GetModuleContentsList(module)
// Load fully in bg
Expand Down
4 changes: 3 additions & 1 deletion GUI/Controls/ModInfoTabs/Relationships.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public GUIMod SelectedModule
get => selectedModule;
}

public event Action<CkanModule> ModuleDoubleClicked;

private void UpdateModDependencyGraph(CkanModule module)
{
Util.Invoke(DependsGraphTree, () => _UpdateModDependencyGraph(module));
Expand All @@ -87,7 +89,7 @@ private void UpdateModDependencyGraph(CkanModule module)

private void DependsGraphTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
Main.Instance.ManageMods.ResetFilterAndSelectModOnList(e.Node.Name);
ModuleDoubleClicked?.Invoke(e.Node.Tag as CkanModule);
}

private bool ImMyOwnGrandpa(TreeNode node)
Expand Down
2 changes: 1 addition & 1 deletion GUI/Dialogs/ErrorDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ErrorDialog()
[ForbidGUICalls]
public void ShowErrorDialog(string text, params object[] args)
{
Util.Invoke(Main.Instance, () =>
Util.Invoke(this, () =>
{
log.ErrorFormat(text, args);
// Append to previous text, if any
Expand Down
2 changes: 1 addition & 1 deletion GUI/Dialogs/ManageGameInstancesDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 95e3cf6

Please sign in to comment.