hactoolnet: Tweak NCA processing

- Ignore the relevant --section#(dir) option if the equivalent --exefs(dir) or --romfs(dir) option is set
- Display a warning instead of completely erroring when trying to extract a section that doesn't exist
- Fix an off-by-one error that resulted in section 3 not being extracted. In practice this hasn't mattered much up to this point because no official NCAs contain a section 3.
This commit is contained in:
Alex Barney 2022-04-08 18:16:39 -07:00
parent 98b6d7a346
commit c62de98f63

View file

@ -39,15 +39,35 @@ internal static class ProcessNca
baseNca = new Nca(ctx.KeySet, baseFile);
}
for (int i = 0; i < 3; i++)
for (int i = 0; i < 4; i++)
{
if (ctx.Options.SectionOut[i] != null)
if ((ctx.Options.SectionOut[i] is not null || ctx.Options.SectionOutDir[i] is not null) && !nca.SectionExists(i))
{
ctx.Logger.LogMessage($"WARNING: NCA section {i} does not exist.");
continue;
}
if (ctx.Options.SectionOut[i] is not null)
{
// Prioritize the --exefs and --romfs options over --section# ones
if (Nca.GetSectionTypeFromIndex(i, nca.Header.ContentType) == NcaSectionType.Code && ctx.Options.ExefsOut is not null)
continue;
if (Nca.GetSectionTypeFromIndex(i, nca.Header.ContentType) == NcaSectionType.Data && ctx.Options.RomfsOut is not null)
continue;
OpenStorage(i).WriteAllBytes(ctx.Options.SectionOut[i], ctx.Logger);
}
if (ctx.Options.SectionOutDir[i] != null)
if (ctx.Options.SectionOutDir[i] is not null)
{
// Prioritize the --exefsdir and --romfsdir options over --section#dir ones
if (Nca.GetSectionTypeFromIndex(i, nca.Header.ContentType) == NcaSectionType.Code && ctx.Options.ExefsOutDir is not null)
continue;
if (Nca.GetSectionTypeFromIndex(i, nca.Header.ContentType) == NcaSectionType.Data && ctx.Options.RomfsOutDir is not null)
continue;
FileSystemClient fs = ctx.Horizon.Fs;
string mountName = $"section{i}";