Skip to content

Commit

Permalink
Merge #2948 Catch nested GameData folders in Netkan
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Jan 6, 2020
2 parents 3ab4bd7 + 9d3374f commit b4175fc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
- [Netkan] Coerce GitHub URLs into the authenticated API in Netkan (#2946 by: HebaruSan; reviewed: DasSkelett)
- [Netkan] Request fewer GitHub releases and cache string URLs in Netkan (#2950 by: HebaruSan)
- [GUI] Create ~/.local/share/applications/ if it doesn't exist on Linux (#1848 by: DinCahill; reviewed: ayan4ml, politas, dannydi12)
- [Netkan] Catch nested GameData folders in Netkan (#2948 by: HebaruSan; reviewed: techman83)

## v1.26.6 (Leonov)

Expand Down
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

0 comments on commit b4175fc

Please sign in to comment.