Skip to content

Commit

Permalink
Merge #3904 Refactor repository and available module handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Sep 15, 2023
2 parents b901adb + 008a7a0 commit 5588442
Show file tree
Hide file tree
Showing 153 changed files with 5,032 additions and 3,534 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Show recommendations of full changeset with opt-out (#3892 by: HebaruSan; reviewed: techman83)
- [Multiple] Dutch translation and icon duplication guardrails (#3897 by: HebaruSan; reviewed: techman83)
- [GUI] Shorten toolbar button labels (#3903 by: HebaruSan; reviewed: techman83)
- [Multiple] Refactor repository and available module handling (#3904 by: HebaruSan; reviewed: techman83)

### Bugfixes

Expand Down
16 changes: 9 additions & 7 deletions Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ namespace CKAN.CmdLine
{
public class Available : ICommand
{
public IUser user { get; set; }

public Available(IUser user)
public Available(RepositoryDataManager repoData, IUser user)
{
this.user = user;
this.repoData = repoData;
this.user = user;
}

public int RunCommand(CKAN.GameInstance instance, object raw_options)
{
AvailableOptions opts = (AvailableOptions)raw_options;
IRegistryQuerier registry = RegistryManager.Instance(instance).registry;
AvailableOptions opts = (AvailableOptions)raw_options;
IRegistryQuerier registry = RegistryManager.Instance(instance, repoData).registry;

var compatible = registry
.CompatibleModules(instance.VersionCriteria())
.Where(m => !m.IsDLC);
Expand All @@ -42,5 +41,8 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)

return Exit.OK;
}

private IUser user;
private RepositoryDataManager repoData;
}
}
4 changes: 3 additions & 1 deletion Cmdline/Action/Compat.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Linq;
using CKAN.Versioning;

using CommandLine;
using CommandLine.Text;

using CKAN.Versioning;

namespace CKAN.CmdLine
{
public class CompatOptions : VerbCommandOptions
Expand Down
4 changes: 2 additions & 2 deletions Cmdline/Action/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ private int RemoveFilters(FilterRemoveOptions opts, string verb)
return Exit.OK;
}

private GameInstanceManager manager { get; set; }
private IUser user { get; set; }
private GameInstanceManager manager;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Filter));
}
Expand Down
7 changes: 5 additions & 2 deletions Cmdline/Action/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

using CommandLine;
using CommandLine.Text;
using log4net;

using CKAN.Versioning;
using CKAN.Games;
using CKAN.Games.KerbalSpaceProgram.DLC;

