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

Don't stage if compatible with current game version #3031

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion Netkan/Transformers/StagingTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using log4net;
using Autofac;
using CKAN.Extensions;
using CKAN.GameVersionProviders;
using CKAN.Versioning;
using CKAN.NetKAN.Model;

namespace CKAN.NetKAN.Transformers
{
internal sealed class StagingTransformer : ITransformer
{
public StagingTransformer()
{
IKspBuildMap builds = ServiceLocator.Container.Resolve<IKspBuildMap>();
builds.Refresh(BuildMapSource.Embedded);
currentRelease = builds.KnownVersions.Max().ToVersionRange();
}

public string Name { get { return "staging"; } }

public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
Expand All @@ -17,7 +27,8 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
var matchingKeys = kspVersionKeys
.Where(vk => json.ContainsKey(vk)
&& !string.IsNullOrEmpty((string)json[vk])
&& (string)json[vk] != "any")
&& (string)json[vk] != "any"
&& !CompatibleWithCurrent((string)json[vk]))
.Memoize();
if (matchingKeys.Any())
{
Expand All @@ -30,6 +41,13 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)
yield return metadata;
}

private bool CompatibleWithCurrent(string version)
{
return currentRelease.IntersectWith(KspVersion.Parse(version).ToVersionRange()) != null;
}

private static KspVersionRange currentRelease;

private static readonly string[] kspVersionKeys = new string[]
{
"ksp_version",
Expand Down