Skip to content

Commit

Permalink
Pre-release handling
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 19, 2024
1 parent 46ae1e0 commit 560b81d
Show file tree
Hide file tree
Showing 132 changed files with 2,186 additions and 1,186 deletions.
10 changes: 6 additions & 4 deletions Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ public Available(RepositoryDataManager repoData, IUser user)

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

IEnumerable<CkanModule> compatible = registry
.CompatibleModules(instance.VersionCriteria())
IEnumerable<CkanModule> compatible = RegistryManager
.Instance(instance, repoData)
.registry
.CompatibleModules(instance.StabilityToleranceConfig,
instance.VersionCriteria())
.Where(m => !m.IsDLC)
.OrderBy(m => m.identifier);

Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public int RunCommand(CKAN.GameInstance instance, object options)
{
HashSet<string>? possibleConfigOnlyDirs = null;
installer.InstallList(toInstall,
new RelationshipResolverOptions(),
new RelationshipResolverOptions(instance.StabilityToleranceConfig),
regMgr,
ref possibleConfigOnlyDirs,
opts?.NetUserAgent);
Expand Down
7 changes: 4 additions & 3 deletions Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
(options?.allow_incompatible ?? false)
? null
: crit)
?? registry.LatestAvailable(arg, crit,
null, installed)
?? registry.LatestAvailable(arg,
instance.StabilityToleranceConfig,
crit, null, installed)
?? registry.InstalledModule(arg)?.Module)
.OfType<CkanModule>()
.ToList();
Expand All @@ -102,7 +103,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}