namespace CKAN.CmdLine
{
Expand Down Expand Up @@ -566,7 +569,7 @@ int badArgument()
{
if (GameVersion.TryParse(options.makingHistoryVersion, out GameVersion ver))
{
dlcs.Add(new DLC.MakingHistoryDlcDetector(), ver);
dlcs.Add(new MakingHistoryDlcDetector(), ver);
}
else
{
Expand All @@ -578,7 +581,7 @@ int badArgument()
{
if (GameVersion.TryParse(options.breakingGroundVersion, out GameVersion ver))
{
dlcs.Add(new DLC.BreakingGroundDlcDetector(), ver);
dlcs.Add(new BreakingGroundDlcDetector(), ver);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/ICommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface ICommand
{
int RunCommand(CKAN.GameInstance ksp, object options);
int RunCommand(CKAN.GameInstance instance, object options);
}
}
33 changes: 17 additions & 16 deletions Cmdline/Action/Import.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using System;
using System.IO;
using System.Collections.Generic;

using log4net;

namespace CKAN.CmdLine
{

/// <summary>
/// Handler for "ckan import" command.
/// Imports manually downloaded ZIP files into the cache.
/// </summary>
public class Import : ICommand
{

/// <summary>
/// Initialize the command
/// </summary>
/// <param name="user">IUser object for user interaction</param>
public Import(GameInstanceManager mgr, IUser user)
public Import(GameInstanceManager mgr, RepositoryDataManager repoData, IUser user)
{
manager = mgr;
this.user = user;
manager = mgr;
this.repoData = repoData;
this.user = user;
}

/// <summary>
Expand All @@ -31,7 +31,7 @@ public Import(GameInstanceManager mgr, IUser user)
/// <returns>
/// Process exit code
/// </returns>
public int RunCommand(CKAN.GameInstance ksp, object options)
public int RunCommand(CKAN.GameInstance instance, object options)
{
try
{
Expand All @@ -45,19 +45,18 @@ public int RunCommand(CKAN.GameInstance ksp, object options)
else
{
log.InfoFormat("Importing {0} files", toImport.Count);
List<string> toInstall = new List<string>();
RegistryManager regMgr = RegistryManager.Instance(ksp);
ModuleInstaller inst = new ModuleInstaller(ksp, manager.Cache, user);
inst.ImportFiles(toImport, user, mod => toInstall.Add(mod.identifier), regMgr.registry, !opts.Headless);
var toInstall = new List<string>();
var installer = new ModuleInstaller(instance, manager.Cache, user);
var regMgr = RegistryManager.Instance(instance, repoData);
installer.ImportFiles(toImport, user, mod => toInstall.Add(mod.identifier), regMgr.registry, !opts.Headless);
HashSet<string> possibleConfigOnlyDirs = null;
if (toInstall.Count > 0)
{
inst.InstallList(
installer.InstallList(
toInstall,
new RelationshipResolverOptions(),
regMgr,
ref possibleConfigOnlyDirs
);
ref possibleConfigOnlyDirs);
}
return Exit.OK;
}
Expand Down Expand Up @@ -104,9 +103,11 @@ private void AddFile(HashSet<FileInfo> files, string filename)
}
}

private readonly GameInstanceManager manager;
private readonly IUser user;
private static readonly ILog log = LogManager.GetLogger(typeof(Import));
private readonly GameInstanceManager manager;
private readonly RepositoryDataManager repoData;
private readonly IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Import));
}

}
27 changes: 16 additions & 11 deletions Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
using System;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

using log4net;

namespace CKAN.CmdLine
{
public class Install : ICommand
{
private static readonly ILog log = LogManager.GetLogger(typeof(Install));

public IUser user { get; set; }
private GameInstanceManager manager;

/// <summary>
/// Initialize the install command object
/// </summary>
/// <param name="mgr">GameInstanceManager containing our instances</param>
/// <param name="user">IUser object for interaction</param>
public Install(GameInstanceManager mgr, IUser user)
public Install(GameInstanceManager mgr, RepositoryDataManager repoData, IUser user)
{
manager = mgr;
this.user = user;
manager = mgr;
this.repoData = repoData;
this.user = user;
}

/// <summary>
Expand Down Expand Up @@ -101,7 +98,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}
else
{
Search.AdjustModulesCase(instance, options.modules);
Search.AdjustModulesCase(instance,
RegistryManager.Instance(instance, repoData).registry,
options.modules);
}

if (options.modules.Count == 0)
Expand All @@ -127,7 +126,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
install_ops.without_enforce_consistency = true;
}

RegistryManager regMgr = RegistryManager.Instance(instance);
var regMgr = RegistryManager.Instance(instance, repoData);
List<string> modules = options.modules;

for (bool done = false; !done; )
Expand Down Expand Up @@ -268,5 +267,11 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)

return Exit.OK;
}

private GameInstanceManager manager;
private RepositoryDataManager repoData;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Install));
}
}
23 changes: 14 additions & 9 deletions Cmdline/Action/List.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
using System;
using System;
using System.Collections.Generic;

using log4net;

using CKAN.Exporters;
using CKAN.Types;
using CKAN.Versioning;
using log4net;

