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

Catch nested GameData folders in Netkan #2948

Merged
merged 1 commit into from
Jan 6, 2020
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 Netkan/ConsoleUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConsoleUser : IUser
/// <summary>
/// Initializes a new instance of the <see cref="T:CKAN.CmdLine.ConsoleUser"/> class.
/// </summary>
/// <param name="headless">If set to <c>true</c>, supress interactive dialogs like Yes/No-Dialog or SelectionDialog.</param>
/// <param name="headless">If set to <c>true</c>, suppress interactive dialogs like Yes/No-Dialog or SelectionDialog.</param>
public ConsoleUser (bool headless)
{
Headless = headless;
Expand Down
1 change: 1 addition & 0 deletions Netkan/Services/IModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ internal interface IModuleService

IEnumerable<InstallableFile> GetConfigFiles(CkanModule module, ZipFile zip);

IEnumerable<string> FileDestinations(CkanModule module, string filePath);
}
}
7 changes: 7 additions & 0 deletions Netkan/Services/ModuleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public IEnumerable<InstallableFile> GetConfigFiles(CkanModule module, ZipFile zi
.Where(instF => cfgRegex.IsMatch(instF.source.Name));
}

public IEnumerable<string> FileDestinations(CkanModule module, string filePath)
{
return ModuleInstaller
.FindInstallableFiles(module, filePath, new KSP("/", "dummy", null, false))
.Select(f => f.destination);
}

/// <summary>
/// Return a parsed JObject from a stream.
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion Netkan/Validators/InstallsFilesValidator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using CKAN.NetKAN.Model;
using CKAN.NetKAN.Services;

Expand All @@ -20,14 +21,23 @@ public void Validate(Metadata metadata)
var file = _http.DownloadPackage(metadata.Download, metadata.Identifier, metadata.RemoteTimestamp);

// Make sure this would actually generate an install.

if (!_moduleService.HasInstallableFiles(mod, file))
{
throw new Kraken(string.Format(
"Module contains no files matching: {0}",
mod.DescribeInstallStanzas()
));
}

// Make sure no paths include GameData other than at the start
var gamedatas = _moduleService.FileDestinations(mod, file)
.Where(p => p.StartsWith("GameData") && p.LastIndexOf("/GameData/") > 0)
.ToList();
if (gamedatas.Any())
{
var badPaths = string.Join("\r\n", gamedatas);
throw new Kraken($"GameData directory found within GameData:\r\n{badPaths}");
}
}
}
}
4 changes: 2 additions & 2 deletions Netkan/Validators/LicensesValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Validate(Metadata metadata)
{
if (licenses == null || licenses.Count < 1)
{
throw new Kraken("License should match spec. Set `x_netkan_license_ok` to supress");
throw new Kraken("License should match spec. Set `x_netkan_license_ok` to suppress");
}
else foreach (var lic in licenses)
{
Expand All @@ -44,7 +44,7 @@ public void Validate(Metadata metadata)
}
catch
{
throw new Kraken($"License {lic} should match spec. Set `x_netkan_license_ok` to supress");
throw new Kraken($"License {lic} should match spec. Set `x_netkan_license_ok` to suppress");
}
}
}
Expand Down