Skip to content

Commit 0617bf3

Browse files
committed
Process all folders in all MS-CAB files in a set (fixes #43)
1 parent 425d13a commit 0617bf3

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

SabreTools.Serialization/Wrappers/MicrosoftCabinet.Extraction.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,16 @@ public bool Extract(string outputDirectory, bool includeDebug)
150150
// Display warning in debug runs
151151
if (includeDebug) Console.WriteLine("WARNING: LZX and Quantum compression schemes are not supported so some files may be skipped!");
152152

153+
// Do not ignore previous links by default
154+
bool ignorePrev = false;
155+
153156
// Open the full set if possible
154157
var cabinet = this;
155158
if (Filename != null)
159+
{
156160
cabinet = OpenSet(Filename);
161+
ignorePrev = true;
162+
}
157163

158164
// If the archive is invalid
159165
if (cabinet?.Folders == null || cabinet.Folders.Length == 0)
@@ -163,10 +169,19 @@ public bool Extract(string outputDirectory, bool includeDebug)
163169
{
164170
// Loop through the folders
165171
bool allExtracted = true;
166-
for (int f = 0; f < cabinet.Folders.Length; f++)
172+
while (true)
167173
{
168-
var folder = cabinet.Folders[f];
169-
allExtracted &= cabinet.ExtractFolder(Filename, outputDirectory, folder, f, includeDebug);
174+
// Loop through the current folders
175+
for (int f = 0; f < cabinet.Folders.Length; f++)
176+
{
177+
var folder = cabinet.Folders[f];
178+
allExtracted &= cabinet.ExtractFolder(Filename, outputDirectory, folder, f, ignorePrev, includeDebug);
179+
}
180+
181+
// Move to the next cabinet, if possible
182+
cabinet = cabinet.Next;
183+
if (cabinet?.Folders == null || cabinet.Folders.Length == 0)
184+
break;
170185
}
171186

172187
return allExtracted;
@@ -185,12 +200,14 @@ public bool Extract(string outputDirectory, bool includeDebug)
185200
/// <param name="outputDirectory">Path to the output directory</param>
186201
/// <param name="folder">Folder containing the blocks to decompress</param>
187202
/// <param name="folderIndex">Index of the folder in the cabinet</param>
203+
/// <param name="ignorePrev">True to ignore previous links, false otherwise</param>
188204
/// <param name="includeDebug">True to include debug data, false otherwise</param>
189205
/// <returns>True if all files extracted, false otherwise</returns>
190206
private bool ExtractFolder(string? filename,
191207
string outputDirectory,
192208
CFFOLDER? folder,
193209
int folderIndex,
210+
bool ignorePrev,
194211
bool includeDebug)
195212
{
196213
// Decompress the blocks, if possible
@@ -200,7 +217,7 @@ private bool ExtractFolder(string? filename,
200217

201218
// Loop through the files
202219
bool allExtracted = true;
203-
var files = GetFiles(folderIndex);
220+
var files = GetFiles(folderIndex, ignorePrev);
204221
for (int i = 0; i < files.Length; i++)
205222
{
206223
var file = files[i];

SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ private static CompressionType GetCompressionType(CFFOLDER folder)
365365
/// Get all files for the current folder index
366366
/// </summary>
367367
/// <param name="folderIndex">Index of the folder in the cabinet</param>
368+
/// <param name="ignorePrev">True to ignore previous links, false otherwise</param>
368369
/// <returns>Array of all files for the folder</returns>
369-
private CFFILE[] GetFiles(int folderIndex)
370+
private CFFILE[] GetFiles(int folderIndex, bool ignorePrev = false)
370371
{
371372
// Ignore invalid archives
372373
if (Files == null)
@@ -378,6 +379,15 @@ private CFFILE[] GetFiles(int folderIndex)
378379
if (string.IsNullOrEmpty(f.Name))
379380
return false;
380381

382+
// Ignore links to previous cabinets, if required
383+
if (ignorePrev)
384+
{
385+
if (f.FolderIndex == FolderIndex.CONTINUED_FROM_PREV)
386+
return false;
387+
else if (f.FolderIndex == FolderIndex.CONTINUED_PREV_AND_NEXT)
388+
return false;
389+
}
390+
381391
int fileFolder = GetFolderIndex(f);
382392
return fileFolder == folderIndex;
383393
});

0 commit comments

Comments
 (0)