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

Select compatible KSP versions #1957

Merged
merged 21 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
295ac5a
Introduced KspVersionCriteria, started to use it across the application
grzegrzk Dec 11, 2016
0fa45cb
User can select compatible KSP versions - list is filtered & updated
grzegrzk Dec 11, 2016
cac3002
Redesigned dialog to choose compatible versions + it also displays ma…
grzegrzk Dec 12, 2016
a35bcd1
Reverted changes made in ChooseKspInstance - the "settings" button is…
grzegrzk Dec 12, 2016
e184753
Compatible versions are stored on disk + warning dialog is displayed …
grzegrzk Dec 12, 2016
7d31e12
Corrected StrictGameComparator, corrected tests, removed unnecessary …
grzegrzk Dec 12, 2016
bb45796
Corrected reference to autofac + removed unnecessary code
grzegrzk Dec 13, 2016
858a02c
Correction for tests
grzegrzk Dec 13, 2016
4ea4e8a
Argh! Removed dependency added by accident when playing with nuget
grzegrzk Dec 13, 2016
d1a58c6
Naming changes to adhere to C# rules
grzegrzk Dec 13, 2016
03176b4
KSP class now accepts only distinct compatible versions
grzegrzk Dec 13, 2016
0763a89
Add IntersectWith method to KspVersionRange
dbent Dec 13, 2016
4b13979
Merge remote-tracking branch 'upstream/feature/kspversionrange_inters…
grzegrzk Dec 14, 2016
c36ace0
Fix Highest/Lowest comparisons with unbounded bounds
dbent Dec 14, 2016
c52d721
Merge remote-tracking branch 'upstream/feature/kspversionrange_inters…
grzegrzk Dec 14, 2016
c40376d
StrictGameComparator is using now KspVersionRange.IntersectWith + add…
grzegrzk Dec 14, 2016
a28e013
Reverted Main.Designer.cs to last valid state
grzegrzk Dec 15, 2016
17926c5
Added by hand menu item to Main.Designer.cs
grzegrzk Dec 15, 2016
3aba61f
Got rid of compilation warnings
grzegrzk Dec 15, 2016
b8ac281
Got rid of compilation warnings in tests
grzegrzk Dec 15, 2016
bb29084
Added missing event handler to "Compatible KSP versions" menu item
grzegrzk Dec 16, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cmdline/Action/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
try
{
// Check if upgrades are available, and show appropriately.
CkanModule latest = registry.LatestAvailable(mod.Key, ksp.Version());
CkanModule latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria());

log.InfoFormat("Latest {0} is {1}", mod.Key, latest);

Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<CkanModule> PerformSearch(CKAN.KSP ksp, string term)
{
var registry = RegistryManager.Instance(ksp).registry;
return registry
.Available(ksp.Version())
.Available(ksp.VersionCriteria())
.Where((module) =>
{
// Extract the description. This is an optional field and may be null.
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int RunCommand(CKAN.KSP ksp, 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
CkanModule moduleToShow = registry
.Available(ksp.Version())
.Available(ksp.VersionCriteria())
.SingleOrDefault(
mod => mod.name == options.Modname
|| mod.identifier == options.Modname
Expand Down
4 changes: 2 additions & 2 deletions Cmdline/Action/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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.Version());
available_prior = registry.Available(ksp.VersionCriteria());
}

// If no repository is selected, select all.
Expand Down Expand Up @@ -56,7 +56,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.Version()));
PrintChanges(available_prior, registry.Available(ksp.VersionCriteria()));
}

