hactoolnet: Set archive bit when missing from concat files

This commit is contained in:
Alex Barney 2019-05-06 19:04:17 -05:00
parent 67bf8b19ce
commit da5a3449dd

View file

@ -21,11 +21,15 @@ namespace hactoolnet
{ {
ctx.Logger.LogMessage("Treating path as SD card storage"); ctx.Logger.LogMessage("Treating path as SD card storage");
switchFs = SwitchFs.OpenSdCard(ctx.Keyset, baseFs); switchFs = SwitchFs.OpenSdCard(ctx.Keyset, baseFs);
CheckForNcaFolders(ctx, switchFs);
} }
else if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Contents", "registered"))) else if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Contents", "registered")))
{ {
ctx.Logger.LogMessage("Treating path as NAND storage"); ctx.Logger.LogMessage("Treating path as NAND storage");
switchFs = SwitchFs.OpenNandPartition(ctx.Keyset, baseFs); switchFs = SwitchFs.OpenNandPartition(ctx.Keyset, baseFs);
CheckForNcaFolders(ctx, switchFs);
} }
else else
{ {
@ -298,5 +302,26 @@ namespace hactoolnet
save.Value.Extract(outDir, ctx.Logger); save.Value.Extract(outDir, ctx.Logger);
} }
} }
private static void CheckForNcaFolders(Context ctx, SwitchFs switchFs)
{
IFileSystem fs = switchFs.ContentFs;
DirectoryEntry[] ncaDirs = fs.EnumerateEntries("*.nca", SearchOptions.RecurseSubdirectories)
.Where(x => x.Type == DirectoryEntryType.Directory)
.Where(x => fs.FileExists($"{x.FullPath}/00"))
.ToArray();
if (ncaDirs.Length > 0)
{
ctx.Logger.LogMessage("Warning: NCA folders without the archive flag were found. Fixing...");
}
foreach (DirectoryEntry file in ncaDirs)
{
fs.SetConcatenationFileAttribute(file.FullPath);
ctx.Logger.LogMessage($"{file.FullPath}");
}
}
} }
} }