From da5a3449dd760b263c3937f2a69d75c4d4939e51 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 6 May 2019 19:04:17 -0500 Subject: [PATCH] hactoolnet: Set archive bit when missing from concat files --- src/hactoolnet/ProcessSwitchFs.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/hactoolnet/ProcessSwitchFs.cs b/src/hactoolnet/ProcessSwitchFs.cs index da329c32..a7b57cf8 100644 --- a/src/hactoolnet/ProcessSwitchFs.cs +++ b/src/hactoolnet/ProcessSwitchFs.cs @@ -21,11 +21,15 @@ namespace hactoolnet { ctx.Logger.LogMessage("Treating path as SD card storage"); switchFs = SwitchFs.OpenSdCard(ctx.Keyset, baseFs); + + CheckForNcaFolders(ctx, switchFs); } else if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Contents", "registered"))) { ctx.Logger.LogMessage("Treating path as NAND storage"); switchFs = SwitchFs.OpenNandPartition(ctx.Keyset, baseFs); + + CheckForNcaFolders(ctx, switchFs); } else { @@ -298,5 +302,26 @@ namespace hactoolnet 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}"); + } + } } }