return Exit.OK;
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Upgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public int RunCommand(CKAN.KSP ksp, object raw_options)
try
{
// Check if upgrades are available
var latest = registry.LatestAvailable(mod.Key, ksp.Version());
var latest = registry.LatestAvailable(mod.Key, ksp.VersionCriteria());

// This may be an unindexed mod. If so,
// skip rather than crash. See KSP-CKAN/CKAN#841.
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private static int Version(IUser user)

private static int Available(CKAN.KSP current_instance, IUser user)
{
List<CkanModule> available = RegistryManager.Instance(current_instance).registry.Available(current_instance.Version());
List<CkanModule> available = RegistryManager.Instance(current_instance).registry.Available(current_instance.VersionCriteria());

user.RaiseMessage("Mods available for KSP {0}", current_instance.Version());
user.RaiseMessage("");
Expand Down
3 changes: 3 additions & 0 deletions Core/CKAN-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CompatibleKspVersionsDto.cs" />
<Compile Include="Exporters\BbCodeExporter.cs" />
<Compile Include="Exporters\DelimeterSeperatedValueExporter.cs" />
<Compile Include="Exporters\Exporter.cs" />
Expand Down Expand Up @@ -110,6 +111,8 @@
<Compile Include="Types\GameComparator\GrasGameComparator.cs" />
<Compile Include="Types\GameComparator\StrictGameComparator.cs" />
<Compile Include="Types\GameComparator\YoyoGameComparator.cs" />
<Compile Include="Versioning\KspVersionCriteria.cs" />
<Compile Include="Types\GameComparator\BaseGameComparator.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions Core/CompatibleKspVersionsDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CKAN
{
//
//This is DTO object to be serialized/deserialized as JSON
//
class CompatibleKspVersionsDto
{
public CompatibleKspVersionsDto()
{
this.CompatibleKspVersions = new List<String>();
}

public String VersionOfKspWhenWritten { get; set; }

public List<String> CompatibleKspVersions { get; set; }
}
}
3 changes: 3 additions & 0 deletions Core/GameVersionProviders/IKspBuildMap.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using CKAN.Versioning;
using System.Collections.Generic;

namespace CKAN.GameVersionProviders
{
public interface IKspBuildMap
{
KspVersion this[string buildId] { get; }

List<KspVersion> KnownVersions { get; }

void Refresh();
}
}
14 changes: 14 additions & 0 deletions Core/GameVersionProviders/KspBuildMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ public sealed class KspBuildMap : IKspBuildMap
}
}

public List<KspVersion> KnownVersions
{
get
{
EnsureBuildMap();
List<KspVersion> knownVersions = new List<KspVersion>();
foreach (var version in _jBuilds.Builds)
{
knownVersions.Add(KspVersion.Parse(version.Value));
}
return knownVersions;
}
}

public KspBuildMap(IWin32Registry registry)
{
_registry = registry;
Expand Down
54 changes: 54 additions & 0 deletions Core/KSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CKAN.GameVersionProviders;
using CKAN.Versioning;
using log4net;
using Newtonsoft.Json;

[assembly: InternalsVisibleTo("CKAN.Tests")]

Expand All @@ -29,6 +30,9 @@ public class KSP : IDisposable

private readonly string gameDir;
private KspVersion version;
private List<KspVersion> _compatibleVersions = new List<KspVersion>();
public KspVersion VersionOfKspWhenCompatibleVersionsWereStored { get; private set; }
public bool CompatibleVersionsAreFromDifferentKsp { get { return _compatibleVersions.Count > 0 && VersionOfKspWhenCompatibleVersionsWereStored != Version(); } }

public NetFileCache Cache { get; private set; }

Expand Down Expand Up @@ -92,9 +96,53 @@ private void Init()
foreach (DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
}

LoadCompatibleVersions();

log.DebugFormat("Initialised {0}", CkanDir());
}

public void SetCompatibleVersions(List<KspVersion> compatibleVersions)
{
this._compatibleVersions = compatibleVersions.Distinct().ToList();
SaveCompatibleVersions();
}

private void SaveCompatibleVersions()
{
CompatibleKspVersionsDto compatibleKspVersionsDto = new CompatibleKspVersionsDto();

compatibleKspVersionsDto.VersionOfKspWhenWritten = Version().ToString();
compatibleKspVersionsDto.CompatibleKspVersions = _compatibleVersions.Select(v => v.ToString()).ToList();

String json = JsonConvert.SerializeObject(compatibleKspVersionsDto);
File.WriteAllText(CompatibleKspVersionsFile(), json);

this.VersionOfKspWhenCompatibleVersionsWereStored = Version();
}

private void LoadCompatibleVersions()
{
String path = CompatibleKspVersionsFile();
if (File.Exists(path))
{
string json = File.ReadAllText(path);
CompatibleKspVersionsDto compatibleKspVersionsDto = JsonConvert.DeserializeObject<CompatibleKspVersionsDto>(json);

_compatibleVersions = compatibleKspVersionsDto.CompatibleKspVersions.Select(v => KspVersion.Parse(v)).ToList();
this.VersionOfKspWhenCompatibleVersionsWereStored = KspVersion.Parse(compatibleKspVersionsDto.VersionOfKspWhenWritten);
}
}

