Skip to content

Commit

Permalink
Merge #2886 - Use current metadata for installed module compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Oct 19, 2019
2 parents 9992941 + f58be31 commit 37f5388
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- [Multiple] Fail on http status codes >=300 for cURL downloads (#2879 by: DasSkelett; reviewed: HebaruSan)
- [Multiple] Normalize install paths (#2887 by: HebaruSan; reviewed: DasSkelett)
- [Multiple] Fixes for KSP in Windows drive root (#2857 by: HebaruSan; reviewed: DasSkelett)
- [GUI] Use current metadata for installed module compatibility (#2886 by: HebaruSan; reviewed: DasSkelett)

### Internal

Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
{
AvailableOptions opts = (AvailableOptions)raw_options;
IRegistryQuerier registry = RegistryManager.Instance(ksp).registry;
List<CkanModule> available = registry.Available(ksp.VersionCriteria());
var available = registry.Available(ksp.VersionCriteria());

user.RaiseMessage("Mods available for KSP {0}", ksp.Version());
user.RaiseMessage("");
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static void AdjustModulesCase(CKAN.KSP ksp, List<string> modules)
{
IRegistryQuerier registry = RegistryManager.Instance(ksp).registry;
// Get the list of all compatible and incompatible mods
List<CkanModule> mods = registry.Available(ksp.VersionCriteria());
List<CkanModule> mods = registry.Available(ksp.VersionCriteria()).ToList();
mods.AddRange(registry.Incompatible(ksp.VersionCriteria()));
for (int i = 0; i < modules.Count; ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
{
// Get a list of available modules prior to the update.
var registry = RegistryManager.Instance(ksp).registry;
available_prior = registry.Available(ksp.VersionCriteria());
available_prior = registry.Available(ksp.VersionCriteria()).ToList();
}

// If no repository is selected, select all.
Expand Down Expand Up @@ -69,7 +69,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
if (options.list_changes)
{
var registry = RegistryManager.Instance(ksp).registry;
PrintChanges(available_prior, registry.Available(ksp.VersionCriteria()));
PrintChanges(available_prior, registry.Available(ksp.VersionCriteria()).ToList());
}

return Exit.OK;
Expand Down Expand Up @@ -154,7 +154,7 @@ private void UpdateRepository(CKAN.KSP ksp, string repository = null)
: CKAN.Repo.Update(registry_manager, ksp, user, repository);

user.RaiseMessage("Updated information on {0} available modules",
registry_manager.registry.Available(ksp.VersionCriteria()).Count);
registry_manager.registry.Available(ksp.VersionCriteria()).Count());
}
}
}
3 changes: 2 additions & 1 deletion ConsoleUI/ModInfoScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;
using CKAN.Versioning;
using CKAN.ConsoleUI.Toolkit;

Expand Down Expand Up @@ -312,7 +313,7 @@ private int addVersionDisplay()

if (ChangePlan.IsAnyAvailable(registry, mod.identifier)) {

List<CkanModule> avail = registry.AllAvailable( mod.identifier);
List<CkanModule> avail = registry.AllAvailable(mod.identifier).ToList();
CkanModule inst = registry.GetInstalledVersion(mod.identifier);
CkanModule latest = registry.LatestAvailable( mod.identifier, null);
bool installed = registry.IsInstalled(mod.identifier, false);
Expand Down
4 changes: 2 additions & 2 deletions Core/Registry/AvailableModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ public CkanModule ByVersion(ModuleVersion v)
return module;
}

public List<CkanModule> AllAvailable()
public IEnumerable<CkanModule> AllAvailable()
{
// Some code may expect this to be sorted in descending order
return new List<CkanModule>(module_version.Values.Reverse());
return module_version.Values.Reverse();
}

/// <summary>
Expand Down
9 changes: 5 additions & 4 deletions Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using CKAN.Versioning;

namespace CKAN
Expand All @@ -19,7 +20,7 @@ public interface IRegistryQuerier
/// the specified version of KSP.
/// </summary>
// TODO: This name is misleading. It's more a LatestAvailable's'
List<CkanModule> Available(KspVersionCriteria ksp_version);
IEnumerable<CkanModule> Available(KspVersionCriteria ksp_version);

/// <summary>
/// Get full JSON metadata string for a mod's available versions
Expand Down Expand Up @@ -49,7 +50,7 @@ public interface IRegistryQuerier
/// Returns all available version of a module.
/// <exception cref="ModuleNotFoundKraken">Throws if asked for a non-existent module.</exception>
/// </summary>
List<CkanModule> AllAvailable(string identifier);
IEnumerable<CkanModule> AllAvailable(string identifier);

/// <summary>
/// Returns the latest available version of a module that satisifes the specified version and
Expand Down Expand Up @@ -105,7 +106,7 @@ List<CkanModule> LatestAvailableWithProvides(
/// Returns a simple array of all incompatible modules for
/// the specified version of KSP.
/// </summary>
List<CkanModule> Incompatible(KspVersionCriteria ksp_version);
IEnumerable<CkanModule> Incompatible(KspVersionCriteria ksp_version);

/// <summary>
/// Returns a dictionary of all modules installed, along with their
Expand Down Expand Up @@ -194,7 +195,7 @@ public static bool HasUpdate(this IRegistryQuerier querier, string identifier, K
/// </returns>
public static string CompatibleGameVersions(this IRegistryQuerier querier, string identifier)
{
List<CkanModule> releases = querier.AllAvailable(identifier);
List<CkanModule> releases = querier.AllAvailable(identifier).ToList();
if (releases != null && releases.Count > 0) {
ModuleVersion minMod = null, maxMod = null;
KspVersion minKsp = null, maxKsp = null;
Expand Down
15 changes: 5 additions & 10 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,9 @@ public void RemoveAvailable(CkanModule module)
/// <summary>
/// <see cref="IRegistryQuerier.Available"/>
/// </summary>
public List<CkanModule> Available(KspVersionCriteria ksp_version)
public IEnumerable<CkanModule> Available(KspVersionCriteria ksp_version)
{
var candidates = new List<string>(available_modules.Keys);
var compatible = new List<CkanModule>();

// It's nice to see things in alphabetical order, so sort our keys first.
candidates.Sort();
Expand All @@ -492,19 +491,17 @@ public List<CkanModule> Available(KspVersionCriteria ksp_version)
if (available != null
&& allDependenciesCompatible(available, ksp_version))
{
compatible.Add(available);
yield return available;
}
}
return compatible;
}

/// <summary>
/// <see cref="IRegistryQuerier.Incompatible"/>
/// </summary>
public List<CkanModule> Incompatible(KspVersionCriteria ksp_version)
public IEnumerable<CkanModule> Incompatible(KspVersionCriteria ksp_version)
{
var candidates = new List<string>(available_modules.Keys);
var incompatible = new List<CkanModule>();

// It's nice to see things in alphabetical order, so sort our keys first.
candidates.Sort();
Expand All @@ -518,11 +515,9 @@ public List<CkanModule> Incompatible(KspVersionCriteria ksp_version)
if (available == null
|| !allDependenciesCompatible(available, ksp_version))
{
incompatible.Add(LatestAvailable(candidate, null));
yield return LatestAvailable(candidate, null);
}
}

return incompatible;
}

private bool allDependenciesCompatible(CkanModule mod, KspVersionCriteria ksp_version)
Expand Down Expand Up @@ -580,7 +575,7 @@ public CkanModule LatestAvailable(
}


public List<CkanModule> AllAvailable(string module)
public IEnumerable<CkanModule> AllAvailable(string module)
{
log.DebugFormat("Finding all available versions for {0}", module);
try
Expand Down
11 changes: 6 additions & 5 deletions GUI/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public string Version
/// <param name="registry">CKAN registry object for current game instance</param>
/// <param name="current_ksp_version">Current game version</param>
/// <param name="incompatible">If true, mark this module as incompatible</param>
public GUIMod(InstalledModule instMod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
public GUIMod(InstalledModule instMod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool? incompatible = null)
: this(instMod.Module, registry, current_ksp_version, incompatible)
{
IsInstalled = true;
Expand All @@ -152,7 +152,7 @@ public GUIMod(InstalledModule instMod, IRegistryQuerier registry, KspVersionCrit
/// <param name="registry">CKAN registry object for current game instance</param>
/// <param name="current_ksp_version">Current game version</param>
/// <param name="incompatible">If true, mark this module as incompatible</param>
public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool? incompatible = null)
: this(mod.identifier, registry, current_ksp_version, incompatible)
{
Mod = mod;
Expand All @@ -167,7 +167,6 @@ public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria curr
HasUpdate = registry.HasUpdate(mod.identifier, current_ksp_version);
HasReplacement = registry.GetReplacement(mod, current_ksp_version) != null;
DownloadSize = mod.download_size == 0 ? Properties.Resources.GUIModNSlashA : CkanModule.FmtSize(mod.download_size);
IsIncompatible = IsIncompatible || !mod.IsCompatibleKSP(current_ksp_version);

if (mod.resources != null)
{
Expand All @@ -194,10 +193,12 @@ public GUIMod(CkanModule mod, IRegistryQuerier registry, KspVersionCriteria curr
/// <param name="registry">CKAN registry object for current game instance</param>
/// <param name="current_ksp_version">Current game version</param>
/// <param name="incompatible">If true, mark this module as incompatible</param>
public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool incompatible = false)
public GUIMod(string identifier, IRegistryQuerier registry, KspVersionCriteria current_ksp_version, bool? incompatible = null)
{
Identifier = identifier;
IsIncompatible = incompatible;
IsIncompatible = incompatible
?? registry.AllAvailable(identifier)
.All(m => !m.IsCompatibleKSP(current_ksp_version));
IsAutodetected = registry.IsAutodetected(identifier);
DownloadCount = registry.DownloadCount(identifier);
if (registry.IsAutodetected(identifier))
Expand Down
2 changes: 1 addition & 1 deletion GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void _UpdateModsList(IEnumerable<ModChange> mc, Dictionary<string, bool>
AddLogMessage(Properties.Resources.MainModListLoadingAvailable);
gui_mods.UnionWith(
registry.Available(versionCriteria)
.Select(m => new GUIMod(m, registry, versionCriteria))
.Select(m => new GUIMod(m, registry, versionCriteria, false))
);
AddLogMessage(Properties.Resources.MainModListLoadingIncompatible);
gui_mods.UnionWith(
Expand Down
9 changes: 5 additions & 4 deletions Tests/Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Transactions;
using System.Collections.Generic;
using System.Linq;
using CKAN;
using CKAN.Versioning;
using NUnit.Framework;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void Available_NoDLCInstalled_ExcludesModulesDependingOnMH()
registry.AddAvailable(DLCDepender);

// Act
List<CkanModule> avail = registry.Available(v0_24_2);
List<CkanModule> avail = registry.Available(v0_24_2).ToList();

// Assert
Assert.IsFalse(avail.Contains(DLCDepender));
Expand All @@ -129,7 +130,7 @@ public void Available_MHInstalled_IncludesModulesDependingOnMH()
registry.AddAvailable(DLCDepender);

// Act
List<CkanModule> avail = registry.Available(v0_24_2);
List<CkanModule> avail = registry.Available(v0_24_2).ToList();

// Assert
Assert.IsTrue(avail.Contains(DLCDepender));
Expand All @@ -153,7 +154,7 @@ public void Available_MH110Installed_IncludesModulesDependingOnMH110()
registry.AddAvailable(DLCDepender);

// Act
List<CkanModule> avail = registry.Available(v0_24_2);
List<CkanModule> avail = registry.Available(v0_24_2).ToList();

// Assert
Assert.IsTrue(avail.Contains(DLCDepender));
Expand All @@ -177,7 +178,7 @@ public void Available_MH100Installed_ExcludesModulesDependingOnMH110()
registry.AddAvailable(DLCDepender);

// Act
List<CkanModule> avail = registry.Available(v0_24_2);
List<CkanModule> avail = registry.Available(v0_24_2).ToList();

// Assert
Assert.IsFalse(avail.Contains(DLCDepender));
Expand Down

0 comments on commit 37f5388

Please sign in to comment.