From 0dc9823d2bec3f34a046ddd15e5ea32225d4feae Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 29 Jul 2025 08:04:02 -0400 Subject: [PATCH] Fix assumption about MS-CAB sets --- .../Wrappers/MicrosoftCabinet.cs | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs index b6a200ef..49e42d22 100644 --- a/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs +++ b/SabreTools.Serialization/Wrappers/MicrosoftCabinet.cs @@ -118,7 +118,7 @@ namespace SabreTools.Serialization.Wrappers /// Path to the output directory /// True to include debug data, false otherwise /// Indicates if all files were able to be extracted - /// Will extract all items found in the set with forward-only reading + /// Will extract all items found in the set public static bool ExtractSet(string filename, string outDir, bool includeDebug) { // Get a wrapper for the set @@ -131,7 +131,7 @@ namespace SabreTools.Serialization.Wrappers // Loop through the cabinets do { - current.ExtractCabinet(filename, outDir, forwardOnly: true, includeDebug); + current.ExtractCabinet(filename, outDir, includeDebug); current = current.Next; } while (current?.Header != null); @@ -154,7 +154,7 @@ namespace SabreTools.Serialization.Wrappers /// Indicates if all files were able to be extracted /// Will read spanned folders but won't attempt to extract unrelated folders public bool ExtractAll(string? filename, string outDir, bool includeDebug) - => ExtractCabinet(filename, outDir, forwardOnly: false, includeDebug); + => ExtractCabinet(filename, outDir, includeDebug); /// /// Extract a cabinet file to an output directory, if possible @@ -162,9 +162,8 @@ namespace SabreTools.Serialization.Wrappers /// Filename for one cabinet in the set, if available /// Path to the output directory /// True to include debug data, false otherwise - /// Indicates if decompression should be done forward-only /// Indicates if all files were able to be extracted - private bool ExtractCabinet(string? filename, string outDir, bool forwardOnly, bool includeDebug) + private bool ExtractCabinet(string? filename, string outDir, bool includeDebug) { // If the archive is invalid if (Folders == null || Folders.Length == 0) @@ -176,7 +175,7 @@ namespace SabreTools.Serialization.Wrappers for (int f = 0; f < Folders.Length; f++) { var folder = Folders[f]; - ExtractFolder(filename, outDir, folder, f, forwardOnly, includeDebug); + ExtractFolder(filename, outDir, folder, f, includeDebug); } return true; @@ -195,17 +194,15 @@ namespace SabreTools.Serialization.Wrappers /// Path to the output directory /// Folder containing the blocks to decompress /// Index of the folder in the cabinet - /// Indicates if decompression should be done forward-only /// True to include debug data, false otherwise private void ExtractFolder(string? filename, string outDir, CFFOLDER? folder, int folderIndex, - bool forwardOnly, bool includeDebug) { // Decompress the blocks, if possible - using var blockStream = DecompressBlocks(filename, folder, folderIndex, forwardOnly); + using var blockStream = DecompressBlocks(filename, folder, folderIndex); if (blockStream == null || blockStream.Length == 0) return; @@ -465,14 +462,11 @@ namespace SabreTools.Serialization.Wrappers /// Filename for one cabinet in the set, if available /// Folder containing the blocks to decompress /// Index of the folder in the cabinet - /// Indicates if decompression should be done forward-only /// Stream representing the decompressed data on success, null otherwise - public Stream? DecompressBlocks(string? filename, CFFOLDER? folder, int folderIndex, bool forwardOnly) + public Stream? DecompressBlocks(string? filename, CFFOLDER? folder, int folderIndex) { // Ensure data blocks - var dataBlocks = forwardOnly - ? GetDataBlocksForward(filename, folder, folderIndex) - : GetDataBlocks(filename, folder, folderIndex); + var dataBlocks = GetDataBlocks(filename, folder, folderIndex); if (dataBlocks == null || dataBlocks.Length == 0) return null; @@ -609,16 +603,6 @@ namespace SabreTools.Serialization.Wrappers return [.. prevBlocks, .. folder.DataBlocks, .. nextBlocks]; } - /// - /// Get the set of data blocks for a folder using forward reading only - /// - /// Filename for one cabinet in the set, if available - /// Folder containing the blocks to decompress - /// Index of the folder in the cabinet - /// Array of data blocks on success, null otherwise - private CFDATA[]? GetDataBlocksForward(string? filename, CFFOLDER? folder, int folderIndex) - => GetDataBlocks(filename, folder, folderIndex, skipPrev: true, skipNext: false); - /// /// Get all files for the current folder index ///