Skip to content

Commit

Permalink
Fix NRE and test data
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jun 19, 2019
1 parent cae3130 commit 77ecd95
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
59 changes: 31 additions & 28 deletions Netkan/Validators/InstallValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,39 @@ internal sealed class InstallValidator : IValidator
public void Validate(Metadata metadata)
{
var json = metadata.Json();
foreach (JObject stanza in json["install"])
if (json.ContainsKey("install"))
{
string install_to = (string)stanza["install_to"];
if (metadata.SpecVersion < v1p2 && install_to.StartsWith("GameData/"))
foreach (JObject stanza in json["install"])
{
throw new Kraken("spec_version v1.2+ required for GameData with path");
}
if (metadata.SpecVersion < v1p12 && install_to.StartsWith("Ships/"))
{
throw new Kraken("spec_version v1.12+ required to install to Ships/ with path");
}
if (metadata.SpecVersion < v1p16 && install_to.StartsWith("Ships/@thumbs"))
{
throw new Kraken("spec_version v1.16+ required to install to Ships/@thumbs with path");
}
if (metadata.SpecVersion < v1p4 && stanza.ContainsKey("find"))
{
throw new Kraken("spec_version v1.4+ required for install with 'find'");
}
if (metadata.SpecVersion < v1p10 && stanza.ContainsKey("find_regexp"))
{
throw new Kraken("spec_version v1.10+ required for install with 'find_regexp'");
}
if (metadata.SpecVersion < v1p16 && stanza.ContainsKey("find_matches_files"))
{
throw new Kraken("spec_version v1.16+ required for 'find_matches_files'");
}
if (metadata.SpecVersion < v1p18 && stanza.ContainsKey("as"))
{
throw new Kraken("spec_version v1.18+ required for 'as'");
string install_to = (string)stanza["install_to"];
if (metadata.SpecVersion < v1p2 && install_to.StartsWith("GameData/"))
{
throw new Kraken("spec_version v1.2+ required for GameData with path");
}
if (metadata.SpecVersion < v1p12 && install_to.StartsWith("Ships/"))
{
throw new Kraken("spec_version v1.12+ required to install to Ships/ with path");
}
if (metadata.SpecVersion < v1p16 && install_to.StartsWith("Ships/@thumbs"))
{
throw new Kraken("spec_version v1.16+ required to install to Ships/@thumbs with path");
}
if (metadata.SpecVersion < v1p4 && stanza.ContainsKey("find"))
{
throw new Kraken("spec_version v1.4+ required for install with 'find'");
}
if (metadata.SpecVersion < v1p10 && stanza.ContainsKey("find_regexp"))
{
throw new Kraken("spec_version v1.10+ required for install with 'find_regexp'");
}
if (metadata.SpecVersion < v1p16 && stanza.ContainsKey("find_matches_files"))
{
throw new Kraken("spec_version v1.16+ required for 'find_matches_files'");
}
if (metadata.SpecVersion < v1p18 && stanza.ContainsKey("as"))
{
throw new Kraken("spec_version v1.18+ required for 'as'");
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/NetKAN/Validators/CkanValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public void SetUp()
{
ValidCkan["spec_version"] = 1;
ValidCkan["identifier"] = "AwesomeMod";
ValidCkan["name"] = "Awesome Mod";
ValidCkan["abstract"] = "A great mod";
ValidCkan["license"] = "GPL-3.0";
ValidCkan["version"] = "1.0.0";
ValidCkan["download"] = "https://www.awesome-mod.example/AwesomeMod.zip";
}
Expand Down

0 comments on commit 77ecd95

Please sign in to comment.