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

Introducing IGameComparatorExemptions in order to waive checking version compatibility for select modules. (Take 2) #1965

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions Core/CKAN-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<Compile Include="Types\CKANVersion.cs" />
<Compile Include="Registry\IRegistryQuerier.cs" />
<Compile Include="Types\ExportFileType.cs" />
<Compile Include="Types\GameComparator\GameComparatorExemptions.cs" />
<Compile Include="Types\GameComparator\IGameComparatorExemptions.cs" />
<Compile Include="User.cs" />
<Compile Include="Types\Version.cs" />
<Compile Include="Meta.cs" />
Expand Down Expand Up @@ -119,7 +121,4 @@
<None Include="packages.config" />
<EmbeddedResource Include="builds.json" />
</ItemGroup>
<ItemGroup />
<ItemGroup />
<ItemGroup />
</Project>
</Project>
61 changes: 61 additions & 0 deletions Core/Types/GameComparator/GameComparatorExemptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CKAN
{
public class GameComparatorExemptions : IGameComparatorExemptions
{
private struct CkanModuleProxy
{
public string Name { get; set; }
public string Identifier { get; set; }
}

private IEnumerable<CkanModuleProxy> _exemptions;


public GameComparatorExemptions(IEnumerable<CkanModule> exemptions = null)
{
if(exemptions != null)
{
_exemptions = exemptions.Select(ex => new CkanModuleProxy
{
Name = ex.name,
Identifier = String.IsNullOrEmpty(ex.identifier)
? ex.name
: ex.identifier
});
}
else
{
initDefaultGameExemptions();
}
}

public GameComparatorExemptions()
{
initDefaultGameExemptions();
}

private void initDefaultGameExemptions()
{
Func<string, CkanModuleProxy> exMod =
name => new CkanModuleProxy { Name = name };
_exemptions = new List<CkanModuleProxy>
{
new CkanModuleProxy {Name= "CustomBarnKit" },
new CkanModuleProxy {Name= "ContractConfigurator" },
new CkanModuleProxy {Name= "ModuleManager" },
new CkanModuleProxy {Name= "Strategia" },
};
}

public bool IsExempt(CkanModule module)
{
_exemptions = _exemptions ?? new List<CkanModuleProxy>();
return _exemptions.Any(e => e.Name.ToLower() == module.name.ToLower()
|| e.Name.ToLower() == module.identifier.ToLower());
}
}
}
6 changes: 4 additions & 2 deletions Core/Types/GameComparator/GrasGameComparator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ public class GrasGameComparator : BaseGameComparator
{
static readonly StrictGameComparator strict = new StrictGameComparator ();
static readonly KspVersion v103 = KspVersion.Parse ("1.0.3");
private IGameComparatorExemptions _gameComparatorExemptions = new GameComparatorExemptions();

public override bool Compatible (KspVersionCriteria gameVersionCriteria, CkanModule module)
{
// If it's strictly compatible, then it's compatible.
if (strict.Compatible (gameVersionCriteria, module))
return true;

bool isExempt = _gameComparatorExemptions.IsExempt(module);
// If we're in strict mode, and it's not strictly compatible, then it's
// not compatible.
if (module.ksp_version_strict)
return false;
return (false || isExempt);

return base.Compatible (gameVersionCriteria, module);
return (base.Compatible(gameVersionCriteria, module) || isExempt);
}

public override bool SingleVersionsCompatible (KspVersion gameVersion, CkanModule module){
Expand Down
11 changes: 11 additions & 0 deletions Core/Types/GameComparator/IGameComparatorExemptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace CKAN
{
/// <summary>
/// Allows certain modules to pass as compatible even though
/// they might not be.
/// </summary>
public interface IGameComparatorExemptions
{
bool IsExempt(CkanModule module);
}
}