diff --git a/BinaryObjectScanner/BinaryObjectScanner.csproj b/BinaryObjectScanner/BinaryObjectScanner.csproj
index 45ba8573..64fb2027 100644
--- a/BinaryObjectScanner/BinaryObjectScanner.csproj
+++ b/BinaryObjectScanner/BinaryObjectScanner.csproj
@@ -54,6 +54,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -65,18 +80,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs
index cc857bed..ef0b2727 100644
--- a/BinaryObjectScanner/FileType/Executable.cs
+++ b/BinaryObjectScanner/FileType/Executable.cs
@@ -40,9 +40,7 @@ namespace BinaryObjectScanner.FileType
{
get
{
- if (contentCheckClasses == null)
- contentCheckClasses = InitCheckClasses();
-
+ contentCheckClasses ??= InitCheckClasses();
return contentCheckClasses ?? Enumerable.Empty();
}
}
@@ -54,9 +52,7 @@ namespace BinaryObjectScanner.FileType
{
get
{
- if (linearExecutableCheckClasses == null)
- linearExecutableCheckClasses = InitCheckClasses();
-
+ linearExecutableCheckClasses ??= InitCheckClasses();
return linearExecutableCheckClasses ?? Enumerable.Empty();
}
}
@@ -68,9 +64,7 @@ namespace BinaryObjectScanner.FileType
{
get
{
- if (msdosExecutableCheckClasses == null)
- msdosExecutableCheckClasses = InitCheckClasses();
-
+ msdosExecutableCheckClasses ??= InitCheckClasses();
return msdosExecutableCheckClasses ?? Enumerable.Empty();
}
}
@@ -82,9 +76,7 @@ namespace BinaryObjectScanner.FileType
{
get
{
- if (newExecutableCheckClasses == null)
- newExecutableCheckClasses = InitCheckClasses();
-
+ newExecutableCheckClasses ??= InitCheckClasses();
return newExecutableCheckClasses ?? Enumerable.Empty();
}
}
@@ -96,9 +88,7 @@ namespace BinaryObjectScanner.FileType
{
get
{
- if (portableExecutableCheckClasses == null)
- portableExecutableCheckClasses = InitCheckClasses();
-
+ portableExecutableCheckClasses ??= InitCheckClasses();
return portableExecutableCheckClasses ?? Enumerable.Empty();
}
}
@@ -140,10 +130,8 @@ namespace BinaryObjectScanner.FileType
if (!File.Exists(file))
return null;
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- return Detect(fs, file, includeDebug);
- }
+ using var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
+ return Detect(fs, file, includeDebug);
}
///
@@ -211,19 +199,17 @@ namespace BinaryObjectScanner.FileType
return null;
// Read the file contents
- byte[] fileContent = new byte[0];
+ byte[] fileContent = [];
try
{
#if NET40
- using (BinaryReader br = new BinaryReader(stream, Encoding.Default))
+ using var br = new BinaryReader(stream, Encoding.Default);
#else
- using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
+ using var br = new BinaryReader(stream, Encoding.Default, true);
#endif
- {
- fileContent = br.ReadBytes((int)stream.Length);
- if (fileContent == null)
- return null;
- }
+ fileContent = br.ReadBytes((int)stream.Length);
+ if (fileContent == null)
+ return null;
}
catch (Exception ex)
{
diff --git a/BinaryObjectScanner/Progress.cs b/BinaryObjectScanner/Progress.cs
index b5ba9f9b..062ab0da 100644
--- a/BinaryObjectScanner/Progress.cs
+++ b/BinaryObjectScanner/Progress.cs
@@ -50,10 +50,7 @@ namespace System
/// The is null ( in Visual Basic).
public Progress(Action handler) : this()
{
- if (handler == null)
- throw new ArgumentNullException(nameof(handler));
-
- _handler = handler;
+ _handler = handler ?? throw new ArgumentNullException(nameof(handler));
}
/// Raised for each reported progress value.
@@ -103,7 +100,7 @@ namespace System
internal static class ProgressStatics
{
/// A default synchronization context that targets the ThreadPool.
- internal static readonly SynchronizationContext DefaultContext = new SynchronizationContext();
+ internal static readonly SynchronizationContext DefaultContext = new();
}
}
diff --git a/Test/Extractor.cs b/Test/Extractor.cs
index 95d1f48d..0de39668 100644
--- a/Test/Extractor.cs
+++ b/Test/Extractor.cs
@@ -57,27 +57,26 @@ namespace Test
private static void ExtractFile(string file, string outputDirectory)
{
Console.WriteLine($"Attempting to extract all files from {file}");
+ using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
- using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
+ // Read the first 8 bytes
+ byte[]? magic = stream.ReadBytes(8);
+ stream.Seek(0, SeekOrigin.Begin);
+
+ // Get the file type
+ SupportedFileType ft = FileTypes.GetFileType(magic ?? []);
+
+ // Executables technically can be "extracted", but let's ignore that
+ // TODO: Support executables that include other stuff
+
+ // 7-zip
+ if (ft == SupportedFileType.SevenZip)
{
- // Read the first 8 bytes
- byte[] magic = stream.ReadBytes(8);
- stream.Seek(0, SeekOrigin.Begin);
+ // Build the archive information
+ Console.WriteLine("Extracting 7-zip contents");
+ Console.WriteLine();
- // Get the file type
- SupportedFileType ft = FileTypes.GetFileType(magic);
-
- // Executables technically can be "extracted", but let's ignore that
- // TODO: Support executables that include other stuff
-
- // 7-zip
- if (ft == SupportedFileType.SevenZip)
- {
- // Build the archive information
- Console.WriteLine("Extracting 7-zip contents");
- Console.WriteLine();
-
- // If the 7-zip file itself fails
+ // If the 7-zip file itself fails
#if NET462_OR_GREATER
try
{
@@ -109,72 +108,72 @@ namespace Test
Console.WriteLine();
}
#else
- Console.WriteLine($"Extracting 7-zip not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting 7-zip not supported on this .NET version");
+ Console.WriteLine();
#endif
+ }
+
+ // BFPK archive
+ else if (ft == SupportedFileType.BFPK)
+ {
+ // Build the BFPK information
+ Console.WriteLine("Extracting BFPK contents");
+ Console.WriteLine();
+
+ var bfpk = BFPK.Create(stream);
+ if (bfpk == null)
+ {
+ Console.WriteLine("Something went wrong parsing BFPK archive");
+ Console.WriteLine();
+ return;
}
- // BFPK archive
- else if (ft == SupportedFileType.BFPK)
+ try
{
- // Build the BFPK information
- Console.WriteLine("Extracting BFPK contents");
+ // Extract the BFPK contents to the directory
+ BinaryObjectScanner.FileType.BFPK.ExtractAll(bfpk, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting BFPK archive: {ex}");
Console.WriteLine();
+ }
+ }
- var bfpk = BFPK.Create(stream);
- if (bfpk == null)
- {
- Console.WriteLine("Something went wrong parsing BFPK archive");
- Console.WriteLine();
- return;
- }
+ // BSP
+ else if (ft == SupportedFileType.BSP)
+ {
+ // Build the BSP information
+ Console.WriteLine("Extracting BSP contents");
+ Console.WriteLine();
- try
- {
- // Extract the BFPK contents to the directory
- BinaryObjectScanner.FileType.BFPK.ExtractAll(bfpk, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting BFPK archive: {ex}");
- Console.WriteLine();
- }
+ var bsp = BSP.Create(stream);
+ if (bsp == null)
+ {
+ Console.WriteLine("Something went wrong parsing BSP");
+ Console.WriteLine();
+ return;
}
- // BSP
- else if (ft == SupportedFileType.BSP)
+ try
{
- // Build the BSP information
- Console.WriteLine("Extracting BSP contents");
- Console.WriteLine();
-
- var bsp = BSP.Create(stream);
- if (bsp == null)
- {
- Console.WriteLine("Something went wrong parsing BSP");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the BSP contents to the directory
- BinaryObjectScanner.FileType.BSP.ExtractAllLumps(bsp, outputDirectory);
- BinaryObjectScanner.FileType.BSP.ExtractAllTextures(bsp, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting BSP: {ex}");
- Console.WriteLine();
- }
+ // Extract the BSP contents to the directory
+ BinaryObjectScanner.FileType.BSP.ExtractAllLumps(bsp, outputDirectory);
+ BinaryObjectScanner.FileType.BSP.ExtractAllTextures(bsp, outputDirectory);
}
-
- // bzip2
- else if (ft == SupportedFileType.BZip2)
+ catch (Exception ex)
{
- // Build the bzip2 information
- Console.WriteLine("Extracting bzip2 contents");
+ Console.WriteLine($"Something went wrong extracting BSP: {ex}");
Console.WriteLine();
+ }
+ }
+
+ // bzip2
+ else if (ft == SupportedFileType.BZip2)
+ {
+ // Build the bzip2 information
+ Console.WriteLine("Extracting bzip2 contents");
+ Console.WriteLine();
#if NET462_OR_GREATER
using (var bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
@@ -195,96 +194,92 @@ namespace Test
}
}
#else
- Console.WriteLine($"Extracting bzip2 not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting bzip2 not supported on this .NET version");
+ Console.WriteLine();
#endif
- }
+ }
- // CFB
- else if (ft == SupportedFileType.CFB)
+ // CFB
+ else if (ft == SupportedFileType.CFB)
+ {
+ // Build the installer information
+ Console.WriteLine("Extracting CFB contents");
+ Console.WriteLine();
+
+ // If the CFB file itself fails
+ try
{
- // Build the installer information
- Console.WriteLine("Extracting CFB contents");
- Console.WriteLine();
-
- // If the CFB file itself fails
- try
+ using var cf = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
+ cf.RootStorage.VisitEntries((e) =>
{
- using (CompoundFile cf = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default))
+ if (!e.IsStream)
+ return;
+
+ var str = cf.RootStorage.GetStream(e.Name);
+ if (str == null)
+ return;
+
+ byte[] strData = str.GetData();
+ if (strData == null)
+ return;
+
+ string decoded = BinaryObjectScanner.FileType.CFB.DecodeStreamName(e.Name)?.TrimEnd('\0') ?? string.Empty;
+ byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
+
+ // UTF-8 encoding of 0x4840.
+ if (nameBytes[0] == 0xe4 && nameBytes[1] == 0xa1 && nameBytes[2] == 0x80)
+ decoded = decoded.Substring(3);
+
+ foreach (char c in Path.GetInvalidFileNameChars())
{
- cf.RootStorage.VisitEntries((e) =>
- {
- if (!e.IsStream)
- return;
-
- var str = cf.RootStorage.GetStream(e.Name);
- if (str == null)
- return;
-
- byte[] strData = str.GetData();
- if (strData == null)
- return;
-
- string decoded = BinaryObjectScanner.FileType.CFB.DecodeStreamName(e.Name).TrimEnd('\0');
- byte[] nameBytes = Encoding.UTF8.GetBytes(e.Name);
-
- // UTF-8 encoding of 0x4840.
- if (nameBytes[0] == 0xe4 && nameBytes[1] == 0xa1 && nameBytes[2] == 0x80)
- decoded = decoded.Substring(3);
-
- foreach (char c in Path.GetInvalidFileNameChars())
- {
- decoded = decoded.Replace(c, '_');
- }
-
- string filename = Path.Combine(outputDirectory, decoded);
- using (Stream fs = File.OpenWrite(filename))
- {
- fs.Write(strData, 0, strData.Length);
- }
- }, recursive: true);
+ decoded = decoded.Replace(c, '_');
}
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting CFB: {ex}");
- Console.WriteLine();
- }
+
+ string filename = Path.Combine(outputDirectory, decoded);
+ using Stream fs = File.OpenWrite(filename);
+ fs.Write(strData, 0, strData.Length);
+ }, recursive: true);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting CFB: {ex}");
+ Console.WriteLine();
+ }
+ }
+
+ // GCF
+ else if (ft == SupportedFileType.GCF)
+ {
+ // Build the GCF information
+ Console.WriteLine("Extracting GCF contents");
+ Console.WriteLine();
+
+ var gcf = GCF.Create(stream);
+ if (gcf == null)
+ {
+ Console.WriteLine("Something went wrong parsing GCF");
+ Console.WriteLine();
+ return;
}
- // GCF
- else if (ft == SupportedFileType.GCF)
+ try
{
- // Build the GCF information
- Console.WriteLine("Extracting GCF contents");
- Console.WriteLine();
-
- var gcf = GCF.Create(stream);
- if (gcf == null)
- {
- Console.WriteLine("Something went wrong parsing GCF");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the GCF contents to the directory
- BinaryObjectScanner.FileType.GCF.ExtractAll(gcf, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting GCF: {ex}");
- Console.WriteLine();
- }
+ // Extract the GCF contents to the directory
+ BinaryObjectScanner.FileType.GCF.ExtractAll(gcf, outputDirectory);
}
-
- // gzip
- else if (ft == SupportedFileType.GZIP)
+ catch (Exception ex)
{
- // Build the gzip information
- Console.WriteLine("Extracting gzip contents");
+ Console.WriteLine($"Something went wrong extracting GCF: {ex}");
Console.WriteLine();
+ }
+ }
+
+ // gzip
+ else if (ft == SupportedFileType.GZIP)
+ {
+ // Build the gzip information
+ Console.WriteLine("Extracting gzip contents");
+ Console.WriteLine();
#if NET462_OR_GREATER
using (var zipFile = GZipArchive.Open(stream))
@@ -310,161 +305,164 @@ namespace Test
}
}
#else
- Console.WriteLine($"Extracting gzip not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting gzip not supported on this .NET version");
+ Console.WriteLine();
#endif
- }
+ }
- // InstallShield Archive V3 (Z)
- else if (ft == SupportedFileType.InstallShieldArchiveV3)
+ // InstallShield Archive V3 (Z)
+ else if (ft == SupportedFileType.InstallShieldArchiveV3)
+ {
+ // Build the InstallShield Archive V3 information
+ Console.WriteLine("Extracting InstallShield Archive V3 contents");
+ Console.WriteLine();
+
+ // If the cab file itself fails
+ try
{
- // Build the InstallShield Archive V3 information
- Console.WriteLine("Extracting InstallShield Archive V3 contents");
- Console.WriteLine();
-
- // If the cab file itself fails
- try
+ var archive = new InstallShieldArchiveV3(file);
+ foreach (var cfile in archive.Files.Select(kvp => kvp.Value))
{
- var archive = new InstallShieldArchiveV3(file);
- foreach (var cfile in archive.Files.Select(kvp => kvp.Value))
+ // If an individual entry fails
+ try
{
- // If an individual entry fails
+ string tempFile = Path.Combine(outputDirectory, cfile.FullPath ?? string.Empty);
+ string? directoryName = Path.GetDirectoryName(tempFile);
+ if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName))
+ Directory.CreateDirectory(directoryName);
+
+ (byte[]? fileContents, string? error) = archive.Extract(cfile.FullPath ?? string.Empty);
+ if (!string.IsNullOrWhiteSpace(error))
+ continue;
+
+ if (fileContents != null && fileContents.Length > 0)
+ {
+ using FileStream fs = File.OpenWrite(tempFile);
+ fs.Write(fileContents, 0, fileContents.Length);
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting InstallShield Archive V3 entry {cfile.Name}: {ex}");
+ Console.WriteLine();
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting InstallShield Archive V3: {ex}");
+ Console.WriteLine();
+ }
+ }
+
+ // IS-CAB archive
+ else if (ft == SupportedFileType.InstallShieldCAB)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting IS-CAB contents");
+ Console.WriteLine();
+
+ // If the cab file itself fails
+ try
+ {
+ var cabfile = UnshieldSharp.Cabinet.InstallShieldCabinet.Open(file);
+ for (int i = 0; i < (cabfile?.FileCount ?? 0); i++)
+ {
+ // If an individual entry fails
+ try
+ {
+ string? filename = cabfile?.FileName(i);
+ string tempFile;
try
{
- string tempFile = Path.Combine(outputDirectory, cfile.FullPath);
- if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
- Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
-
- (byte[] fileContents, string error) = archive.Extract(cfile.FullPath);
- if (!string.IsNullOrWhiteSpace(error))
- continue;
-
- using (FileStream fs = File.OpenWrite(tempFile))
- {
- fs.Write(fileContents, 0, fileContents.Length);
- }
+ tempFile = Path.Combine(outputDirectory, filename ?? $"BAD_FILENAME{i}");
}
- catch (Exception ex)
+ catch
{
- Console.WriteLine($"Something went wrong extracting InstallShield Archive V3 entry {cfile.Name}: {ex}");
- Console.WriteLine();
+ tempFile = Path.Combine(outputDirectory, $"BAD_FILENAME{i}");
}
+
+ cabfile?.FileSave(i, tempFile);
}
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting InstallShield Archive V3: {ex}");
- Console.WriteLine();
- }
- }
-
- // IS-CAB archive
- else if (ft == SupportedFileType.InstallShieldCAB)
- {
- // Build the archive information
- Console.WriteLine("Extracting IS-CAB contents");
- Console.WriteLine();
-
- // If the cab file itself fails
- try
- {
- var cabfile = UnshieldSharp.Cabinet.InstallShieldCabinet.Open(file);
- for (int i = 0; i < cabfile.FileCount; i++)
+ catch (Exception ex)
{
- // If an individual entry fails
- try
- {
- string filename = cabfile.FileName(i);
- string tempFile;
- try
- {
- tempFile = Path.Combine(outputDirectory, filename);
- }
- catch
- {
- tempFile = Path.Combine(outputDirectory, $"BAD_FILENAME{i}");
- }
-
- cabfile.FileSave(i, tempFile);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting IS-CAB entry {i}: {ex}");
- Console.WriteLine();
- }
+ Console.WriteLine($"Something went wrong extracting IS-CAB entry {i}: {ex}");
+ Console.WriteLine();
}
}
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting IS-CAB: {ex}");
- Console.WriteLine();
- }
}
-
- // Microsoft Cabinet archive
- else if (ft == SupportedFileType.MicrosoftCAB)
+ catch (Exception ex)
{
- // Build the cabinet information
- Console.WriteLine("Extracting MS-CAB contents");
+ Console.WriteLine($"Something went wrong extracting IS-CAB: {ex}");
Console.WriteLine();
-
- var cabinet = MicrosoftCabinet.Create(stream);
- if (cabinet == null)
- {
- Console.WriteLine("Something went wrong parsing MS-CAB archive");
- Console.WriteLine();
- return;
- }
-
- try
- {
- Console.WriteLine("MS-CAB extraction is disabled");
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting MS-CAB: {ex}");
- Console.WriteLine();
- }
}
+ }
- // Microsoft LZ / LZ32
- else if (ft == SupportedFileType.MicrosoftLZ)
+ // Microsoft Cabinet archive
+ else if (ft == SupportedFileType.MicrosoftCAB)
+ {
+ // Build the cabinet information
+ Console.WriteLine("Extracting MS-CAB contents");
+ Console.WriteLine();
+
+ var cabinet = MicrosoftCabinet.Create(stream);
+ if (cabinet == null)
{
- // Build the Microsoft LZ / LZ32 information
- Console.WriteLine("Extracting Microsoft LZ / LZ32 contents");
+ Console.WriteLine("Something went wrong parsing MS-CAB archive");
Console.WriteLine();
+ return;
+ }
- // If the LZ file itself fails
- try
+ try
+ {
+ Console.WriteLine("MS-CAB extraction is disabled");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting MS-CAB: {ex}");
+ Console.WriteLine();
+ }
+ }
+
+ // Microsoft LZ / LZ32
+ else if (ft == SupportedFileType.MicrosoftLZ)
+ {
+ // Build the Microsoft LZ / LZ32 information
+ Console.WriteLine("Extracting Microsoft LZ / LZ32 contents");
+ Console.WriteLine();
+
+ // If the LZ file itself fails
+ try
+ {
+ byte[]? data = SabreTools.Compression.LZ.Decompressor.Decompress(stream);
+
+ // Create the temp filename
+ string tempFile = "temp.bin";
+ if (!string.IsNullOrEmpty(file))
{
- byte[] data = SabreTools.Compression.LZ.Decompressor.Decompress(stream);
-
- // Create the temp filename
- string tempFile = "temp.bin";
- if (!string.IsNullOrEmpty(file))
- {
- string expandedFilePath = SabreTools.Compression.LZ.Decompressor.GetExpandedName(file, out _);
- tempFile = Path.GetFileName(expandedFilePath).TrimEnd('\0');
- if (tempFile.EndsWith(".ex"))
- tempFile += "e";
- else if (tempFile.EndsWith(".dl"))
- tempFile += "l";
- }
-
- tempFile = Path.Combine(outputDirectory, tempFile);
-
- // Write the file data to a temp file
- using (Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
- {
- tempStream.Write(data, 0, data.Length);
- }
+ string? expandedFilePath = SabreTools.Compression.LZ.Decompressor.GetExpandedName(file, out _);
+ tempFile = Path.GetFileName(expandedFilePath)?.TrimEnd('\0') ?? string.Empty;
+ if (tempFile.EndsWith(".ex"))
+ tempFile += "e";
+ else if (tempFile.EndsWith(".dl"))
+ tempFile += "l";
}
- catch (Exception ex)
+
+ tempFile = Path.Combine(outputDirectory, tempFile);
+
+ // Write the file data to a temp file
+ if (data != null && data.Length > 0)
{
- Console.WriteLine($"Something went wrong extracting Microsoft LZ / LZ32: {ex}");
- Console.WriteLine();
+ using Stream tempStream = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
+ tempStream.Write(data, 0, data.Length);
}
}
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting Microsoft LZ / LZ32: {ex}");
+ Console.WriteLine();
+ }
+ }
#if NETFRAMEWORK && !NET40
// MoPaQ (MPQ) archive
@@ -480,7 +478,7 @@ namespace Test
using (var mpqArchive = new StormLibSharp.MpqArchive(file, FileAccess.Read))
{
// Try to open the listfile
- string listfile = null;
+ string? listfile = null;
StormLibSharp.MpqFileStream listStream = mpqArchive.OpenFile("(listfile)");
// If we can't read the listfile, we just return
@@ -525,68 +523,68 @@ namespace Test
}
#endif
- // PAK
- else if (ft == SupportedFileType.PAK)
+ // PAK
+ else if (ft == SupportedFileType.PAK)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting PAK contents");
+ Console.WriteLine();
+
+ var pak = PAK.Create(stream);
+ if (pak == null)
{
- // Build the archive information
- Console.WriteLine("Extracting PAK contents");
+ Console.WriteLine("Something went wrong parsing PAK");
Console.WriteLine();
-
- var pak = PAK.Create(stream);
- if (pak == null)
- {
- Console.WriteLine("Something went wrong parsing PAK");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the PAK contents to the directory
- BinaryObjectScanner.FileType.PAK.ExtractAll(pak, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting PAK: {ex}");
- Console.WriteLine();
- }
+ return;
}
- // PFF
- else if (ft == SupportedFileType.PFF)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting PFF contents");
+ // Extract the PAK contents to the directory
+ BinaryObjectScanner.FileType.PAK.ExtractAll(pak, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting PAK: {ex}");
Console.WriteLine();
+ }
+ }
- var pff = PFF.Create(stream);
- if (pff == null)
- {
- Console.WriteLine("Something went wrong parsing PFF");
- Console.WriteLine();
- return;
- }
+ // PFF
+ else if (ft == SupportedFileType.PFF)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting PFF contents");
+ Console.WriteLine();
- try
- {
- // Extract the PFF contents to the directory
- BinaryObjectScanner.FileType.PFF.ExtractAll(pff, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting PFF: {ex}");
- Console.WriteLine();
- }
+ var pff = PFF.Create(stream);
+ if (pff == null)
+ {
+ Console.WriteLine("Something went wrong parsing PFF");
+ Console.WriteLine();
+ return;
}
- // PKZIP
- else if (ft == SupportedFileType.PKZIP)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting PKZIP contents");
+ // Extract the PFF contents to the directory
+ BinaryObjectScanner.FileType.PFF.ExtractAll(pff, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting PFF: {ex}");
Console.WriteLine();
+ }
+ }
- // If the zip file itself fails
+ // PKZIP
+ else if (ft == SupportedFileType.PKZIP)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting PKZIP contents");
+ Console.WriteLine();
+
+ // If the zip file itself fails
#if NET462_OR_GREATER
try
{
@@ -619,46 +617,46 @@ namespace Test
Console.WriteLine();
}
#else
- Console.WriteLine($"Extracting PKZIP not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting PKZIP not supported on this .NET version");
+ Console.WriteLine();
#endif
+ }
+
+ // Quantum
+ else if (ft == SupportedFileType.Quantum)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting Quantum contents");
+ Console.WriteLine();
+
+ var quantum = Quantum.Create(stream);
+ if (quantum == null)
+ {
+ Console.WriteLine("Something went wrong parsing Quantum");
+ Console.WriteLine();
+ return;
}
- // Quantum
- else if (ft == SupportedFileType.Quantum)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting Quantum contents");
- Console.WriteLine();
-
- var quantum = Quantum.Create(stream);
- if (quantum == null)
- {
- Console.WriteLine("Something went wrong parsing Quantum");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the Quantum contents to the directory
- BinaryObjectScanner.FileType.Quantum.ExtractAll(quantum, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting Quantum: {ex}");
- Console.WriteLine();
- }
+ // Extract the Quantum contents to the directory
+ BinaryObjectScanner.FileType.Quantum.ExtractAll(quantum, outputDirectory);
}
-
- // RAR
- else if (ft == SupportedFileType.RAR)
+ catch (Exception ex)
{
- // Build the archive information
- Console.WriteLine("Extracting RAR contents");
+ Console.WriteLine($"Something went wrong extracting Quantum: {ex}");
Console.WriteLine();
+ }
+ }
- // If the rar file itself fails
+ // RAR
+ else if (ft == SupportedFileType.RAR)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting RAR contents");
+ Console.WriteLine();
+
+ // If the rar file itself fails
#if NET462_OR_GREATER
try
{
@@ -690,46 +688,46 @@ namespace Test
Console.WriteLine();
}
#else
- Console.WriteLine($"Extracting RAR not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting RAR not supported on this .NET version");
+ Console.WriteLine();
#endif
+ }
+
+ // SGA
+ else if (ft == SupportedFileType.SGA)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting SGA contents");
+ Console.WriteLine();
+
+ var sga = SGA.Create(stream);
+ if (sga == null)
+ {
+ Console.WriteLine("Something went wrong parsing SGA");
+ Console.WriteLine();
+ return;
}
- // SGA
- else if (ft == SupportedFileType.SGA)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting SGA contents");
- Console.WriteLine();
-
- var sga = SGA.Create(stream);
- if (sga == null)
- {
- Console.WriteLine("Something went wrong parsing SGA");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the SGA contents to the directory
- BinaryObjectScanner.FileType.SGA.ExtractAll(sga, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting SGA: {ex}");
- Console.WriteLine();
- }
+ // Extract the SGA contents to the directory
+ BinaryObjectScanner.FileType.SGA.ExtractAll(sga, outputDirectory);
}
-
- // Tape Archive
- else if (ft == SupportedFileType.RAR)
+ catch (Exception ex)
{
- // Build the archive information
- Console.WriteLine("Extracting Tape Archive contents");
+ Console.WriteLine($"Something went wrong extracting SGA: {ex}");
Console.WriteLine();
+ }
+ }
- // If the tar file itself fails
+ // Tape Archive
+ else if (ft == SupportedFileType.RAR)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting Tape Archive contents");
+ Console.WriteLine();
+
+ // If the tar file itself fails
#if NET462_OR_GREATER
try
{
@@ -761,98 +759,98 @@ namespace Test
Console.WriteLine();
}
#else
- Console.WriteLine($"Extracting Tape Archive not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting Tape Archive not supported on this .NET version");
+ Console.WriteLine();
#endif
+ }
+
+ // VBSP
+ else if (ft == SupportedFileType.VBSP)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting VBSP contents");
+ Console.WriteLine();
+
+ var vbsp = VBSP.Create(stream);
+ if (vbsp == null)
+ {
+ Console.WriteLine("Something went wrong parsing VBSP");
+ Console.WriteLine();
+ return;
}
- // VBSP
- else if (ft == SupportedFileType.VBSP)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting VBSP contents");
+ // Extract the VBSP contents to the directory
+ BinaryObjectScanner.FileType.VBSP.ExtractAllLumps(vbsp, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting VBSP: {ex}");
Console.WriteLine();
+ }
+ }
- var vbsp = VBSP.Create(stream);
- if (vbsp == null)
- {
- Console.WriteLine("Something went wrong parsing VBSP");
- Console.WriteLine();
- return;
- }
+ // VPK
+ else if (ft == SupportedFileType.VPK)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting VPK contents");
+ Console.WriteLine();
- try
- {
- // Extract the VBSP contents to the directory
- BinaryObjectScanner.FileType.VBSP.ExtractAllLumps(vbsp, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting VBSP: {ex}");
- Console.WriteLine();
- }
+ var vpk = VPK.Create(stream);
+ if (vpk == null)
+ {
+ Console.WriteLine("Something went wrong parsing VPK");
+ Console.WriteLine();
+ return;
}
- // VPK
- else if (ft == SupportedFileType.VPK)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting VPK contents");
+ // Extract the VPK contents to the directory
+ BinaryObjectScanner.FileType.VPK.ExtractAll(vpk, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting VPK: {ex}");
Console.WriteLine();
+ }
+ }
- var vpk = VPK.Create(stream);
- if (vpk == null)
- {
- Console.WriteLine("Something went wrong parsing VPK");
- Console.WriteLine();
- return;
- }
+ // WAD
+ else if (ft == SupportedFileType.WAD)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting WAD contents");
+ Console.WriteLine();
- try
- {
- // Extract the VPK contents to the directory
- BinaryObjectScanner.FileType.VPK.ExtractAll(vpk, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting VPK: {ex}");
- Console.WriteLine();
- }
+ var wad = WAD.Create(stream);
+ if (wad == null)
+ {
+ Console.WriteLine("Something went wrong parsing WAD");
+ Console.WriteLine();
+ return;
}
- // WAD
- else if (ft == SupportedFileType.WAD)
+ try
{
- // Build the archive information
- Console.WriteLine("Extracting WAD contents");
- Console.WriteLine();
-
- var wad = WAD.Create(stream);
- if (wad == null)
- {
- Console.WriteLine("Something went wrong parsing WAD");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the WAD contents to the directory
- BinaryObjectScanner.FileType.WAD.ExtractAllLumps(wad, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting WAD: {ex}");
- Console.WriteLine();
- }
+ // Extract the WAD contents to the directory
+ BinaryObjectScanner.FileType.WAD.ExtractAllLumps(wad, outputDirectory);
}
-
- // xz
- else if (ft == SupportedFileType.RAR)
+ catch (Exception ex)
{
- // Build the xz information
- Console.WriteLine("Extracting xz contents");
+ Console.WriteLine($"Something went wrong extracting WAD: {ex}");
Console.WriteLine();
+ }
+ }
+
+ // xz
+ else if (ft == SupportedFileType.RAR)
+ {
+ // Build the xz information
+ Console.WriteLine("Extracting xz contents");
+ Console.WriteLine();
#if NET462_OR_GREATER
using (var xzFile = new XZStream(stream))
@@ -873,45 +871,44 @@ namespace Test
}
}
#else
- Console.WriteLine($"Extracting xz not supported on this .NET version");
- Console.WriteLine();
+ Console.WriteLine($"Extracting xz not supported on this .NET version");
+ Console.WriteLine();
#endif
- }
+ }
- // XZP
- else if (ft == SupportedFileType.XZP)
+ // XZP
+ else if (ft == SupportedFileType.XZP)
+ {
+ // Build the archive information
+ Console.WriteLine("Extracting XZP contents");
+ Console.WriteLine();
+
+ var xzp = XZP.Create(stream);
+ if (xzp == null)
{
- // Build the archive information
- Console.WriteLine("Extracting XZP contents");
- Console.WriteLine();
-
- var xzp = XZP.Create(stream);
- if (xzp == null)
- {
- Console.WriteLine("Something went wrong parsing XZP");
- Console.WriteLine();
- return;
- }
-
- try
- {
- // Extract the XZP contents to the directory
- BinaryObjectScanner.FileType.XZP.ExtractAll(xzp, outputDirectory);
- }
- catch (Exception ex)
- {
- Console.WriteLine($"Something went wrong extracting XZP: {ex}");
- Console.WriteLine();
- }
- }
-
- // Everything else
- else
- {
- Console.WriteLine("Not a supported extractable file format, skipping...");
+ Console.WriteLine("Something went wrong parsing XZP");
Console.WriteLine();
return;
}
+
+ try
+ {
+ // Extract the XZP contents to the directory
+ BinaryObjectScanner.FileType.XZP.ExtractAll(xzp, outputDirectory);
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"Something went wrong extracting XZP: {ex}");
+ Console.WriteLine();
+ }
+ }
+
+ // Everything else
+ else
+ {
+ Console.WriteLine("Not a supported extractable file format, skipping...");
+ Console.WriteLine();
+ return;
}
}
}
diff --git a/Test/Options.cs b/Test/Options.cs
index ef241765..345319ab 100644
--- a/Test/Options.cs
+++ b/Test/Options.cs
@@ -19,7 +19,7 @@ namespace Test
///
/// Set of input paths to use for operations
///
- public List InputPaths { get; private set; } = new List();
+ public List InputPaths { get; private set; } = [];
#region Extraction
@@ -90,7 +90,7 @@ namespace Test
///
/// Parse commandline arguments into an Options object
///
- public static Options ParseOptions(string[] args)
+ public static Options? ParseOptions(string[] args)
{
// If we have invalid arguments
if (args == null || args.Length == 0)
@@ -154,7 +154,7 @@ namespace Test
case "-o":
case "--outdir":
- options.OutputPath = index + 1 < args.Length ? args[++index] : null;
+ options.OutputPath = index + 1 < args.Length ? args[++index] : string.Empty;
break;
#endregion
diff --git a/Test/Printer.cs b/Test/Printer.cs
index 4d8c382b..12a220d0 100644
--- a/Test/Printer.cs
+++ b/Test/Printer.cs
@@ -45,39 +45,39 @@ namespace Test
{
Console.WriteLine($"Attempting to print info for {file}");
- using (Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
+ using Stream stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
+
+ // Read the first 8 bytes
+ byte[]? magic = stream.ReadBytes(8);
+ stream.Seek(0, SeekOrigin.Begin);
+
+ // Get the file type
+ SupportedFileType ft = FileTypes.GetFileType(magic ?? []);
+ if (ft == SupportedFileType.UNKNOWN)
{
- // Read the first 8 bytes
- byte[] magic = stream.ReadBytes(8);
- stream.Seek(0, SeekOrigin.Begin);
+ string extension = Path.GetExtension(file).TrimStart('.');
+ ft = FileTypes.GetFileType(extension);
+ }
- // Get the file type
- SupportedFileType ft = FileTypes.GetFileType(magic);
- if (ft == SupportedFileType.UNKNOWN)
- {
- string extension = Path.GetExtension(file).TrimStart('.');
- ft = FileTypes.GetFileType(extension);
- }
+ // Print out the file format
+ Console.WriteLine($"File format found: {ft}");
- // Print out the file format
- Console.WriteLine($"File format found: {ft}");
+ // Setup the wrapper to print
+ var wrapper = WrapperFactory.CreateWrapper(ft, stream);
- // Setup the wrapper to print
- var wrapper = WrapperFactory.CreateWrapper(ft, stream);
+ // If we don't have a wrapper
+ if (wrapper == null)
+ {
+ Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
+ Console.WriteLine();
+ return;
+ }
- // If we don't have a wrapper
- if (wrapper == null)
- {
- Console.WriteLine($"Either {ft} is not supported or something went wrong during parsing!");
- Console.WriteLine();
- return;
- }
+ // Print the wrapper name
+ Console.WriteLine($"{wrapper.Description()} wrapper created successfully!");
- // Print the wrapper name
- Console.WriteLine($"{wrapper.Description()} wrapper created successfully!");
-
- // Get the base info output name
- string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
+ // Get the base info output name
+ string filenameBase = $"info-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}";
#if NET6_0_OR_GREATER
// If we have the JSON flag
@@ -88,22 +88,17 @@ namespace Test
Console.WriteLine(serializedData);
// Write the output data
- using (var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.json")))
- {
- sw.WriteLine(serializedData);
- }
+ using var jsw = new StreamWriter(File.OpenWrite($"{filenameBase}.json"));
+ jsw.WriteLine(serializedData);
}
#endif
- // Create the output data
- StringBuilder builder = wrapper.PrettyPrint();
- Console.WriteLine(builder);
+ // Create the output data
+ var builder = wrapper.PrettyPrint();
+ Console.WriteLine(builder);
- // Write the output data
- using (var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt")))
- {
- sw.WriteLine(builder.ToString());
- }
- }
+ // Write the output data
+ using var sw = new StreamWriter(File.OpenWrite($"{filenameBase}.txt"));
+ sw.WriteLine(builder.ToString());
}
#region Printing Implementations
@@ -113,38 +108,38 @@ namespace Test
///
private static StringBuilder PrettyPrint(this IWrapper wrapper)
{
- switch (wrapper)
+ return wrapper switch
{
- case AACSMediaKeyBlock item: return item.PrettyPrint();
- case BDPlusSVM item: return item.PrettyPrint();
- case BFPK item: return item.PrettyPrint();
- case BSP item: return item.PrettyPrint();
- case CFB item: return item.PrettyPrint();
- case CIA item: return item.PrettyPrint();
- case GCF item: return item.PrettyPrint();
- case InstallShieldCabinet item: return item.PrettyPrint();
- case IRD item: return item.PrettyPrint();
- case LinearExecutable item: return item.PrettyPrint();
- case MicrosoftCabinet item: return item.PrettyPrint();
- case MSDOS item: return item.PrettyPrint();
- case N3DS item: return item.PrettyPrint();
- case NCF item: return item.PrettyPrint();
- case NewExecutable item: return item.PrettyPrint();
- case Nitro item: return item.PrettyPrint();
- case PAK item: return item.PrettyPrint();
- case PFF item: return item.PrettyPrint();
- case PlayJAudioFile item: return item.PrettyPrint();
- case PortableExecutable item: return item.PrettyPrint();
- case Quantum item: return item.PrettyPrint();
- case SGA item: return item.PrettyPrint();
- case VBSP item: return item.PrettyPrint();
- case VPK item: return item.PrettyPrint();
- case WAD item: return item.PrettyPrint();
- case XeMID item: return item.PrettyPrint();
- case XMID item: return item.PrettyPrint();
- case XZP item: return item.PrettyPrint();
- default: return new StringBuilder();
- }
+ AACSMediaKeyBlock item => item.PrettyPrint(),
+ BDPlusSVM item => item.PrettyPrint(),
+ BFPK item => item.PrettyPrint(),
+ BSP item => item.PrettyPrint(),
+ CFB item => item.PrettyPrint(),
+ CIA item => item.PrettyPrint(),
+ GCF item => item.PrettyPrint(),
+ InstallShieldCabinet item => item.PrettyPrint(),
+ IRD item => item.PrettyPrint(),
+ LinearExecutable item => item.PrettyPrint(),
+ MicrosoftCabinet item => item.PrettyPrint(),
+ MSDOS item => item.PrettyPrint(),
+ N3DS item => item.PrettyPrint(),
+ NCF item => item.PrettyPrint(),
+ NewExecutable item => item.PrettyPrint(),
+ Nitro item => item.PrettyPrint(),
+ PAK item => item.PrettyPrint(),
+ PFF item => item.PrettyPrint(),
+ PlayJAudioFile item => item.PrettyPrint(),
+ PortableExecutable item => item.PrettyPrint(),
+ Quantum item => item.PrettyPrint(),
+ SGA item => item.PrettyPrint(),
+ VBSP item => item.PrettyPrint(),
+ VPK item => item.PrettyPrint(),
+ WAD item => item.PrettyPrint(),
+ XeMID item => item.PrettyPrint(),
+ XMID item => item.PrettyPrint(),
+ XZP item => item.PrettyPrint(),
+ _ => new StringBuilder(),
+ };
}
///
@@ -152,7 +147,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this AACSMediaKeyBlock item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.AACSMediaKeyBlock.Print(builder, item.Model);
return builder;
}
@@ -162,7 +157,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this BDPlusSVM item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.BDPlusSVM.Print(builder, item.Model);
return builder;
}
@@ -172,7 +167,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this BFPK item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.BFPK.Print(builder, item.Model);
return builder;
}
@@ -182,7 +177,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this BSP item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.BSP.Print(builder, item.Model);
return builder;
}
@@ -192,7 +187,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this CFB item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.CFB.Print(builder, item.Model);
return builder;
}
@@ -202,7 +197,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this CIA item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.CIA.Print(builder, item.Model);
return builder;
}
@@ -212,7 +207,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this GCF item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.GCF.Print(builder, item.Model);
return builder;
}
@@ -222,7 +217,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this InstallShieldCabinet item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.InstallShieldCabinet.Print(builder, item.Model);
return builder;
}
@@ -232,7 +227,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this IRD item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.IRD.Print(builder, item.Model);
return builder;
}
@@ -242,7 +237,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this LinearExecutable item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.LinearExecutable.Print(builder, item.Model);
return builder;
}
@@ -252,7 +247,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this MicrosoftCabinet item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.MicrosoftCabinet.Print(builder, item.Model);
return builder;
}
@@ -262,7 +257,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this MSDOS item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.MSDOS.Print(builder, item.Model);
return builder;
}
@@ -272,7 +267,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this N3DS item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.N3DS.Print(builder, item.Model);
return builder;
}
@@ -282,7 +277,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this NCF item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.NCF.Print(builder, item.Model);
return builder;
}
@@ -292,7 +287,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this NewExecutable item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.NewExecutable.Print(builder, item.Model);
return builder;
}
@@ -302,7 +297,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this Nitro item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.Nitro.Print(builder, item.Model);
return builder;
}
@@ -312,7 +307,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this PAK item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.PAK.Print(builder, item.Model);
return builder;
}
@@ -322,7 +317,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this PFF item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.PFF.Print(builder, item.Model);
return builder;
}
@@ -332,7 +327,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this PlayJAudioFile item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.PlayJAudioFile.Print(builder, item.Model);
return builder;
}
@@ -342,7 +337,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this PortableExecutable item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.PortableExecutable.Print(builder, item.Model);
return builder;
}
@@ -352,7 +347,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this Quantum item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.Quantum.Print(builder, item.Model);
return builder;
}
@@ -362,7 +357,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this SGA item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.SGA.Print(builder, item.Model);
return builder;
}
@@ -372,7 +367,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this VBSP item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.VBSP.Print(builder, item.Model);
return builder;
}
@@ -382,7 +377,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this VPK item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.VPK.Print(builder, item.Model);
return builder;
}
@@ -392,7 +387,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this WAD item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.WAD.Print(builder, item.Model);
return builder;
}
@@ -402,7 +397,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this XeMID item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.XeMID.Print(builder, item.Model);
return builder;
}
@@ -412,7 +407,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this XMID item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.XMID.Print(builder, item.Model);
return builder;
}
@@ -422,7 +417,7 @@ namespace Test
///
private static StringBuilder PrettyPrint(this XZP item)
{
- StringBuilder builder = new StringBuilder();
+ var builder = new StringBuilder();
SabreTools.Printing.XZP.Print(builder, item.Model);
return builder;
}
diff --git a/Test/Program.cs b/Test/Program.cs
index 65bdb8f7..6d618560 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -1,5 +1,4 @@
using System;
-using System.Text;
using BinaryObjectScanner;
namespace Test
@@ -8,9 +7,9 @@ namespace Test
{
static void Main(string[] args)
{
-#if NET462_OR_GREATER
+#if NET462_OR_GREATER || NETCOREAPP
// Register the codepages
- Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+ System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
#endif
// Create progress indicator
diff --git a/Test/Protector.cs b/Test/Protector.cs
index 375c8c04..aa0e4277 100644
--- a/Test/Protector.cs
+++ b/Test/Protector.cs
@@ -29,10 +29,8 @@ namespace Test
}
catch (Exception ex)
{
- using (StreamWriter sw = new StreamWriter(File.OpenWrite($"exception-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt")))
- {
- sw.WriteLine(ex);
- }
+ using var sw = new StreamWriter(File.OpenWrite($"exception-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt"));
+ sw.WriteLine(ex);
}
}
@@ -41,7 +39,7 @@ namespace Test
///
/// File or directory path
/// Dictionary of protections found, if any
- private static void WriteProtectionResultFile(string path, ConcurrentDictionary> protections)
+ private static void WriteProtectionResultFile(string path, ConcurrentDictionary>? protections)
{
if (protections == null)
{
@@ -49,25 +47,23 @@ namespace Test
return;
}
- using (var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt")))
+ using var sw = new StreamWriter(File.OpenWrite($"protection-{DateTime.Now:yyyy-MM-dd_HHmmss.ffff}.txt"));
+ foreach (string key in protections.Keys.OrderBy(k => k))
{
- foreach (string key in protections.Keys.OrderBy(k => k))
- {
- // Skip over files with no protection
- if (protections[key] == null || !protections[key].Any())
- continue;
+ // Skip over files with no protection
+ if (protections[key] == null || !protections[key].Any())
+ continue;
- string line = $"{key}: {string.Join(", ", protections[key].OrderBy(p => p))}";
- Console.WriteLine(line);
- sw.WriteLine(line);
- }
+ string line = $"{key}: {string.Join(", ", protections[key].OrderBy(p => p))}";
+ Console.WriteLine(line);
+ sw.WriteLine(line);
}
}
///
/// Protection progress changed handler
///
- public static void Changed(object source, ProtectionProgress value)
+ public static void Changed(object? source, ProtectionProgress value)
{
Console.WriteLine($"{value.Percentage * 100:N2}%: {value.Filename} - {value.Protection}");
}
diff --git a/Test/Test.csproj b/Test/Test.csproj
index e95d1c2c..539be90d 100644
--- a/Test/Test.csproj
+++ b/Test/Test.csproj
@@ -4,13 +4,23 @@
net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0
win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64
Exe
+ latest
+ enable
true
+ true
+
+
+
+
+
+
+
@@ -22,14 +32,4 @@
-
-
-
-
-
-
- Always
-
-
-
\ No newline at end of file