Fix issues from manual testing

This commit is contained in:
Matt Nadareski
2025-09-26 22:52:09 -04:00
parent 7395d9842c
commit ae6bf0f2da
2 changed files with 19 additions and 12 deletions

View File

@@ -62,11 +62,8 @@ namespace SabreTools.Serialization.Readers
/// <returns>Filled Footer on success, null on error</returns>
public static Footer ParseFooter(Stream data)
{
// Seek to the end of the end of the data
data.Seek(0, SeekOrigin.End);
// Seek backward to the theoretical starts
data.Seek(-24, SeekOrigin.Current);
// Seek from the end (24 bytes has to use -23)
data.Seek(-23, SeekOrigin.End);
var obj = new Footer();

View File

@@ -50,6 +50,9 @@ namespace SabreTools.Serialization.Wrappers
{
try
{
// Ensure the stream is starting at the beginning
_dataSource.Seek(0, SeekOrigin.Begin);
// Try to deserialize the source data
var deserializer = new Readers.AdvancedInstaller();
var sfx = deserializer.Deserialize(_dataSource);
@@ -541,6 +544,9 @@ namespace SabreTools.Serialization.Wrappers
{
try
{
// Ensure the stream is starting at the beginning
_dataSource.Seek(0, SeekOrigin.Begin);
// Try to deserialize the source data
var deserializer = new Readers.SpoonInstaller();
var sfx = deserializer.Deserialize(_dataSource);
@@ -554,19 +560,23 @@ namespace SabreTools.Serialization.Wrappers
// Get the offset and compressed size
long offset = entry.FileOffset;
int size = (int)entry.CompressedSize;
int compressed = (int)entry.CompressedSize;
int extracted = (int)entry.UncompressedSize;
// Try to read the file data
byte[] data = ReadRangeFromSource(offset, size);
if (data.Length == 0)
byte[] bz2Data = ReadRangeFromSource(offset, compressed);
if (bz2Data.Length == 0)
continue;
// Try opening the stream
using var ms = new MemoryStream(data);
using var bz2File = new BZip2InputStream(ms, true);
using var ms = new MemoryStream(bz2Data);
using var bz2File = new BZip2InputStream(ms, false);
// Try to read the decompressed data
byte[] data = bz2File.ReadBytes(extracted);
// Ensure directory separators are consistent
string filename = entry.Filename ?? $"FILE_{i}";
string filename = entry.Filename?.TrimEnd('\0') ?? $"FILE_{i}";
if (Path.DirectorySeparatorChar == '\\')
filename = filename.Replace('/', '\\');
else if (Path.DirectorySeparatorChar == '/')
@@ -580,7 +590,7 @@ namespace SabreTools.Serialization.Wrappers
// Write the output file
var fs = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
bz2File.CopyTo(fs);
fs.Write(data, 0, data.Length);
fs.Flush();
}