diff --git a/.github/workflows/build_nupkg.yml b/.github/workflows/build_nupkg.yml index d8ebd2b3..e48929a4 100644 --- a/.github/workflows/build_nupkg.yml +++ b/.github/workflows/build_nupkg.yml @@ -16,10 +16,16 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore + + - name: Build library + run: dotnet build + + - name: Run tests + run: dotnet test - name: Pack run: dotnet pack diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 7de5fd59..5dcab558 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -12,7 +12,7 @@ jobs: matrix: project: [InfoPrint] runtime: [win-x86, win-x64, win-arm64, linux-x64, linux-arm64, osx-x64] - framework: [net8.0] #[net20, net35, net40, net452, net472, net48, netcoreapp3.1, net5.0, net6.0, net7.0, net8.0] + framework: [net9.0] #[net20, net35, net40, net452, net472, net48, netcoreapp3.1, net5.0, net6.0, net7.0, net8.0, net9.0] conf: [Debug] #[Release, Debug] steps: @@ -23,13 +23,13 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore - name: Build - run: dotnet publish ${{ matrix.project }}/${{ matrix.project }}.csproj -f ${{ matrix.framework }} -r ${{ matrix.runtime }} -c ${{ matrix.conf == 'Release' && 'Release -p:DebugType=None -p:DebugSymbols=false' || 'Debug'}} --self-contained true --version-suffix ${{ github.sha }} ${{ (startsWith(matrix.framework, 'net5') || startsWith(matrix.framework, 'net6') || startsWith(matrix.framework, 'net7') || startsWith(matrix.framework, 'net8')) && '-p:PublishSingleFile=true' || ''}} + run: dotnet publish ${{ matrix.project }}/${{ matrix.project }}.csproj -f ${{ matrix.framework }} -r ${{ matrix.runtime }} -c ${{ matrix.conf == 'Release' && 'Release -p:DebugType=None -p:DebugSymbols=false' || 'Debug'}} --self-contained true --version-suffix ${{ github.sha }} ${{ (startsWith(matrix.framework, 'net5') || startsWith(matrix.framework, 'net6') || startsWith(matrix.framework, 'net7') || startsWith(matrix.framework, 'net8') || startsWith(matrix.framework, 'net9')) && '-p:PublishSingleFile=true' || ''}} - name: Archive build run: | diff --git a/.github/workflows/check_pr.yml b/.github/workflows/check_pr.yml index bba92af8..9d421c56 100644 --- a/.github/workflows/check_pr.yml +++ b/.github/workflows/check_pr.yml @@ -11,7 +11,10 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Build - run: dotnet build \ No newline at end of file + run: dotnet build + + - name: Run tests + run: dotnet test \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 6b5bed4c..dd43191a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/InfoPrint/bin/Debug/net8.0/InfoPrint.dll", + "program": "${workspaceFolder}/InfoPrint/bin/Debug/net9.0/InfoPrint.dll", "args": [], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/InfoPrint/InfoPrint.csproj b/InfoPrint/InfoPrint.csproj index 6fd4ac89..6b54e25c 100644 --- a/InfoPrint/InfoPrint.csproj +++ b/InfoPrint/InfoPrint.csproj @@ -1,32 +1,32 @@  - - net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - Exe - false - false - latest - enable - true - true - + + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + Exe + false + false + latest + enable + true + true + - - - win-x86;win-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 - - - net6.0;net7.0;net8.0 - + + + win-x86;win-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 + + + net6.0;net7.0;net8.0;net9.0 + - - - + + + - + \ No newline at end of file diff --git a/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj b/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj index 62f4cc84..67cbf3cd 100644 --- a/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj +++ b/SabreTools.Serialization.Test/SabreTools.Serialization.Test.csproj @@ -1,38 +1,38 @@ - - net6.0;net8.0 - false - latest - enable - + + net6.0;net8.0;net9.0 + false + latest + enable + - - - + + + - - - + + + - - - Always - - + + + Always + + - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + - + \ No newline at end of file diff --git a/SabreTools.Serialization/Deserializers/CHD.cs b/SabreTools.Serialization/Deserializers/CHD.cs index 1febe8bf..fa72bd2d 100644 --- a/SabreTools.Serialization/Deserializers/CHD.cs +++ b/SabreTools.Serialization/Deserializers/CHD.cs @@ -232,10 +232,10 @@ namespace SabreTools.Serialization.Deserializers return null; header.Version = data.ReadUInt32BigEndian(); - header.Compressors = new uint[4]; + header.Compressors = new CodecType[4]; for (int i = 0; i < header.Compressors.Length; i++) { - header.Compressors[i] = data.ReadUInt32BigEndian(); + header.Compressors[i] = (CodecType)data.ReadUInt32BigEndian(); } header.LogicalBytes = data.ReadUInt64BigEndian(); diff --git a/SabreTools.Serialization/Printers/CHD.cs b/SabreTools.Serialization/Printers/CHD.cs index e285b76a..ea1383e9 100644 --- a/SabreTools.Serialization/Printers/CHD.cs +++ b/SabreTools.Serialization/Printers/CHD.cs @@ -124,8 +124,6 @@ namespace SabreTools.Serialization.Printers builder.AppendLine(header.Length, $"Length"); builder.AppendLine(header.Version, $"Version"); - // TODO: Remove this hack when actual compressor names are supported - // builder.AppendLine(header.Compressors, $"Compressors"); string compressorsLine = "Compressors: "; if (header.Compressors == null) { @@ -136,7 +134,7 @@ namespace SabreTools.Serialization.Printers var compressors = new List(); for (int i = 0; i < header.Compressors.Length; i++) { - uint compressor = header.Compressors[i]; + uint compressor = (uint)header.Compressors[i]; byte[] compressorBytes = BitConverter.GetBytes(compressor); Array.Reverse(compressorBytes); string compressorString = Encoding.ASCII.GetString(compressorBytes); diff --git a/SabreTools.Serialization/SabreTools.Serialization.csproj b/SabreTools.Serialization/SabreTools.Serialization.csproj index 7bfac6be..be96be24 100644 --- a/SabreTools.Serialization/SabreTools.Serialization.csproj +++ b/SabreTools.Serialization/SabreTools.Serialization.csproj @@ -1,58 +1,58 @@ - - - net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - true - false - false - latest - enable - true - true - 1.6.9 + + + net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + true + false + false + latest + enable + true + true + 1.6.9 - - Matt Nadareski - Serialization and deserialization helpers for various types - Copyright (c) Matt Nadareski 2019-2024 - https://github.com/SabreTools/ - README.md - https://github.com/SabreTools/SabreTools.Serialization - git - serialize serialization deserialize deserialization file stream - MIT - + + Matt Nadareski + Serialization and deserialization helpers for various types + Copyright (c) Matt Nadareski 2019-2024 + https://github.com/SabreTools/ + README.md + https://github.com/SabreTools/SabreTools.Serialization + git + serialize serialization deserialize deserialization file stream + MIT + - - - win-x86;win-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 - - - win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 - - - net6.0;net7.0;net8.0 - + + + win-x86;win-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64 + + + win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 + + + net6.0;net7.0;net8.0;net9.0 + - - - + + + - - - - + + + + - - - - - - - + + + + + + + - + \ No newline at end of file diff --git a/SabreTools.Serialization/Serializers/AttractMode.cs b/SabreTools.Serialization/Serializers/AttractMode.cs index 3fd8833f..7f42cb18 100644 --- a/SabreTools.Serialization/Serializers/AttractMode.cs +++ b/SabreTools.Serialization/Serializers/AttractMode.cs @@ -83,7 +83,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/BaseBinarySerializer.cs b/SabreTools.Serialization/Serializers/BaseBinarySerializer.cs index 841eb2cc..d78b8dc2 100644 --- a/SabreTools.Serialization/Serializers/BaseBinarySerializer.cs +++ b/SabreTools.Serialization/Serializers/BaseBinarySerializer.cs @@ -26,7 +26,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/ClrMamePro.cs b/SabreTools.Serialization/Serializers/ClrMamePro.cs index 8281893a..72c7e4f9 100644 --- a/SabreTools.Serialization/Serializers/ClrMamePro.cs +++ b/SabreTools.Serialization/Serializers/ClrMamePro.cs @@ -28,7 +28,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/Hashfile.cs b/SabreTools.Serialization/Serializers/Hashfile.cs index e20c65e3..2bcfd693 100644 --- a/SabreTools.Serialization/Serializers/Hashfile.cs +++ b/SabreTools.Serialization/Serializers/Hashfile.cs @@ -31,7 +31,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/JsonFile.cs b/SabreTools.Serialization/Serializers/JsonFile.cs index 8b41f716..a69fa1a8 100644 --- a/SabreTools.Serialization/Serializers/JsonFile.cs +++ b/SabreTools.Serialization/Serializers/JsonFile.cs @@ -30,7 +30,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/SeparatedValue.cs b/SabreTools.Serialization/Serializers/SeparatedValue.cs index eac4edb7..ccbac25d 100644 --- a/SabreTools.Serialization/Serializers/SeparatedValue.cs +++ b/SabreTools.Serialization/Serializers/SeparatedValue.cs @@ -29,7 +29,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Serializers/XmlFile.cs b/SabreTools.Serialization/Serializers/XmlFile.cs index a185c675..c24b0dd8 100644 --- a/SabreTools.Serialization/Serializers/XmlFile.cs +++ b/SabreTools.Serialization/Serializers/XmlFile.cs @@ -33,7 +33,7 @@ namespace SabreTools.Serialization.Serializers return null; byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, bytes.Length); + int read = stream.Read(bytes, 0, bytes.Length); return bytes; } diff --git a/SabreTools.Serialization/Wrappers/WrapperFactory.cs b/SabreTools.Serialization/Wrappers/WrapperFactory.cs index 1a891554..5ff9b358 100644 --- a/SabreTools.Serialization/Wrappers/WrapperFactory.cs +++ b/SabreTools.Serialization/Wrappers/WrapperFactory.cs @@ -3,6 +3,7 @@ using System.IO; using SabreTools.IO.Extensions; using SabreTools.Matching; using SabreTools.Serialization.Interfaces; +using static SabreTools.Matching.Extensions; namespace SabreTools.Serialization.Wrappers { @@ -13,51 +14,51 @@ namespace SabreTools.Serialization.Wrappers /// public static IWrapper? CreateWrapper(WrapperType fileType, Stream? data) { - switch (fileType) + return fileType switch { - case WrapperType.AACSMediaKeyBlock: return AACSMediaKeyBlock.Create(data); - case WrapperType.BDPlusSVM: return BDPlusSVM.Create(data); - case WrapperType.BFPK: return BFPK.Create(data); - case WrapperType.BSP: return BSP.Create(data); - case WrapperType.BZip2: return null; // TODO: Implement wrapper - case WrapperType.CFB: return CFB.Create(data); - case WrapperType.CHD: return CHD.Create(data); - case WrapperType.CIA: return CIA.Create(data); - case WrapperType.Executable: return CreateExecutableWrapper(data); - case WrapperType.GCF: return GCF.Create(data); - case WrapperType.GZIP: return null; // TODO: Implement wrapper - case WrapperType.IniFile: return null; // TODO: Implement wrapper - case WrapperType.InstallShieldArchiveV3: return null; // TODO: Implement wrapper - case WrapperType.InstallShieldCAB: return InstallShieldCabinet.Create(data); - case WrapperType.LDSCRYPT: return null; // TODO: Implement wrapper - case WrapperType.MicrosoftCAB: return MicrosoftCabinet.Create(data); - case WrapperType.MicrosoftLZ: return null; // TODO: Implement wrapper - case WrapperType.MoPaQ: return MoPaQ.Create(data); - case WrapperType.N3DS: return N3DS.Create(data); - case WrapperType.NCF: return NCF.Create(data); - case WrapperType.Nitro: return Nitro.Create(data); - case WrapperType.PAK: return PAK.Create(data); - case WrapperType.PFF: return PFF.Create(data); - case WrapperType.PIC: return PIC.Create(data); - case WrapperType.PKZIP: return PKZIP.Create(data); - case WrapperType.PlayJAudioFile: return PlayJAudioFile.Create(data); - case WrapperType.PlayJPlaylist: return PlayJPlaylist.Create(data); - case WrapperType.Quantum: return Quantum.Create(data); - case WrapperType.RAR: return null; // TODO: Implement wrapper - case WrapperType.RealArcadeInstaller: return null; // TODO: Implement wrapper - case WrapperType.RealArcadeMezzanine: return null; // TODO: Implement wrapper - case WrapperType.SevenZip: return null; // TODO: Implement wrapper - case WrapperType.SFFS: return null; // TODO: Implement wrapper - case WrapperType.SGA: return SGA.Create(data); - case WrapperType.TapeArchive: return null; // TODO: Implement wrapper - case WrapperType.Textfile: return null; // TODO: Implement wrapper - case WrapperType.VBSP: return VBSP.Create(data); - case WrapperType.VPK: return VPK.Create(data); - case WrapperType.WAD: return WAD.Create(data); - case WrapperType.XZ: return null; // TODO: Implement wrapper - case WrapperType.XZP: return XZP.Create(data); - default: return null; - } + WrapperType.AACSMediaKeyBlock => AACSMediaKeyBlock.Create(data), + WrapperType.BDPlusSVM => BDPlusSVM.Create(data), + WrapperType.BFPK => BFPK.Create(data), + WrapperType.BSP => BSP.Create(data), + WrapperType.BZip2 => null,// TODO: Implement wrapper + WrapperType.CFB => CFB.Create(data), + WrapperType.CHD => CHD.Create(data), + WrapperType.CIA => CIA.Create(data), + WrapperType.Executable => CreateExecutableWrapper(data), + WrapperType.GCF => GCF.Create(data), + WrapperType.GZIP => null,// TODO: Implement wrapper + WrapperType.IniFile => null,// TODO: Implement wrapper + WrapperType.InstallShieldArchiveV3 => null,// TODO: Implement wrapper + WrapperType.InstallShieldCAB => InstallShieldCabinet.Create(data), + WrapperType.LDSCRYPT => null,// TODO: Implement wrapper + WrapperType.MicrosoftCAB => MicrosoftCabinet.Create(data), + WrapperType.MicrosoftLZ => null,// TODO: Implement wrapper + WrapperType.MoPaQ => MoPaQ.Create(data), + WrapperType.N3DS => N3DS.Create(data), + WrapperType.NCF => NCF.Create(data), + WrapperType.Nitro => Nitro.Create(data), + WrapperType.PAK => PAK.Create(data), + WrapperType.PFF => PFF.Create(data), + WrapperType.PIC => PIC.Create(data), + WrapperType.PKZIP => PKZIP.Create(data), + WrapperType.PlayJAudioFile => PlayJAudioFile.Create(data), + WrapperType.PlayJPlaylist => PlayJPlaylist.Create(data), + WrapperType.Quantum => Quantum.Create(data), + WrapperType.RAR => null,// TODO: Implement wrapper + WrapperType.RealArcadeInstaller => null,// TODO: Implement wrapper + WrapperType.RealArcadeMezzanine => null,// TODO: Implement wrapper + WrapperType.SevenZip => null,// TODO: Implement wrapper + WrapperType.SFFS => null,// TODO: Implement wrapper + WrapperType.SGA => SGA.Create(data), + WrapperType.TapeArchive => null,// TODO: Implement wrapper + WrapperType.Textfile => null,// TODO: Implement wrapper + WrapperType.VBSP => VBSP.Create(data), + WrapperType.VPK => VPK.Create(data), + WrapperType.WAD => WAD.Create(data), + WrapperType.XZ => null,// TODO: Implement wrapper + WrapperType.XZP => XZP.Create(data), + _ => null, + }; } /// @@ -91,22 +92,35 @@ namespace SabreTools.Serialization.Wrappers } // New Executable +#if NET20 + else if (Matching.Extensions.StartsWith(magic, Models.NewExecutable.Constants.SignatureBytes)) +#else else if (magic.StartsWith(Models.NewExecutable.Constants.SignatureBytes)) +#endif { stream.Seek(0, SeekOrigin.Begin); return NewExecutable.Create(stream); } // Linear Executable +#if NET20 + else if (Matching.Extensions.StartsWith(magic, Models.LinearExecutable.Constants.LESignatureBytes) + || Matching.Extensions.StartsWith(magic, Models.LinearExecutable.Constants.LXSignatureBytes)) +#else else if (magic.StartsWith(Models.LinearExecutable.Constants.LESignatureBytes) || magic.StartsWith(Models.LinearExecutable.Constants.LXSignatureBytes)) +#endif { stream.Seek(0, SeekOrigin.Begin); return LinearExecutable.Create(stream); } // Portable Executable +#if NET20 + else if (Matching.Extensions.StartsWith(magic, Models.PortableExecutable.Constants.SignatureBytes)) +#else else if (magic.StartsWith(Models.PortableExecutable.Constants.SignatureBytes)) +#endif { stream.Seek(0, SeekOrigin.Begin); return PortableExecutable.Create(stream); @@ -133,11 +147,19 @@ namespace SabreTools.Serialization.Wrappers #region AACSMediaKeyBlock // Block starting with verify media key record +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x81, 0x00, 0x00, 0x14 })) +#else if (magic.StartsWith(new byte?[] { 0x81, 0x00, 0x00, 0x14 })) +#endif return WrapperType.AACSMediaKeyBlock; // Block starting with type and version record +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x10, 0x00, 0x00, 0x0C })) +#else if (magic.StartsWith(new byte?[] { 0x10, 0x00, 0x00, 0x0C })) +#endif return WrapperType.AACSMediaKeyBlock; // Shares an extension with INF setup information so it can't be used accurately @@ -153,7 +175,11 @@ namespace SabreTools.Serialization.Wrappers #region BDPlusSVM +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x42, 0x44, 0x53, 0x56, 0x4D, 0x5F, 0x43, 0x43 })) +#else if (magic.StartsWith(new byte?[] { 0x42, 0x44, 0x53, 0x56, 0x4D, 0x5F, 0x43, 0x43 })) +#endif return WrapperType.BDPlusSVM; if (extension.Equals("svm", StringComparison.OrdinalIgnoreCase)) @@ -163,7 +189,11 @@ namespace SabreTools.Serialization.Wrappers #region BFPK +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x42, 0x46, 0x50, 0x4b })) +#else if (magic.StartsWith(new byte?[] { 0x42, 0x46, 0x50, 0x4b })) +#endif return WrapperType.BFPK; #endregion @@ -172,19 +202,31 @@ namespace SabreTools.Serialization.Wrappers // Shares a first 4 bytes with some .mc files // Shares an extension with VBSP +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x1d, 0x00, 0x00, 0x00 }) && extension.Equals("bsp", StringComparison.OrdinalIgnoreCase)) +#else if (magic.StartsWith(new byte?[] { 0x1d, 0x00, 0x00, 0x00 }) && extension.Equals("bsp", StringComparison.OrdinalIgnoreCase)) +#endif return WrapperType.BSP; // Shares a first 4 bytes with some .mc files // Shares an extension with VBSP +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x1e, 0x00, 0x00, 0x00 }) && extension.Equals("bsp", StringComparison.OrdinalIgnoreCase)) +#else if (magic.StartsWith(new byte?[] { 0x1e, 0x00, 0x00, 0x00 }) && extension.Equals("bsp", StringComparison.OrdinalIgnoreCase)) +#endif return WrapperType.BSP; #endregion #region BZip2 +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x42, 0x52, 0x68 })) +#else if (magic.StartsWith(new byte?[] { 0x42, 0x52, 0x68 })) +#endif return WrapperType.BZip2; if (extension.Equals("bz2", StringComparison.OrdinalIgnoreCase)) @@ -194,7 +236,11 @@ namespace SabreTools.Serialization.Wrappers #region CFB +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })) +#else if (magic.StartsWith(new byte?[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 })) +#endif return WrapperType.CFB; // Installer package @@ -221,7 +267,11 @@ namespace SabreTools.Serialization.Wrappers #region CHD +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4D, 0x43, 0x6F, 0x6D, 0x70, 0x72, 0x48, 0x44 })) +#else if (magic.StartsWith(new byte?[] { 0x4D, 0x43, 0x6F, 0x6D, 0x70, 0x72, 0x48, 0x44 })) +#endif return WrapperType.CHD; #endregion @@ -236,34 +286,62 @@ namespace SabreTools.Serialization.Wrappers #region Executable // DOS MZ executable file format (and descendants) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4d, 0x5a })) +#else if (magic.StartsWith(new byte?[] { 0x4d, 0x5a })) +#endif return WrapperType.Executable; /* // None of the following are supported yet // Executable and Linkable Format +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x7f, 0x45, 0x4c, 0x46 })) +#else if (magic.StartsWith(new byte?[] { 0x7f, 0x45, 0x4c, 0x46 })) +#endif return FileTypes.Executable; // Mach-O binary (32-bit) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xfe, 0xed, 0xfa, 0xce })) +#else if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xce })) +#endif return FileTypes.Executable; // Mach-O binary (32-bit, reverse byte ordering scheme) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xce, 0xfa, 0xed, 0xfe })) +#else if (magic.StartsWith(new byte?[] { 0xce, 0xfa, 0xed, 0xfe })) +#endif return FileTypes.Executable; // Mach-O binary (64-bit) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xfe, 0xed, 0xfa, 0xcf })) +#else if (magic.StartsWith(new byte?[] { 0xfe, 0xed, 0xfa, 0xcf })) +#endif return FileTypes.Executable; // Mach-O binary (64-bit, reverse byte ordering scheme) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xcf, 0xfa, 0xed, 0xfe })) +#else if (magic.StartsWith(new byte?[] { 0xcf, 0xfa, 0xed, 0xfe })) +#endif return FileTypes.Executable; // Prefrred Executable File Format +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 })) +#else if (magic.StartsWith(new byte?[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 })) +#endif return FileTypes.Executable; */ @@ -279,7 +357,11 @@ namespace SabreTools.Serialization.Wrappers #region GCF +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 })) +#endif return WrapperType.GCF; if (extension.Equals("gcf", StringComparison.OrdinalIgnoreCase)) @@ -289,7 +371,11 @@ namespace SabreTools.Serialization.Wrappers #region GZIP +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x1f, 0x8b })) +#else if (magic.StartsWith(new byte?[] { 0x1f, 0x8b })) +#endif return WrapperType.GZIP; if (extension.Equals("gz", StringComparison.OrdinalIgnoreCase)) @@ -306,7 +392,11 @@ namespace SabreTools.Serialization.Wrappers #region InstallShieldArchiveV3 +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x13, 0x5D, 0x65, 0x8C })) +#else if (magic.StartsWith(new byte?[] { 0x13, 0x5D, 0x65, 0x8C })) +#endif return WrapperType.InstallShieldArchiveV3; if (extension.Equals("z", StringComparison.OrdinalIgnoreCase)) @@ -316,7 +406,11 @@ namespace SabreTools.Serialization.Wrappers #region InstallShieldCAB +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x49, 0x53, 0x63 })) +#else if (magic.StartsWith(new byte?[] { 0x49, 0x53, 0x63 })) +#endif return WrapperType.InstallShieldCAB; // Both InstallShieldCAB and MicrosoftCAB share the same extension @@ -325,14 +419,22 @@ namespace SabreTools.Serialization.Wrappers #region LDSCRYPT +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4C, 0x44, 0x53, 0x43, 0x52, 0x59, 0x50, 0x54 })) +#else if (magic.StartsWith(new byte?[] { 0x4C, 0x44, 0x53, 0x43, 0x52, 0x59, 0x50, 0x54 })) +#endif return WrapperType.LDSCRYPT; #endregion #region MicrosoftCAB +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4d, 0x53, 0x43, 0x46 })) +#else if (magic.StartsWith(new byte?[] { 0x4d, 0x53, 0x43, 0x46 })) +#endif return WrapperType.MicrosoftCAB; // Both InstallShieldCAB and MicrosoftCAB share the same extension @@ -341,17 +443,29 @@ namespace SabreTools.Serialization.Wrappers #region MicrosoftLZ +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 })) +#else if (magic.StartsWith(new byte?[] { 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33 })) +#endif return WrapperType.MicrosoftLZ; #endregion #region MoPaQ +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4d, 0x50, 0x51, 0x1a })) +#else if (magic.StartsWith(new byte?[] { 0x4d, 0x50, 0x51, 0x1a })) +#endif return WrapperType.MoPaQ; +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x4d, 0x50, 0x51, 0x1b })) +#else if (magic.StartsWith(new byte?[] { 0x4d, 0x50, 0x51, 0x1b })) +#endif return WrapperType.MoPaQ; if (extension.Equals("mpq", StringComparison.OrdinalIgnoreCase)) @@ -373,7 +487,11 @@ namespace SabreTools.Serialization.Wrappers #region NCF +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 })) +#endif return WrapperType.NCF; if (extension.Equals("ncf", StringComparison.OrdinalIgnoreCase)) @@ -403,7 +521,11 @@ namespace SabreTools.Serialization.Wrappers #region PAK +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x50, 0x41, 0x43, 0x4B })) +#else if (magic.StartsWith(new byte?[] { 0x50, 0x41, 0x43, 0x4B })) +#endif return WrapperType.PAK; // Both PAK and Quantum share one extension @@ -415,15 +537,27 @@ namespace SabreTools.Serialization.Wrappers #region PFF // Version 2 +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x32 })) +#else if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x32 })) +#endif return WrapperType.PFF; // Version 3 +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x33 })) +#else if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x33 })) +#endif return WrapperType.PFF; // Version 4 +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x34 })) +#else if (magic.StartsWith(new byte?[] { 0x14, 0x00, 0x00, 0x00, 0x50, 0x46, 0x46, 0x34 })) +#endif return WrapperType.PFF; if (extension.Equals("pff", StringComparison.OrdinalIgnoreCase)) @@ -434,19 +568,35 @@ namespace SabreTools.Serialization.Wrappers #region PKZIP // PKZIP (Unknown) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x50, 0x4b, 0x00, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x00, 0x00 })) +#endif return WrapperType.PKZIP; // PKZIP +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x50, 0x4b, 0x03, 0x04 })) +#else if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x03, 0x04 })) +#endif return WrapperType.PKZIP; // PKZIP (Empty Archive) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x50, 0x4b, 0x05, 0x06 })) +#else if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x05, 0x06 })) +#endif return WrapperType.PKZIP; // PKZIP (Spanned Archive) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x50, 0x4b, 0x07, 0x08 })) +#else if (magic.StartsWith(new byte?[] { 0x50, 0x4b, 0x07, 0x08 })) +#endif return WrapperType.PKZIP; // PKZIP @@ -538,7 +688,11 @@ namespace SabreTools.Serialization.Wrappers #region PLJ // https://www.iana.org/assignments/media-types/audio/vnd.everad.plj +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xFF, 0x9D, 0x53, 0x4B })) +#else if (magic.StartsWith(new byte?[] { 0xFF, 0x9D, 0x53, 0x4B })) +#endif return WrapperType.PlayJAudioFile; // https://www.iana.org/assignments/media-types/audio/vnd.everad.plj @@ -549,7 +703,11 @@ namespace SabreTools.Serialization.Wrappers #region Quantum +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x44, 0x53 })) +#else if (magic.StartsWith(new byte?[] { 0x44, 0x53 })) +#endif return WrapperType.Quantum; if (extension.Equals("q", StringComparison.OrdinalIgnoreCase)) @@ -564,11 +722,19 @@ namespace SabreTools.Serialization.Wrappers #region RAR // RAR archive version 1.50 onwards +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 })) +#endif return WrapperType.RAR; // RAR archive version 5.0 onwards +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00 })) +#endif return WrapperType.RAR; if (extension.Equals("rar", StringComparison.OrdinalIgnoreCase)) @@ -580,19 +746,31 @@ namespace SabreTools.Serialization.Wrappers // RASGI2.0 // Found in the ".rgs files in IA item "Nova_RealArcadeCD_USA". +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x52, 0x41, 0x53, 0x47, 0x49, 0x32, 0x2E, 0x30 })) +#else if (magic.StartsWith(new byte?[] { 0x52, 0x41, 0x53, 0x47, 0x49, 0x32, 0x2E, 0x30 })) +#endif return WrapperType.RealArcadeInstaller; // XZip2.0 // Found in the ".mez" files in IA item "Nova_RealArcadeCD_USA". +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x58, 0x5A, 0x69, 0x70, 0x32, 0x2E, 0x30 })) +#else if (magic.StartsWith(new byte?[] { 0x58, 0x5A, 0x69, 0x70, 0x32, 0x2E, 0x30 })) +#endif return WrapperType.RealArcadeMezzanine; #endregion #region SevenZip +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c })) +#else if (magic.StartsWith(new byte?[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c })) +#endif return WrapperType.SevenZip; if (extension.Equals("7z", StringComparison.OrdinalIgnoreCase)) @@ -603,14 +781,22 @@ namespace SabreTools.Serialization.Wrappers #region SFFS // Found in Redump entry 81756, confirmed to be "StarForce Filesystem" by PiD. +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x53, 0x46, 0x46, 0x53 })) +#else if (magic.StartsWith(new byte?[] { 0x53, 0x46, 0x46, 0x53 })) +#endif return WrapperType.SFFS; #endregion #region SGA +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x5F, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45 })) +#else if (magic.StartsWith(new byte?[] { 0x5F, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45 })) +#endif return WrapperType.SGA; if (extension.Equals("sga", StringComparison.OrdinalIgnoreCase)) @@ -620,10 +806,18 @@ namespace SabreTools.Serialization.Wrappers #region TapeArchive +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30 })) +#else if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30 })) +#endif return WrapperType.TapeArchive; +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00 })) +#endif return WrapperType.TapeArchive; if (extension.Equals("tar", StringComparison.OrdinalIgnoreCase)) @@ -636,32 +830,60 @@ namespace SabreTools.Serialization.Wrappers // Not all textfiles can be determined through magic number // HTML +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c })) +#else if (magic.StartsWith(new byte?[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c })) +#endif return WrapperType.Textfile; // HTML and XML +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 })) +#else if (magic.StartsWith(new byte?[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 })) +#endif return WrapperType.Textfile; // InstallShield Compiled Rules +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x61, 0x4C, 0x75, 0x5A })) +#else if (magic.StartsWith(new byte?[] { 0x61, 0x4C, 0x75, 0x5A })) +#endif return WrapperType.Textfile; // Microsoft Office File (old) +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 })) +#else if (magic.StartsWith(new byte?[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 })) +#endif return WrapperType.Textfile; // Rich Text File +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 })) +#else if (magic.StartsWith(new byte?[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 })) +#endif return WrapperType.Textfile; // Windows Help File +#if NET20 + if (Matching.Extensions.StartsWith(magic, new byte?[] { 0x3F, 0x5F, 0x03, 0x00 })) +#else if (magic.StartsWith(new byte?[] { 0x3F, 0x5F, 0x03, 0x00 })) +#endif return WrapperType.Textfile; // XML // "