Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor repository and available module handling #3904

Merged
merged 24 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db0ab11
Trivial format changes
HebaruSan Sep 11, 2023
4b05dce
Remove unnecessary using CKAN.GameVersionProviders
HebaruSan Sep 11, 2023
8390294
Rename IsCompatibleKSP to be game-agnostic
HebaruSan Sep 13, 2023
f8ef2dd
Move Registry.GetMinMaxVersions to CkanModule, add tests
HebaruSan Sep 11, 2023
fd1a784
Move tags index into Registry
HebaruSan Sep 12, 2023
018e3ed
Dispose RegistryManager without accidentally instantiating it
HebaruSan Sep 12, 2023
b7e127b
Game-specific namespaces
HebaruSan Sep 11, 2023
3c78954
Multi-game DLC detection
HebaruSan Sep 12, 2023
1e692f3
Multi-game max game versions
HebaruSan Sep 12, 2023
6eddd43
Better encapsulation of Registry.Repositories
HebaruSan Sep 12, 2023
2bf4ea1
Cache latest (in)compat mods in CompatiblitySorter
HebaruSan Sep 12, 2023
fec8cd7
Move GameInstance.Scan to RegistryManager.ScanUnmanagedFiles
HebaruSan Sep 12, 2023
5ba0ab0
Detect empty tar.gz files
HebaruSan Sep 11, 2023
ec61324
Make InstallationHistory send CkanModule instead of GUIMod
HebaruSan Sep 12, 2023
0011f93
Suppress Versions tab flickering
HebaruSan Sep 12, 2023
f91aabc
Repo settings double click and deletion prevention
HebaruSan Sep 12, 2023
d33913d
Fix failed downloads crash, show original exception
HebaruSan Sep 12, 2023
73826b8
Set target.size after successful download
HebaruSan Sep 13, 2023
1523ff2
Refresh or update after changing repos
HebaruSan Sep 13, 2023
7ddc0ed
Create repository data manager
HebaruSan Sep 13, 2023
cbb1d6e
Update existing code to use repo data manager
HebaruSan Sep 13, 2023
c46bbc7
Tests for replaced_by
HebaruSan Sep 13, 2023
666eec9
Shift- or ctrl-click Refresh to override etags check
HebaruSan Sep 13, 2023
008a7a0
Check CanTimeout instead of catching exceptions
HebaruSan Sep 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading