diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs
index ebc2dcee..c059b46d 100644
--- a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs
+++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs
@@ -778,6 +778,47 @@ namespace BurnOutSharp.Wrappers
#region Files
+ ///
+ /// Extract a single file to an output directory
+ ///
+ /// File index to check
+ /// Output directory to use for writing
+ /// Byte array representing the data, null on error
+ public bool ExtractFile(int fileIndex, string outputDirectory)
+ {
+ // If we have an invalid file index
+ if (fileIndex < 0 || fileIndex >= Files.Length)
+ return false;
+
+ // If we have an invalid output directory
+ if (string.IsNullOrWhiteSpace(outputDirectory))
+ return false;
+
+ // Ensure the directory exists
+ Directory.CreateDirectory(outputDirectory);
+
+ // Get the file header
+ var file = Files[fileIndex];
+ if (file == null || file.FileSize == 0)
+ return false;
+
+ // Create the output filename
+ string fileName = Path.Combine(outputDirectory, file.Name);
+
+ // Get the file data, if possible
+ byte[] fileData = GetFileData(fileIndex);
+ if (fileData == null)
+ return false;
+
+ // Write the file data
+ using (FileStream fs = File.OpenWrite(fileName))
+ {
+ fs.Write(fileData, 0, fileData.Length);
+ }
+
+ return true;
+ }
+
///
/// Get the DateTime for a particular file index
///
@@ -818,6 +859,33 @@ namespace BurnOutSharp.Wrappers
}
}
+ ///
+ /// Get the uncompressed data associated with a file
+ ///
+ /// File index to check
+ /// Byte array representing the data, null on error
+ public byte[] GetFileData(int fileIndex)
+ {
+ // If we have an invalid file index
+ if (fileIndex < 0 || fileIndex >= Files.Length)
+ return null;
+
+ // Get the file header
+ var file = Files[fileIndex];
+ if (file == null || file.FileSize == 0)
+ return null;
+
+ // Get the parent folder data
+ byte[] folderData = GetUncompressedData((int)file.FolderIndex);
+ if (folderData == null)
+ return null;
+
+ // Get the segment that represents this file
+ byte[] fileData = new byte[file.FileSize];
+ Array.Copy(folderData, file.FolderStartOffset, fileData, 0, file.FileSize);
+ return fileData;
+ }
+
#endregion
#region Printing