namespace CKAN.CmdLine
{
public class List : ICommand
{
private static readonly ILog log = LogManager.GetLogger(typeof(List));

public IUser user { get; set; }

public List(IUser user)
public List(RepositoryDataManager repoData, IUser user)
{
this.user = user;
this.repoData = repoData;
this.user = user;
}

public int RunCommand(CKAN.GameInstance instance, object raw_options)
{
ListOptions options = (ListOptions) raw_options;

IRegistryQuerier registry = RegistryManager.Instance(instance).registry;
var regMgr = RegistryManager.Instance(instance, repoData);
var registry = regMgr.registry;

ExportFileType? exportFileType = null;

Expand Down Expand Up @@ -163,5 +163,10 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
default: return null;
}
}

private RepositoryDataManager repoData;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(List));
}
}
17 changes: 11 additions & 6 deletions Cmdline/Action/Mark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;

using CommandLine;
using CommandLine.Text;
using log4net;
Expand All @@ -14,7 +15,10 @@ public class Mark : ISubCommand
/// <summary>
/// Initialize the subcommand
/// </summary>
public Mark() { }
public Mark(RepositoryDataManager repoData)
{
this.repoData = repoData;
}

/// <summary>
/// Run the subcommand
Expand Down Expand Up @@ -77,10 +81,10 @@ private int MarkAuto(MarkAutoOptions opts, bool value, string verb, string descr
return exitCode;
}

var ksp = MainClass.GetGameInstance(manager);
var regMgr = RegistryManager.Instance(ksp);
var instance = MainClass.GetGameInstance(manager);
var regMgr = RegistryManager.Instance(instance, repoData);
bool needSave = false;
Search.AdjustModulesCase(ksp, opts.modules);
Search.AdjustModulesCase(instance, regMgr.registry, opts.modules);
foreach (string id in opts.modules)
{
InstalledModule im = regMgr.registry.InstalledModule(id);
Expand Down Expand Up @@ -115,8 +119,9 @@ private int MarkAuto(MarkAutoOptions opts, bool value, string verb, string descr
return Exit.OK;
}

private IUser user { get; set; }
private GameInstanceManager manager { get; set; }
private GameInstanceManager manager;
private RepositoryDataManager repoData;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Mark));
}
Expand Down
12 changes: 7 additions & 5 deletions Cmdline/Action/Prompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace CKAN.CmdLine

public class Prompt
{
public Prompt(GameInstanceManager mgr)
public Prompt(GameInstanceManager mgr, RepositoryDataManager repoData)
{
manager = mgr;
this.repoData = repoData;
}

public int RunCommand(object raw_options)
Expand Down Expand Up @@ -184,7 +185,7 @@ private static bool WantsAvailIdentifiers(TypeInfo ti)
private string[] GetAvailIdentifiers(string prefix)
{
CKAN.GameInstance inst = MainClass.GetGameInstance(manager);
return RegistryManager.Instance(inst)
return RegistryManager.Instance(inst, repoData)
.registry
.CompatibleModules(inst.VersionCriteria())
.Where(m => !m.IsDLC)
Expand All @@ -201,7 +202,7 @@ private static bool WantsInstIdentifiers(TypeInfo ti)
private string[] GetInstIdentifiers(string prefix)
{
CKAN.GameInstance inst = MainClass.GetGameInstance(manager);
var registry = RegistryManager.Instance(inst).registry;
var registry = RegistryManager.Instance(inst, repoData).registry;
return registry.Installed(false, false)
.Select(kvp => kvp.Key)
.Where(ident => ident.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)
Expand All @@ -219,8 +220,9 @@ private string[] GetGameInstances(string prefix)
.Where(ident => ident.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase))
.ToArray();

private readonly GameInstanceManager manager;
private const string exitCommand = "exit";
private readonly GameInstanceManager manager;
private readonly RepositoryDataManager repoData;
private const string exitCommand = "exit";
}

}
Loading

0 comments on commit 5588442

Please sign in to comment.