Process all folders in all MS-CAB files in a set (fixes #43)

This commit is contained in:
Matt Nadareski
2025-11-15 09:00:28 -05:00
parent 425d13a2ac
commit 0617bf3170
2 changed files with 32 additions and 5 deletions

View File

@@ -150,10 +150,16 @@ namespace SabreTools.Serialization.Wrappers
// Display warning in debug runs
if (includeDebug) Console.WriteLine("WARNING: LZX and Quantum compression schemes are not supported so some files may be skipped!");
// Do not ignore previous links by default
bool ignorePrev = false;
// Open the full set if possible
var cabinet = this;
if (Filename != null)
{
cabinet = OpenSet(Filename);
ignorePrev = true;
}
// If the archive is invalid
if (cabinet?.Folders == null || cabinet.Folders.Length == 0)
@@ -163,10 +169,19 @@ namespace SabreTools.Serialization.Wrappers
{
// Loop through the folders
bool allExtracted = true;
for (int f = 0; f < cabinet.Folders.Length; f++)
while (true)
{
var folder = cabinet.Folders[f];
allExtracted &= cabinet.ExtractFolder(Filename, outputDirectory, folder, f, includeDebug);
// Loop through the current folders
for (int f = 0; f < cabinet.Folders.Length; f++)
{
var folder = cabinet.Folders[f];
allExtracted &= cabinet.ExtractFolder(Filename, outputDirectory, folder, f, ignorePrev, includeDebug);
}
// Move to the next cabinet, if possible
cabinet = cabinet.Next;
if (cabinet?.Folders == null || cabinet.Folders.Length == 0)
break;
}
return allExtracted;
@@ -185,12 +200,14 @@ namespace SabreTools.Serialization.Wrappers
/// <param name="outputDirectory">Path to the output directory</param>
/// <param name="folder">Folder containing the blocks to decompress</param>
/// <param name="folderIndex">Index of the folder in the cabinet</param>
/// <param name="ignorePrev">True to ignore previous links, false otherwise</param>
/// <param name="includeDebug">True to include debug data, false otherwise</param>
/// <returns>True if all files extracted, false otherwise</returns>
private bool ExtractFolder(string? filename,
string outputDirectory,
CFFOLDER? folder,
int folderIndex,
bool ignorePrev,
bool includeDebug)
{
// Decompress the blocks, if possible
@@ -200,7 +217,7 @@ namespace SabreTools.Serialization.Wrappers
// Loop through the files
bool allExtracted = true;
var files = GetFiles(folderIndex);
var files = GetFiles(folderIndex, ignorePrev);
for (int i = 0; i < files.Length; i++)
{
var file = files[i];

View File

@@ -365,8 +365,9 @@ namespace SabreTools.Serialization.Wrappers
/// Get all files for the current folder index
/// </summary>
/// <param name="folderIndex">Index of the folder in the cabinet</param>
/// <param name="ignorePrev">True to ignore previous links, false otherwise</param>
/// <returns>Array of all files for the folder</returns>
private CFFILE[] GetFiles(int folderIndex)
private CFFILE[] GetFiles(int folderIndex, bool ignorePrev = false)
{
// Ignore invalid archives
if (Files == null)
@@ -378,6 +379,15 @@ namespace SabreTools.Serialization.Wrappers
if (string.IsNullOrEmpty(f.Name))
return false;
// Ignore links to previous cabinets, if required
if (ignorePrev)
{
if (f.FolderIndex == FolderIndex.CONTINUED_FROM_PREV)
return false;
else if (f.FolderIndex == FolderIndex.CONTINUED_PREV_AND_NEXT)
return false;
}
int fileFolder = GetFolderIndex(f);
return fileFolder == folderIndex;
});