Normalize ReadRangeFromSource use

This commit is contained in:
Matt Nadareski
2025-09-20 09:49:42 -04:00
parent b2279e97b2
commit d3e7abfaa3
15 changed files with 21 additions and 21 deletions

View File

@@ -82,7 +82,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the data block
var data = ReadRangeFromSource(offset, compressedSize);
if (data == null)
if (data.Length == 0)
return false;
// If we have uncompressed data

View File

@@ -44,7 +44,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the data
var lump = Lumps[index];
var data = ReadRangeFromSource(lump.Offset, lump.Length);
if (data == null)
if (data.Length == 0)
return false;
// Create the filename

View File

@@ -201,7 +201,7 @@ namespace SabreTools.Serialization.Wrappers
// Try to read the sector data
var sectorData = ReadRangeFromSource(sectorDataOffset, (int)SectorSize);
if (sectorData == null)
if (sectorData.Length == 0)
return null;
// Add the sector data to the output

View File

@@ -95,7 +95,7 @@ namespace SabreTools.Serialization.Wrappers
{
int readSize = (int)Math.Min(BlockSize, fileSize);
var data = ReadRangeFromSource((int)dataBlockOffsets[i], readSize);
if (data == null)
if (data.Length == 0)
return false;
fs.Write(data, 0, data.Length);

View File

@@ -73,7 +73,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the compressed data directly
var compressedData = ReadRangeFromSource((int)fileOffset, (int)fileSize);
if (compressedData == null)
if (compressedData.Length == 0)
return false;
// If the compressed and uncompressed sizes match

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Serialization.Wrappers
// Read in the data as an array
byte[]? contents = ReadRangeFromSource(DataOffset, (int)compressedSize);
if (contents == null)
if (contents.Length == 0)
return false;
// Get the decompressor

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Serialization.Wrappers
// Read in the data as an array
byte[]? contents = ReadRangeFromSource(12, (int)compressedSize);
if (contents == null)
if (contents.Length == 0)
return false;
// Get the decompressor

View File

@@ -26,7 +26,7 @@ namespace SabreTools.Serialization.Wrappers
// Read in the data as an array
byte[]? contents = ReadRangeFromSource(14, (int)compressedSize);
if (contents == null)
if (contents.Length == 0)
return false;
// Get the decompressor

View File

@@ -43,7 +43,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the item data
var directoryItem = DirectoryItems[index];
var data = ReadRangeFromSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength);
if (data == null)
if (data.Length == 0)
return false;
// If we have an invalid output directory

View File

@@ -69,7 +69,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the data block
var data = ReadRangeFromSource(offset, size);
if (data == null)
if (data.Length == 0)
return false;
// Write the data -- TODO: Compressed data?

View File

@@ -1173,7 +1173,7 @@ namespace SabreTools.Serialization.Wrappers
try
{
entryData = ReadRangeFromSource((int)address, (int)size);
if (entryData == null || entryData.Length < 4)
if (entryData.Length < 4)
continue;
}
catch (EndOfStreamException)
@@ -1871,10 +1871,10 @@ namespace SabreTools.Serialization.Wrappers
return _sectionData[index];
// Populate the raw section data based on the source
byte[]? sectionData = ReadRangeFromSource((int)address, (int)size);
var sectionData = ReadRangeFromSource((int)address, (int)size);
// Cache and return the section data, even if null
_sectionData[index] = sectionData ?? [];
// Cache and return the section data
_sectionData[index] = sectionData;
return sectionData;
}
@@ -2032,10 +2032,10 @@ namespace SabreTools.Serialization.Wrappers
return null;
// Populate the raw table data based on the source
byte[]? tableData = ReadRangeFromSource((int)address, (int)size);
var tableData = ReadRangeFromSource((int)address, (int)size);
// Cache and return the table data, even if null
_tableData[index] = tableData ?? [];
// Cache and return the table data
_tableData[index] = tableData;
return tableData;
}

View File

@@ -83,7 +83,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the compressed data directly
var compressedData = ReadRangeFromSource((int)fileOffset, (int)fileSize);
if (compressedData == null)
if (compressedData.Length == 0)
return false;
// If the compressed and uncompressed sizes match

View File

@@ -44,7 +44,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the data
var lump = Lumps[index];
var data = ReadRangeFromSource(lump.Offset, lump.Length);
if (data == null)
if (data.Length == 0)
return false;
// If we have an invalid output directory

View File

@@ -43,7 +43,7 @@ namespace SabreTools.Serialization.Wrappers
// Read the data -- TODO: Handle uncompressed lumps (see BSP.ExtractTexture)
var lump = DirEntries[index];
var data = ReadRangeFromSource((int)lump.Offset, (int)lump.Length);
if (data == null)
if (data.Length == 0)
return false;
// If we have an invalid output directory

View File

@@ -52,7 +52,7 @@ namespace SabreTools.Serialization.Wrappers
// Load the item data
var data = ReadRangeFromSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength);
if (data == null)
if (data.Length == 0)
return false;
// If we have an invalid output directory