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

Default install stanza multi-game support, catch missing install_to #3441

Merged
merged 2 commits into from
Sep 17, 2021
Merged
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
2 changes: 1 addition & 1 deletion Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public static List<InstallableFile> FindInstallableFiles(CkanModule module, ZipF
else
{
files.AddRange(ModuleInstallDescriptor
.DefaultInstallStanza(module.identifier)
.DefaultInstallStanza(ksp.game, module.identifier)
.FindInstallableFiles(zipfile, ksp));
}
}
Expand Down
5 changes: 3 additions & 2 deletions Core/Types/CkanModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using log4net;
using Newtonsoft.Json;
using CKAN.Versioning;
using CKAN.Games;

namespace CKAN
{
Expand Down Expand Up @@ -683,7 +684,7 @@ public override string ToString()
return string.Format("{0} {1}", identifier, version);
}

public string DescribeInstallStanzas()
public string DescribeInstallStanzas(IGame game)
{
List<string> descriptions = new List<string>();
if (install != null)
Expand All @@ -695,7 +696,7 @@ public string DescribeInstallStanzas()
}
else
{
descriptions.Add(ModuleInstallDescriptor.DefaultInstallStanza(identifier).DescribeMatch());
descriptions.Add(ModuleInstallDescriptor.DefaultInstallStanza(game, identifier).DescribeMatch());
}
return string.Join(", ", descriptions);
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Types/ModuleInstallDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ public override int GetHashCode()
/// <returns>
/// { "find": "ident", "install_to": "GameData" }
/// </returns>
public static ModuleInstallDescriptor DefaultInstallStanza(string ident)
public static ModuleInstallDescriptor DefaultInstallStanza(IGame game, string ident)
{
return new ModuleInstallDescriptor()
{
find = ident,
install_to = "GameData",
install_to = game.PrimaryModDirectoryRelative,
};
}

Expand Down
4 changes: 4 additions & 0 deletions Netkan/Validators/InstallValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public void Validate(Metadata metadata)
foreach (JObject stanza in json["install"])
{
string install_to = (string)stanza["install_to"];
if (string.IsNullOrEmpty(install_to))
{
throw new Kraken("install stanza missing `install_to`");
}
if (metadata.SpecVersion < v1p2 && install_to.StartsWith("GameData/"))
{
throw new Kraken("spec_version v1.2+ required for GameData with path");
Expand Down
3 changes: 2 additions & 1 deletion Netkan/Validators/InstallsFilesValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CKAN.NetKAN.Model;
using CKAN.NetKAN.Services;
using CKAN.Extensions;
using CKAN.Games;

namespace CKAN.NetKAN.Validators
{
Expand All @@ -29,7 +30,7 @@ public void Validate(Metadata metadata)
{
throw new Kraken(string.Format(
"Module contains no files matching: {0}",
mod.DescribeInstallStanzas()
mod.DescribeInstallStanzas(new KerbalSpaceProgram())
));
}

Expand Down
11 changes: 5 additions & 6 deletions Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,14 @@ In addition, any number of optional directives *may* be provided:

If no install sections are provided, a CKAN client *must* find the
top-most directory in the archive that matches the module identifier,
and install that with a target of `GameData`.

A typical install directive only has `file` and `install_to` sections:
and install that with a target of `GameData`. In other words, the
default install section is:

```json
"install" : [
"install": [
{
"file" : "GameData/ExampleMod",
"install_to" : "GameData"
"find": "<identifier>",
"install_to": "GameData"
}
]
```
Expand Down
7 changes: 4 additions & 3 deletions Tests/Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NUnit.Framework;

using CKAN;
using CKAN.Games;
using Tests.Core.Configuration;
using Tests.Data;

Expand Down Expand Up @@ -73,13 +74,13 @@ public void GenerateDefaultInstall()
string filename = TestData.DogeCoinFlagZip();
using (var zipfile = new ZipFile(filename))
{
ModuleInstallDescriptor stanza = ModuleInstallDescriptor.DefaultInstallStanza("DogeCoinFlag");
ModuleInstallDescriptor stanza = ModuleInstallDescriptor.DefaultInstallStanza(new KerbalSpaceProgram(), "DogeCoinFlag");

Assert.AreEqual("GameData", stanza.install_to);
Assert.AreEqual("DogeCoinFlag", stanza.find);

// Same again, but screwing up the case (we see this *all the time*)
ModuleInstallDescriptor stanza2 = ModuleInstallDescriptor.DefaultInstallStanza("DogecoinFlag");
ModuleInstallDescriptor stanza2 = ModuleInstallDescriptor.DefaultInstallStanza(new KerbalSpaceProgram(), "DogecoinFlag");

Assert.AreEqual("GameData", stanza2.install_to);
Assert.AreEqual("DogecoinFlag", stanza2.find);
Expand Down Expand Up @@ -362,7 +363,7 @@ public void CorruptZip_242()
using (var zipfile = new ZipFile(corrupt_dogezip))
{
// GenerateDefault Install
ModuleInstallDescriptor.DefaultInstallStanza("DogeCoinFlag");
ModuleInstallDescriptor.DefaultInstallStanza(new KerbalSpaceProgram(), "DogeCoinFlag");

// FindInstallableFiles
CkanModule dogemod = TestData.DogeCoinFlag_101_module();
Expand Down