var installer = new ModuleInstaller(instance, manager.Cache, user, options?.NetUserAgent);
var install_ops = new RelationshipResolverOptions
var install_ops = new RelationshipResolverOptions(instance.StabilityToleranceConfig)
{
with_all_suggests = options?.with_all_suggests ?? false,
with_suggests = options?.with_suggests ?? false,
Expand Down
12 changes: 9 additions & 3 deletions Cmdline/Action/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
{
// Check if upgrades are available, and show appropriately.
log.DebugFormat("Check if upgrades are available for {0}", mod.Key);
var latest = registry.LatestAvailable(mod.Key, instance.VersionCriteria());
var latest = registry.LatestAvailable(mod.Key,
instance.StabilityToleranceConfig,
instance.VersionCriteria());
var current = registry.GetInstalledVersion(mod.Key);
var inst = registry.InstalledModule(mod.Key);

Expand All @@ -103,7 +105,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
// Check if mod is replaceable
else if (current.replaced_by != null)
{
var replacement = registry.GetReplacement(mod.Key, instance.VersionCriteria());
var replacement = registry.GetReplacement(mod.Key,
instance.StabilityToleranceConfig,
instance.VersionCriteria());
if (replacement != null)
{
// Replaceable!
Expand All @@ -120,7 +124,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
// Check if mod is replaceable
if (current?.replaced_by != null)
{
var replacement = registry.GetReplacement(latest.identifier, instance.VersionCriteria());
var replacement = registry.GetReplacement(latest.identifier,
instance.StabilityToleranceConfig,
instance.VersionCriteria());
if (replacement != null)
{
// Replaceable!
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Prompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private string[] GetAvailIdentifiers(string prefix)
CKAN.GameInstance inst = MainClass.GetGameInstance(manager);
return RegistryManager.Instance(inst, repoData)
.registry
.CompatibleModules(inst.VersionCriteria())
.CompatibleModules(inst.StabilityToleranceConfig, inst.VersionCriteria())
.Where(m => !m.IsDLC)
.Select(m => m.identifier)
.Where(ident => ident.StartsWith(prefix,
Expand Down
10 changes: 7 additions & 3 deletions Cmdline/Action/Replace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}

// Prepare options. Can these all be done in the new() somehow?
var replace_ops = new RelationshipResolverOptions
var replace_ops = new RelationshipResolverOptions(instance.StabilityToleranceConfig)
{
with_all_suggests = options.with_all_suggests,
with_suggests = options.with_suggests,
Expand Down Expand Up @@ -68,7 +68,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
log.DebugFormat("Testing {0} {1} for possible replacement", mod.Key, mod.Value);
// Check if replacement is available

var replacement = registry.GetReplacement(mod.Key, instance.VersionCriteria());
var replacement = registry.GetReplacement(mod.Key,
instance.StabilityToleranceConfig,
instance.VersionCriteria());
if (replacement != null)
{
// Replaceable
Expand Down Expand Up @@ -100,7 +102,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
try
{
// Check if replacement is available
var replacement = registry.GetReplacement(modToReplace.identifier, instance.VersionCriteria());
var replacement = registry.GetReplacement(modToReplace.identifier,
instance.StabilityToleranceConfig,
instance.VersionCriteria());
if (replacement != null)
{
// Replaceable
Expand Down
4 changes: 2 additions & 2 deletions Cmdline/Action/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class RepoAddOptions : InstanceSpecificOptions
public class RepoPriorityOptions : InstanceSpecificOptions
{
[ValueOption(0)] public string? name { get; set; }
[ValueOption(1)] public int priority { get; set; }
[ValueOption(1)] public int priority { get; set; }
}

public class RepoDefaultOptions : InstanceSpecificOptions
Expand Down Expand Up @@ -459,6 +459,6 @@ private void PrintUsage(string verb)
private readonly RepositoryDataManager repoData;
private IUser? user;

private static readonly ILog log = LogManager.GetLogger(typeof (Repo));
private static readonly ILog log = LogManager.GetLogger(typeof(Repo));
}
}
33 changes: 18 additions & 15 deletions Cmdline/Action/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public Search(RepositoryDataManager repoData, IUser user)
this.user = user;
}

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

Expand All @@ -32,11 +32,11 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
return Exit.BADOPT;
}

var matching_compatible = PerformSearch(ksp, options.search_term, options.author_term, false);
var matching_compatible = PerformSearch(instance, options.search_term, options.author_term, false);
var matching_incompatible = new List<CkanModule>();
if (options.all)
{
matching_incompatible = PerformSearch(ksp, options.search_term, options.author_term, true);
matching_incompatible = PerformSearch(instance, options.search_term, options.author_term, true);
}

// Show how many matches we have.
Expand Down Expand Up @@ -94,10 +94,10 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
user.RaiseMessage(Properties.Resources.SearchIncompatibleModsHeader);
foreach (CkanModule mod in matching_incompatible)
{
CkanModule.GetMinMaxVersions(new List<CkanModule> { mod } , out _, out _, out var minKsp, out var maxKsp);
var gv = GameVersionRange.VersionSpan(ksp.game,
minKsp ?? GameVersion.Any,
maxKsp ?? GameVersion.Any)
CkanModule.GetMinMaxVersions(new List<CkanModule> { mod } , out _, out _, out var mininstance, out var maxinstance);
var gv = GameVersionRange.VersionSpan(instance.game,
mininstance ?? GameVersion.Any,
maxinstance ?? GameVersion.Any)
.ToString();

user.RaiseMessage(Properties.Resources.SearchIncompatibleMod,
Expand Down Expand Up @@ -125,15 +125,15 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
}

/// <summary>
/// Searches for the term in the list of compatible or incompatible modules for the ksp instance.
/// Searches for the term in the list of compatible or incompatible modules for the instance instance.
/// Looks in name, identifier and description fields, and if given, restricts to authors matching the author term.
/// </summary>
/// <returns>List of matching modules.</returns>
/// <param name="ksp">The KSP instance to perform the search for.</param>
/// <param name="instance">The instance instance to perform the search for.</param>
/// <param name="term">The search term. Case insensitive.</param>
/// <param name="author">Name of author to find</param>
/// <param name="searchIncompatible">True to look for incompatible modules, false (default) to look for compatible</param>
public List<CkanModule> PerformSearch(CKAN.GameInstance ksp,
public List<CkanModule> PerformSearch(CKAN.GameInstance instance,
string? term,
string? author = null,
bool searchIncompatible = false)
Expand All @@ -142,11 +142,12 @@ public List<CkanModule> PerformSearch(CKAN.GameInstance ksp,
term = string.IsNullOrWhiteSpace(term) ? string.Empty : CkanModule.nonAlphaNums.Replace(term, "");
author = string.IsNullOrWhiteSpace(author) ? string.Empty : CkanModule.nonAlphaNums.Replace(author, "");

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

return searchIncompatible
? registry
.IncompatibleModules(ksp.VersionCriteria())
.IncompatibleModules(instance.StabilityToleranceConfig,
instance.VersionCriteria())
// Look for a match in each string.
.Where(module => (module.SearchableName.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableIdentifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
Expand All @@ -155,7 +156,8 @@ public List<CkanModule> PerformSearch(CKAN.GameInstance ksp,
&& module.SearchableAuthors.Any((auth) => auth.IndexOf(author, StringComparison.OrdinalIgnoreCase) > -1))
.ToList()
: registry
.CompatibleModules(ksp.VersionCriteria())
.CompatibleModules(instance.StabilityToleranceConfig,
instance.VersionCriteria())
// Look for a match in each string.
.Where(module => (module.SearchableName.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableIdentifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
Expand Down Expand Up @@ -190,9 +192,10 @@ private static string CaseInsensitiveExactMatch(List<CkanModule> mods, string mo
/// <param name="modules">List of strings to convert, format 'identifier' or 'identifier=version'</param>
public static void AdjustModulesCase(CKAN.GameInstance instance, Registry registry, List<string> modules)
{
var stabilityTolerance = instance.StabilityToleranceConfig;
// Get the list of all compatible and incompatible mods
List<CkanModule> mods = registry.CompatibleModules(instance.VersionCriteria()).ToList();
mods.AddRange(registry.IncompatibleModules(instance.VersionCriteria()));
var mods = registry.CompatibleModules(stabilityTolerance, instance.VersionCriteria()).ToList();
mods.AddRange(registry.IncompatibleModules(stabilityTolerance, instance.VersionCriteria()));
for (int i = 0; i < modules.Count; ++i)
{
Match match = CkanModule.idAndVersionMatcher.Match(modules[i]);
Expand Down
3 changes: 2 additions & 1 deletion Cmdline/Action/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)

// Module was not installed, look for an exact match in the available modules,
// either by "name" (the user-friendly display name) or by identifier
var moduleToShow = registry.CompatibleModules(instance.VersionCriteria())
var moduleToShow = registry.CompatibleModules(instance.StabilityToleranceConfig,
instance.VersionCriteria())
.SingleOrDefault(
mod => mod.name == modName
|| mod.identifier == modName);
Expand Down
Loading

0 comments on commit 560b81d

Please sign in to comment.