private string CompatibleKspVersionsFile()
{
return Path.Combine(CkanDir(), "compatible_ksp_versions.json");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a sidenote we should really come up with a centralized mechanism to store both global and local settings data that is not the registry. But that's a story for another day.

}

public List<KspVersion> GetCompatibleVersions()
{
return new List<KspVersion>(this._compatibleVersions);
}

#endregion

#region Destructors and Disposal
Expand Down Expand Up @@ -334,6 +382,12 @@ public KspVersion Version()
return version = DetectVersion(GameDir());
}


public KspVersionCriteria VersionCriteria ()
{
return new KspVersionCriteria(version, _compatibleVersions);
}

#endregion

#region CKAN/GameData Directory Maintenance
Expand Down
6 changes: 3 additions & 3 deletions Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static string CachedOrDownload(string identifier, Version version, Uri ur
IDownloader downloader = null
)
{
var resolver = new RelationshipResolver(modules, options, registry_manager.registry, ksp.Version());
var resolver = new RelationshipResolver(modules, options, registry_manager.registry, ksp.VersionCriteria());
var modsToInstall = resolver.ModList().ToList();
InstallList(modsToInstall, options, downloader);
}
Expand All @@ -173,7 +173,7 @@ public static string CachedOrDownload(string identifier, Version version, Uri ur
IDownloader downloader = null
)
{
var resolver = new RelationshipResolver(modules, options, registry_manager.registry, ksp.Version());
var resolver = new RelationshipResolver(modules, options, registry_manager.registry, ksp.VersionCriteria());
var modsToInstall = resolver.ModList().ToList();
List<CkanModule> downloads = new List<CkanModule> ();

Expand Down Expand Up @@ -993,7 +993,7 @@ public void Upgrade(IEnumerable<string> identifiers, NetAsyncModulesDownloader n
options.with_recommends = false;
options.with_suggests = false;

var resolver = new RelationshipResolver(identifiers.ToList(), options, registry_manager.registry, ksp.Version());
var resolver = new RelationshipResolver(identifiers.ToList(), options, registry_manager.registry, ksp.VersionCriteria());
Upgrade(resolver.ModList(), netAsyncDownloader, enforceConsistency);
}

Expand Down
4 changes: 2 additions & 2 deletions Core/Net/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static int UpdateAllRepositories(RegistryManager registry_manager, KSP ks
ShowUserInconsistencies(registry_manager.registry, user);

// Return how many we got!
return registry_manager.registry.Available(ksp.Version()).Count;
return registry_manager.registry.Available(ksp.VersionCriteria()).Count;
}

public static int Update(RegistryManager registry_manager, KSP ksp, IUser user, Boolean clear = true, string repo = null)
Expand Down Expand Up @@ -414,7 +414,7 @@ private static int Update(RegistryManager registry_manager, KSP ksp, IUser user,
ShowUserInconsistencies(registry_manager.registry, user);

// Return how many we got!
return registry_manager.registry.Available(ksp.Version()).Count;
return registry_manager.registry.Available(ksp.VersionCriteria()).Count;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Core/Registry/AvailableModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void Remove(Version version)
/// <param name="ksp_version">If not null only consider mods which match this ksp version.</param>
/// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param>
/// <returns></returns>
public CkanModule Latest(KspVersion ksp_version = null, RelationshipDescriptor relationship=null)
public CkanModule Latest(KspVersionCriteria ksp_version = null, RelationshipDescriptor relationship=null)
{
var available_versions = new List<Version>(module_version.Keys);
CkanModule module;
Expand Down
10 changes: 5 additions & 5 deletions Core/Registry/IRegistryQuerier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IRegistryQuerier
/// the specified version of KSP.
/// </summary>
// TODO: This name is misleading. It's more a LatestAvailable's'
List<CkanModule> Available(KspVersion ksp_version);
List<CkanModule> Available(KspVersionCriteria ksp_version);

/// <summary>
/// Returns the latest available version of a module that
Expand All @@ -25,7 +25,7 @@ public interface IRegistryQuerier
/// If no ksp_version is provided, the latest module for *any* KSP is returned.
/// <exception cref="ModuleNotFoundKraken">Throws if asked for a non-existent module.</exception>
/// </summary>
CkanModule LatestAvailable(string identifier, KspVersion ksp_version, RelationshipDescriptor relationship_descriptor = null);
CkanModule LatestAvailable(string identifier, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null);

/// <summary>
/// Returns the latest available version of a module that satisifes the specified version and
Expand All @@ -34,7 +34,7 @@ public interface IRegistryQuerier
/// Returns an empty list if nothing is available for our system, which includes if no such module exists.
/// If no KSP version is provided, the latest module for *any* KSP version is given.
/// </summary>
List<CkanModule> LatestAvailableWithProvides(string identifier, KspVersion ksp_version, RelationshipDescriptor relationship_descriptor = null);
List<CkanModule> LatestAvailableWithProvides(string identifier, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null);

/// <summary>
/// Checks the sanity of the registry, to ensure that all dependencies are met,
Expand Down Expand Up @@ -65,7 +65,7 @@ public interface IRegistryQuerier
/// Returns a simple array of all incompatible modules for
/// the specified version of KSP.
/// </summary>
List<CkanModule> Incompatible(KspVersion ksp_version);
List<CkanModule> Incompatible(KspVersionCriteria ksp_version);

/// <summary>
/// Returns a dictionary of all modules installed, along with their
Expand Down Expand Up @@ -128,7 +128,7 @@ public static bool IsAutodetected(this IRegistryQuerier querier, string identifi
/// Is the mod installed and does it have a newer version compatible with version
/// We can't update AD mods
/// </summary>
public static bool HasUpdate(this IRegistryQuerier querier, string identifier, KspVersion version)
public static bool HasUpdate(this IRegistryQuerier querier, string identifier, KspVersionCriteria version)
{
CkanModule newest_version;
try
Expand Down
10 changes: 5 additions & 5 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void RemoveAvailable(CkanModule module)
/// <summary>
/// <see cref="IRegistryQuerier.Available"/>
/// </summary>
public List<CkanModule> Available(KspVersion ksp_version)
public List<CkanModule> Available(KspVersionCriteria ksp_version)
{
var candidates = new List<string>(available_modules.Keys);
var compatible = new List<CkanModule>();
Expand Down Expand Up @@ -461,7 +461,7 @@ public List<CkanModule> Available(KspVersion ksp_version)
/// <summary>
/// <see cref="IRegistryQuerier.Incompatible"/>
/// </summary>
public List<CkanModule> Incompatible(KspVersion ksp_version)
public List<CkanModule> Incompatible(KspVersionCriteria ksp_version)
{
var candidates = new List<string>(available_modules.Keys);
var incompatible = new List<CkanModule>();
Expand Down Expand Up @@ -492,7 +492,7 @@ public List<CkanModule> Incompatible(KspVersion ksp_version)
// be calling LatestAvailableWithProvides()
public CkanModule LatestAvailable(
string module,
KspVersion ksp_version,
KspVersionCriteria ksp_version,
RelationshipDescriptor relationship_descriptor =null)
{
log.DebugFormat("Finding latest available for {0}", module);
Expand All @@ -514,7 +514,7 @@ public List<CkanModule> Incompatible(KspVersion ksp_version)
/// <summary>
/// <see cref = "IRegistryQuerier.LatestAvailableWithProvides" />
/// </summary>
public List<CkanModule> LatestAvailableWithProvides(string module, KspVersion ksp_version, RelationshipDescriptor relationship_descriptor = null)
public List<CkanModule> LatestAvailableWithProvides(string module, KspVersionCriteria ksp_version, RelationshipDescriptor relationship_descriptor = null)
{
// This public interface calculates a cache of modules which
// are compatible with the current version of KSP, and then
Expand All @@ -530,7 +530,7 @@ public List<CkanModule> LatestAvailableWithProvides(string module, KspVersion ks
/// the `available_for_current_version` list has been correctly
/// calculated. Not for direct public consumption. ;)
/// </summary>
private List<CkanModule> LatestAvailableWithProvides(string module, KspVersion ksp_version,
private List<CkanModule> LatestAvailableWithProvides(string module, KspVersionCriteria ksp_version,
IEnumerable<CkanModule> available_for_current_version, RelationshipDescriptor relationship_descriptor=null)
{
log.DebugFormat("Finding latest available with provides for {0}", module);
Expand Down