diff --git a/BinaryObjectScanner.Test/FileType/BFPKTests.cs b/BinaryObjectScanner.Test/FileType/BFPKTests.cs
index bf86df65..b4a87679 100644
--- a/BinaryObjectScanner.Test/FileType/BFPKTests.cs
+++ b/BinaryObjectScanner.Test/FileType/BFPKTests.cs
@@ -40,29 +40,5 @@ namespace BinaryObjectScanner.Test.FileType
bool actual = extractable.Extract(stream, file, outDir, includeDebug: false);
Assert.False(actual);
}
-
- [Fact]
- public void ExtractAll_EmptyModel_False()
- {
- var model = new SabreTools.Models.BFPK.Archive();
- var data = new MemoryStream();
- var item = new SabreTools.Serialization.Wrappers.BFPK(model, data);
- string outputDirectory = string.Empty;
-
- bool actual = BFPK.ExtractAll(item, outputDirectory);
- Assert.False(actual);
- }
-
- [Fact]
- public void ExtractFile_EmptyModel_False()
- {
- var model = new SabreTools.Models.BFPK.Archive();
- var data = new MemoryStream();
- var item = new SabreTools.Serialization.Wrappers.BFPK(model, data);
- string outputDirectory = string.Empty;
-
- bool actual = BFPK.ExtractFile(item, 0, outputDirectory);
- Assert.False(actual);
- }
}
}
diff --git a/BinaryObjectScanner/FileType/BFPK.cs b/BinaryObjectScanner/FileType/BFPK.cs
index 3d3fec55..1f084fda 100644
--- a/BinaryObjectScanner/FileType/BFPK.cs
+++ b/BinaryObjectScanner/FileType/BFPK.cs
@@ -1,6 +1,5 @@
using System.IO;
using BinaryObjectScanner.Interfaces;
-using SabreTools.Compression.Deflate;
namespace BinaryObjectScanner.FileType
{
@@ -29,96 +28,9 @@ namespace BinaryObjectScanner.FileType
// Extract all files
Directory.CreateDirectory(outDir);
- ExtractAll(bfpk, outDir);
+ bfpk.ExtractAll(outDir);
return true;
}
-
- ///
- /// Extract all files from the BFPK to an output directory
- ///
- /// Output directory to write to
- /// True if all files extracted, false otherwise
- public static bool ExtractAll(SabreTools.Serialization.Wrappers.BFPK item, string outputDirectory)
- {
- // If we have no files
- if (item.Model.Files == null || item.Model.Files.Length == 0)
- return false;
-
- // Loop through and extract all files to the output
- bool allExtracted = true;
- for (int i = 0; i < item.Model.Files.Length; i++)
- {
- allExtracted &= ExtractFile(item, i, outputDirectory);
- }
-
- return allExtracted;
- }
-
- ///
- /// Extract a file from the BFPK to an output directory by index
- ///
- /// File index to extract
- /// Output directory to write to
- /// True if the file extracted, false otherwise
- public static bool ExtractFile(SabreTools.Serialization.Wrappers.BFPK item, int index, string outputDirectory)
- {
- // If we have no files
- if (item.Model.Files == null || item.Model.Files.Length == 0)
- return false;
-
- // If we have an invalid index
- if (index < 0 || index >= item.Model.Files.Length)
- return false;
-
- // Get the file information
- var file = item.Model.Files[index];
- if (file == null)
- return false;
-
- // Get the read index and length
- int offset = file.Offset + 4;
- int compressedSize = file.CompressedSize;
-
- // Some files can lack the length prefix
- if (compressedSize > item.GetEndOfFile())
- {
- offset -= 4;
- compressedSize = file.UncompressedSize;
- }
-
- try
- {
- // Ensure the output directory exists
- Directory.CreateDirectory(outputDirectory);
-
- // Create the output path
- string filePath = Path.Combine(outputDirectory, file.Name ?? $"file{index}");
- using FileStream fs = File.OpenWrite(filePath);
-
- // Read the data block
- var data = item.ReadFromDataSource(offset, compressedSize);
- if (data == null)
- return false;
-
- // If we have uncompressed data
- if (compressedSize == file.UncompressedSize)
- {
- fs.Write(data, 0, compressedSize);
- }
- else
- {
- MemoryStream ms = new MemoryStream(data);
- ZlibStream zs = new ZlibStream(ms, CompressionMode.Decompress);
- zs.CopyTo(fs);
- }
-
- return true;
- }
- catch
- {
- return false;
- }
- }
}
}