mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-27 09:12:02 +00:00
Simplify some directives
This commit is contained in:
@@ -120,11 +120,7 @@ namespace BinaryObjectScanner.FileType
|
||||
using (FileStream fs = File.OpenWrite(filePath))
|
||||
{
|
||||
// Read the data block
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource(offset, compressedSize);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource(offset, compressedSize);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource(offset, compressedSize);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -100,11 +100,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Read the data
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
@@ -128,11 +124,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
@@ -196,11 +188,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Read the data
|
||||
#if NET48
|
||||
byte[] data = CreateTextureData(texture);
|
||||
#else
|
||||
byte[]? data = CreateTextureData(texture);
|
||||
#endif
|
||||
var data = CreateTextureData(texture);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
@@ -215,11 +203,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -57,11 +57,7 @@ namespace BinaryObjectScanner.FileType
|
||||
if (strData == null)
|
||||
return;
|
||||
|
||||
#if NET48
|
||||
string decoded = DecodeStreamName(e.Name).TrimEnd('\0');
|
||||
#else
|
||||
string? decoded = DecodeStreamName(e.Name)?.TrimEnd('\0');
|
||||
#endif
|
||||
var decoded = DecodeStreamName(e.Name)?.TrimEnd('\0');
|
||||
if (decoded == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -243,11 +243,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return null;
|
||||
|
||||
// Read the file contents
|
||||
#if NET48
|
||||
byte[] fileContent = null;
|
||||
#else
|
||||
byte[]? fileContent = null;
|
||||
#endif
|
||||
byte[] fileContent = new byte[0];
|
||||
try
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
@@ -270,11 +266,7 @@ namespace BinaryObjectScanner.FileType
|
||||
Parallel.ForEach(ContentCheckClasses, checkClass =>
|
||||
{
|
||||
// Get the protection for the class, if possible
|
||||
#if NET48
|
||||
string protection = checkClass.CheckContents(file, fileContent, includeDebug);
|
||||
#else
|
||||
string? protection = checkClass.CheckContents(file, fileContent, includeDebug);
|
||||
#endif
|
||||
var protection = checkClass.CheckContents(file, fileContent, includeDebug);
|
||||
if (string.IsNullOrWhiteSpace(protection))
|
||||
return;
|
||||
|
||||
@@ -308,11 +300,7 @@ namespace BinaryObjectScanner.FileType
|
||||
Parallel.ForEach(LinearExecutableCheckClasses, checkClass =>
|
||||
{
|
||||
// Get the protection for the class, if possible
|
||||
#if NET48
|
||||
string protection = checkClass.CheckLinearExecutable(file, lex, includeDebug);
|
||||
#else
|
||||
string? protection = checkClass.CheckLinearExecutable(file, lex, includeDebug);
|
||||
#endif
|
||||
var protection = checkClass.CheckLinearExecutable(file, lex, includeDebug);
|
||||
if (string.IsNullOrWhiteSpace(protection))
|
||||
return;
|
||||
|
||||
@@ -346,11 +334,7 @@ namespace BinaryObjectScanner.FileType
|
||||
Parallel.ForEach(MSDOSExecutableCheckClasses, checkClass =>
|
||||
{
|
||||
// Get the protection for the class, if possible
|
||||
#if NET48
|
||||
string protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug);
|
||||
#else
|
||||
string? protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug);
|
||||
#endif
|
||||
var protection = checkClass.CheckMSDOSExecutable(file, mz, includeDebug);
|
||||
if (string.IsNullOrWhiteSpace(protection))
|
||||
return;
|
||||
|
||||
@@ -384,11 +368,7 @@ namespace BinaryObjectScanner.FileType
|
||||
Parallel.ForEach(NewExecutableCheckClasses, checkClass =>
|
||||
{
|
||||
// Get the protection for the class, if possible
|
||||
#if NET48
|
||||
string protection = checkClass.CheckNewExecutable(file, nex, includeDebug);
|
||||
#else
|
||||
string? protection = checkClass.CheckNewExecutable(file, nex, includeDebug);
|
||||
#endif
|
||||
var protection = checkClass.CheckNewExecutable(file, nex, includeDebug);
|
||||
if (string.IsNullOrWhiteSpace(protection))
|
||||
return;
|
||||
|
||||
@@ -422,11 +402,7 @@ namespace BinaryObjectScanner.FileType
|
||||
Parallel.ForEach(PortableExecutableCheckClasses, checkClass =>
|
||||
{
|
||||
// Get the protection for the class, if possible
|
||||
#if NET48
|
||||
string protection = checkClass.CheckPortableExecutable(file, pex, includeDebug);
|
||||
#else
|
||||
string? protection = checkClass.CheckPortableExecutable(file, pex, includeDebug);
|
||||
#endif
|
||||
var protection = checkClass.CheckPortableExecutable(file, pex, includeDebug);
|
||||
if (string.IsNullOrWhiteSpace(protection))
|
||||
return;
|
||||
|
||||
|
||||
@@ -121,11 +121,7 @@ namespace BinaryObjectScanner.FileType
|
||||
}
|
||||
|
||||
// Create the filename
|
||||
#if NET48
|
||||
string filename = file.Path;
|
||||
#else
|
||||
string? filename = file.Path;
|
||||
#endif
|
||||
var filename = file.Path;
|
||||
|
||||
// If we have an invalid output directory
|
||||
if (string.IsNullOrWhiteSpace(outputDirectory))
|
||||
@@ -135,11 +131,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename ?? $"file{index}");
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
@@ -154,11 +146,7 @@ namespace BinaryObjectScanner.FileType
|
||||
for (int i = 0; i < dataBlockOffsets.Count; i++)
|
||||
{
|
||||
int readSize = (int)Math.Min(item.Model.DataBlockHeader?.BlockSize ?? 0, fileSize);
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)dataBlockOffsets[i], readSize);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -46,11 +46,7 @@ namespace BinaryObjectScanner.FileType
|
||||
try
|
||||
{
|
||||
string tempFile = Path.Combine(tempPath, cfile.FullPath);
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(tempFile);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(tempFile);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(tempFile);
|
||||
if (directoryName != null && !Directory.Exists(directoryName))
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -35,11 +35,7 @@ namespace BinaryObjectScanner.FileType
|
||||
#endif
|
||||
{
|
||||
// Get the name of the first cabinet file or header
|
||||
#if NET48
|
||||
string directory = Path.GetDirectoryName(file);
|
||||
#else
|
||||
string? directory = Path.GetDirectoryName(file);
|
||||
#endif
|
||||
var directory = Path.GetDirectoryName(file);
|
||||
string noExtension = Path.GetFileNameWithoutExtension(file);
|
||||
|
||||
bool shouldScanCabinet;
|
||||
|
||||
@@ -107,11 +107,7 @@ namespace BinaryObjectScanner.FileType
|
||||
if (dataBlock == null)
|
||||
continue;
|
||||
|
||||
#if NET48
|
||||
byte[] decompressed = new byte[dataBlock.UncompressedSize];
|
||||
#else
|
||||
byte[]? decompressed = new byte[dataBlock.UncompressedSize];
|
||||
#endif
|
||||
var decompressed = new byte[dataBlock.UncompressedSize];
|
||||
switch (folder.CompressionType & SabreTools.Models.MicrosoftCabinet.CompressionType.MASK_TYPE)
|
||||
{
|
||||
case SabreTools.Models.MicrosoftCabinet.CompressionType.TYPE_NONE:
|
||||
@@ -192,11 +188,7 @@ namespace BinaryObjectScanner.FileType
|
||||
string fileName = Path.Combine(outputDirectory, file.Name ?? $"file{index}");
|
||||
|
||||
// Get the file data, if possible
|
||||
#if NET48
|
||||
byte[] fileData = GetFileData(item, index);
|
||||
#else
|
||||
byte[]? fileData = GetFileData(item, index);
|
||||
#endif
|
||||
var fileData = GetFileData(item, index);
|
||||
if (fileData == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -98,20 +98,12 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Read the item data
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
// Create the filename
|
||||
#if NET48
|
||||
string filename = directoryItem.ItemName;
|
||||
#else
|
||||
string? filename = directoryItem.ItemName;
|
||||
#endif
|
||||
var filename = directoryItem.ItemName;
|
||||
|
||||
// If we have an invalid output directory
|
||||
if (string.IsNullOrWhiteSpace(outputDirectory))
|
||||
@@ -121,11 +113,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename ?? $"file{index}");
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -111,11 +111,7 @@ namespace BinaryObjectScanner.FileType
|
||||
using (FileStream fs = File.OpenWrite(filePath))
|
||||
{
|
||||
// Read the data block
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource(offset, size);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource(offset, size);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource(offset, size);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -51,11 +51,7 @@ namespace BinaryObjectScanner.FileType
|
||||
continue;
|
||||
|
||||
string tempFile = Path.Combine(tempPath, entry.Key);
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(tempFile);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(tempFile);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(tempFile);
|
||||
if (directoryName != null && !Directory.Exists(directoryName))
|
||||
Directory.CreateDirectory(directoryName);
|
||||
entry.WriteToFile(tempFile);
|
||||
|
||||
@@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType
|
||||
// Read the entire compressed data
|
||||
int compressedDataOffset = (int)item.Model.CompressedDataOffset;
|
||||
int compressedDataLength = item.GetEndOfFile() - compressedDataOffset;
|
||||
#if NET48
|
||||
byte[] compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength);
|
||||
#else
|
||||
byte[]? compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength);
|
||||
#endif
|
||||
var compressedData = item.ReadFromDataSource(compressedDataOffset, compressedDataLength);
|
||||
|
||||
// TODO: Figure out decompression
|
||||
// - Single-file archives seem to work
|
||||
|
||||
@@ -136,11 +136,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Create the filename
|
||||
#if NET48
|
||||
string filename;
|
||||
#else
|
||||
string? filename;
|
||||
#endif
|
||||
var filename = string.Empty;
|
||||
switch (item.Model.Header?.MajorVersion)
|
||||
{
|
||||
case 4:
|
||||
@@ -158,11 +154,7 @@ namespace BinaryObjectScanner.FileType
|
||||
#endif
|
||||
|
||||
// Get the parent directory
|
||||
#if NET48
|
||||
object folder;
|
||||
#else
|
||||
object? folder;
|
||||
#endif
|
||||
var folder = default(object);
|
||||
switch (item.Model.Header?.MajorVersion)
|
||||
{
|
||||
#if NET48
|
||||
@@ -240,11 +232,7 @@ namespace BinaryObjectScanner.FileType
|
||||
}
|
||||
|
||||
// Read the compressed data directly
|
||||
#if NET48
|
||||
byte[] compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize);
|
||||
#else
|
||||
byte[]? compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize);
|
||||
#endif
|
||||
var compressedData = item.ReadFromDataSource((int)fileOffset, (int)fileSize);
|
||||
if (compressedData == null)
|
||||
return false;
|
||||
|
||||
@@ -271,11 +259,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -40,11 +40,7 @@ namespace BinaryObjectScanner.FileType
|
||||
try
|
||||
{
|
||||
// Load the current file content
|
||||
#if NET48
|
||||
string fileContent = null;
|
||||
#else
|
||||
string? fileContent = null;
|
||||
#endif
|
||||
var fileContent = string.Empty;
|
||||
using (var sr = new StreamReader(stream, Encoding.Default, true, 1024 * 1024, true))
|
||||
{
|
||||
fileContent = sr.ReadToEnd();
|
||||
|
||||
@@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Read the data
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
@@ -126,11 +122,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -100,11 +100,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// If we have an item with no archive
|
||||
#if NET48
|
||||
byte[] data;
|
||||
#else
|
||||
byte[]? data;
|
||||
#endif
|
||||
var data = new byte[0];
|
||||
if (directoryItem.DirectoryEntry.ArchiveIndex == SabreTools.Models.VPK.Constants.HL_VPK_NO_ARCHIVE)
|
||||
{
|
||||
if (directoryItem.PreloadData == null)
|
||||
@@ -132,11 +128,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Try to open the archive
|
||||
#if NET48
|
||||
Stream archiveStream = null;
|
||||
#else
|
||||
Stream? archiveStream = null;
|
||||
#endif
|
||||
var archiveStream = default(Stream);
|
||||
try
|
||||
{
|
||||
// Open the archive
|
||||
@@ -179,11 +171,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -98,11 +98,7 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Read the data -- TODO: Handle uncompressed lumps (see BSP.ExtractTexture)
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)lump.Offset, (int)lump.Length);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
@@ -117,11 +113,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename);
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
@@ -108,20 +108,12 @@ namespace BinaryObjectScanner.FileType
|
||||
return false;
|
||||
|
||||
// Load the item data
|
||||
#if NET48
|
||||
byte[] data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength);
|
||||
#else
|
||||
byte[]? data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength);
|
||||
#endif
|
||||
var data = item.ReadFromDataSource((int)directoryEntry.EntryOffset, (int)directoryEntry.EntryLength);
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
// Create the filename
|
||||
#if NET48
|
||||
string filename = directoryItem.Name;
|
||||
#else
|
||||
string? filename = directoryItem.Name;
|
||||
#endif
|
||||
var filename = directoryItem.Name;
|
||||
|
||||
// If we have an invalid output directory
|
||||
if (string.IsNullOrWhiteSpace(outputDirectory))
|
||||
@@ -131,11 +123,7 @@ namespace BinaryObjectScanner.FileType
|
||||
filename = Path.Combine(outputDirectory, filename ?? $"file{index}");
|
||||
|
||||
// Ensure the output directory is created
|
||||
#if NET48
|
||||
string directoryName = Path.GetDirectoryName(filename);
|
||||
#else
|
||||
string? directoryName = Path.GetDirectoryName(filename);
|
||||
#endif
|
||||
var directoryName = Path.GetDirectoryName(filename);
|
||||
if (directoryName != null)
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user