Add .NET 9 to target frameworks

This commit is contained in:
Matt Nadareski
2024-11-13 03:55:33 -05:00
parent a4da7f3657
commit 0125bd6619
27 changed files with 256 additions and 375 deletions

View File

@@ -24,7 +24,7 @@ What version are you using?
**Build**
What runtime version are you using?
- [ ] .NET 8.0 running on (Operating System)
- [ ] .NET 9.0 running on (Operating System)
**Describe the issue**
A clear and concise description of what the bug is.

View File

@@ -12,7 +12,7 @@ jobs:
matrix:
project: [SabreTools] #[RombaSharp, SabreTools]
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:
@@ -21,13 +21,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: |

View File

@@ -11,7 +11,7 @@ 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

2
.vscode/launch.json vendored
View File

@@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/SabreTools/bin/Debug/net8.0/SabreTools.dll",
"program": "${workspaceFolder}/SabreTools/bin/Debug/net9.0/SabreTools.dll",
"args": [],
"cwd": "${workspaceFolder}/SabreTools",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
@@ -11,6 +11,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -28,11 +29,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -44,7 +45,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.10" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
</ItemGroup>
</Project>

View File

@@ -510,10 +510,10 @@ namespace SabreTools.Core
private static bool HasZeroHash(this Disk disk)
{
string? md5 = disk.ReadString(Disk.MD5Key);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, Constants.MD5Zero, StringComparison.OrdinalIgnoreCase);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, ZeroHash.MD5Str, StringComparison.OrdinalIgnoreCase);
string? sha1 = disk.ReadString(Disk.SHA1Key);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, Constants.SHA1Zero, StringComparison.OrdinalIgnoreCase);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, ZeroHash.SHA1Str, StringComparison.OrdinalIgnoreCase);
return md5Null && sha1Null;
}
@@ -524,16 +524,16 @@ namespace SabreTools.Core
private static bool HasZeroHash(this Media media)
{
string? md5 = media.ReadString(Media.MD5Key);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, Constants.MD5Zero, StringComparison.OrdinalIgnoreCase);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, ZeroHash.MD5Str, StringComparison.OrdinalIgnoreCase);
string? sha1 = media.ReadString(Media.SHA1Key);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, Constants.SHA1Zero, StringComparison.OrdinalIgnoreCase);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, ZeroHash.SHA1Str, StringComparison.OrdinalIgnoreCase);
string? sha256 = media.ReadString(Media.SHA256Key);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, Constants.SHA256Zero, StringComparison.OrdinalIgnoreCase);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, ZeroHash.SHA256Str, StringComparison.OrdinalIgnoreCase);
string? spamsum = media.ReadString(Media.SpamSumKey);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, Constants.SpamSumZero, StringComparison.OrdinalIgnoreCase);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, ZeroHash.SpamSumStr, StringComparison.OrdinalIgnoreCase);
return md5Null && sha1Null && sha256Null && spamsumNull;
}
@@ -544,25 +544,25 @@ namespace SabreTools.Core
private static bool HasZeroHash(this Rom rom)
{
string? crc = rom.ReadString(Rom.CRCKey);
bool crcNull = string.IsNullOrEmpty(crc) || string.Equals(crc, Constants.CRCZero, StringComparison.OrdinalIgnoreCase);
bool crcNull = string.IsNullOrEmpty(crc) || string.Equals(crc, ZeroHash.CRC32Str, StringComparison.OrdinalIgnoreCase);
string? md5 = rom.ReadString(Rom.MD5Key);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, Constants.MD5Zero, StringComparison.OrdinalIgnoreCase);
bool md5Null = string.IsNullOrEmpty(md5) || string.Equals(md5, ZeroHash.MD5Str, StringComparison.OrdinalIgnoreCase);
string? sha1 = rom.ReadString(Rom.SHA1Key);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, Constants.SHA1Zero, StringComparison.OrdinalIgnoreCase);
bool sha1Null = string.IsNullOrEmpty(sha1) || string.Equals(sha1, ZeroHash.SHA1Str, StringComparison.OrdinalIgnoreCase);
string? sha256 = rom.ReadString(Rom.SHA256Key);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, Constants.SHA256Zero, StringComparison.OrdinalIgnoreCase);
bool sha256Null = string.IsNullOrEmpty(sha256) || string.Equals(sha256, ZeroHash.SHA256Str, StringComparison.OrdinalIgnoreCase);
string? sha384 = rom.ReadString(Rom.SHA384Key);
bool sha384Null = string.IsNullOrEmpty(sha384) || string.Equals(sha384, Constants.SHA384Zero, StringComparison.OrdinalIgnoreCase);
bool sha384Null = string.IsNullOrEmpty(sha384) || string.Equals(sha384, ZeroHash.SHA384Str, StringComparison.OrdinalIgnoreCase);
string? sha512 = rom.ReadString(Rom.SHA512Key);
bool sha512Null = string.IsNullOrEmpty(sha512) || string.Equals(sha512, Constants.SHA512Zero, StringComparison.OrdinalIgnoreCase);
bool sha512Null = string.IsNullOrEmpty(sha512) || string.Equals(sha512, ZeroHash.SHA512Str, StringComparison.OrdinalIgnoreCase);
string? spamsum = rom.ReadString(Rom.SpamSumKey);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, Constants.SpamSumZero, StringComparison.OrdinalIgnoreCase);
bool spamsumNull = string.IsNullOrEmpty(spamsum) || string.Equals(spamsum, ZeroHash.SpamSumStr, StringComparison.OrdinalIgnoreCase);
return crcNull && md5Null && sha1Null && sha256Null && sha384Null && sha512Null && spamsumNull;
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -26,11 +26,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -54,10 +54,10 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.2.3" />
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.Matching" Version="1.3.2" />
<PackageReference Include="SabreTools.Models" Version="1.4.10" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
<PackageReference Include="SabreTools.Matching" Version="1.4.0" />
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -18,7 +18,11 @@ namespace SabreTools.Core.Tools
public static bool ConditionalHashEquals(byte[]? firstHash, byte[]? secondHash)
{
// If either hash is empty, we say they're equal for merging
#if NET20
if (Matching.Extensions.IsNullOrEmpty(firstHash) || Matching.Extensions.IsNullOrEmpty(secondHash))
#else
if (firstHash.IsNullOrEmpty() || secondHash.IsNullOrEmpty())
#endif
return true;
// If they're different sizes, they can't match
@@ -77,8 +81,8 @@ namespace SabreTools.Core.Tools
// Cap the depth between 0 and 20, for now
if (depth < 0)
depth = 0;
else if (depth > Constants.SHA1Zero.Length)
depth = Constants.SHA1Zero.Length;
else if (depth > ZeroHash.SHA1Str.Length)
depth = ZeroHash.SHA1Str.Length;
// Loop through and generate the subdirectory
string path = string.Empty;

View File

@@ -662,19 +662,19 @@ namespace SabreTools.DatFiles
rom.SetName(rom.GetName() == "null" ? "-" : rom.GetName());
rom.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, Constants.SizeZero.ToString());
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey,
rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) == "null" ? Constants.CRCZero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) == "null" ? ZeroHash.CRC32Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key,
rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) == "null" ? Constants.MD5Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) == "null" ? ZeroHash.MD5Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) == "null" ? Constants.SHA1Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) == "null" ? ZeroHash.SHA1Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) == "null" ? Constants.SHA256Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) == "null" ? ZeroHash.SHA256Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) == "null" ? Constants.SHA384Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) == "null" ? ZeroHash.SHA384Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) == "null" ? Constants.SHA512Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) == "null" ? ZeroHash.SHA512Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey,
rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) == "null" ? Constants.SpamSumZero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) == "null" ? ZeroHash.SpamSumStr : null);
}
return rom;
@@ -706,19 +706,19 @@ namespace SabreTools.DatFiles
rom.SetName(rom.GetName() == "null" ? "-" : rom.GetName());
rom.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, Constants.SizeZero.ToString());
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey,
rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) == "null" ? Constants.CRCZero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) == "null" ? ZeroHash.CRC32Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key,
rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) == "null" ? Constants.MD5Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) == "null" ? ZeroHash.MD5Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) == "null" ? Constants.SHA1Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) == "null" ? ZeroHash.SHA1Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) == "null" ? Constants.SHA256Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) == "null" ? ZeroHash.SHA256Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) == "null" ? Constants.SHA384Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) == "null" ? ZeroHash.SHA384Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key,
rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) == "null" ? Constants.SHA512Zero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) == "null" ? ZeroHash.SHA512Str : null);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey,
rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) == "null" ? Constants.SpamSumZero : null);
rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) == "null" ? ZeroHash.SpamSumStr : null);
}
return (item.Item1, rom);

View File

@@ -50,8 +50,8 @@ namespace SabreTools.DatFiles
Depth = 4;
else if (Depth < 0)
Depth = 0;
else if (Depth > Constants.SHA1Zero.Length)
Depth = Constants.SHA1Zero.Length;
else if (Depth > ZeroHash.SHA1Str.Length)
Depth = ZeroHash.SHA1Str.Length;
}
#region Cloning

View File

@@ -231,13 +231,13 @@ namespace SabreTools.DatFiles
&& (string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)) || rom.HasZeroHash()))
{
rom.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, Constants.SizeZero.ToString());
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, Constants.CRCZero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, Constants.MD5Zero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, Constants.SHA1Zero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, null); // Constants.SHA256Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, null); // Constants.SHA384Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, null); // Constants.SHA512Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, null); // Constants.SpamSumZero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, ZeroHash.CRC32Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, ZeroHash.MD5Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, ZeroHash.SHA1Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, null); // ZeroHash.SHA256Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, null); // ZeroHash.SHA384Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, null); // ZeroHash.SHA512Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, null); // ZeroHash.SpamSumStr;
}
// If the file has no size and it's not the above case, skip and log

View File

@@ -221,13 +221,13 @@ namespace SabreTools.DatFiles
&& (string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)) || rom.HasZeroHash()))
{
rom.SetFieldValue<string?>(Models.Metadata.Rom.SizeKey, Constants.SizeZero.ToString());
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, Constants.CRCZero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, Constants.MD5Zero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, Constants.SHA1Zero);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, null); // Constants.SHA256Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, null); // Constants.SHA384Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, null); // Constants.SHA512Zero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, null); // Constants.SpamSumZero;
rom.SetFieldValue<string?>(Models.Metadata.Rom.CRCKey, ZeroHash.CRC32Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.MD5Key, ZeroHash.MD5Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA1Key, ZeroHash.SHA1Str);
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA256Key, null); // ZeroHash.SHA256Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA384Key, null); // ZeroHash.SHA384Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SHA512Key, null); // ZeroHash.SHA512Str;
rom.SetFieldValue<string?>(Models.Metadata.Rom.SpamSumKey, null); // ZeroHash.SpamSumStr;
}
// If the file has no size and it's not the above case, skip and log
@@ -933,23 +933,23 @@ namespace SabreTools.DatFiles
{
Disk disk => bucketBy switch
{
ItemKey.CRC => Constants.CRCZero,
ItemKey.CRC => ZeroHash.CRC32Str,
ItemKey.MD5 => disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key) ?? string.Empty,
ItemKey.SHA1 => disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key) ?? string.Empty,
ItemKey.SHA256 => Constants.SHA256Zero,
ItemKey.SHA384 => Constants.SHA384Zero,
ItemKey.SHA512 => Constants.SHA512Zero,
ItemKey.SpamSum => Constants.SpamSumZero,
ItemKey.SHA256 => ZeroHash.SHA256Str,
ItemKey.SHA384 => ZeroHash.SHA384Str,
ItemKey.SHA512 => ZeroHash.SHA512Str,
ItemKey.SpamSum => ZeroHash.SpamSumStr,
_ => string.Empty,
},
Media media => bucketBy switch
{
ItemKey.CRC => Constants.CRCZero,
ItemKey.CRC => ZeroHash.CRC32Str,
ItemKey.MD5 => media.GetStringFieldValue(Models.Metadata.Media.MD5Key) ?? string.Empty,
ItemKey.SHA1 => media.GetStringFieldValue(Models.Metadata.Media.SHA1Key) ?? string.Empty,
ItemKey.SHA256 => media.GetStringFieldValue(Models.Metadata.Media.SHA256Key) ?? string.Empty,
ItemKey.SHA384 => Constants.SHA384Zero,
ItemKey.SHA512 => Constants.SHA512Zero,
ItemKey.SHA384 => ZeroHash.SHA384Str,
ItemKey.SHA512 => ZeroHash.SHA512Str,
ItemKey.SpamSum => media.GetStringFieldValue(Models.Metadata.Media.SpamSumKey) ?? string.Empty,
_ => string.Empty,
},
@@ -966,13 +966,13 @@ namespace SabreTools.DatFiles
},
_ => bucketBy switch
{
ItemKey.CRC => Constants.CRCZero,
ItemKey.MD5 => Constants.MD5Zero,
ItemKey.SHA1 => Constants.SHA1Zero,
ItemKey.SHA256 => Constants.SHA256Zero,
ItemKey.SHA384 => Constants.SHA384Zero,
ItemKey.SHA512 => Constants.SHA512Zero,
ItemKey.SpamSum => Constants.SpamSumZero,
ItemKey.CRC => ZeroHash.CRC32Str,
ItemKey.MD5 => ZeroHash.MD5Str,
ItemKey.SHA1 => ZeroHash.SHA1Str,
ItemKey.SHA256 => ZeroHash.SHA256Str,
ItemKey.SHA384 => ZeroHash.SHA384Str,
ItemKey.SHA512 => ZeroHash.SHA512Str,
ItemKey.SpamSum => ZeroHash.SpamSumStr,
_ => string.Empty,
},
};

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -10,6 +10,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -26,11 +27,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -40,11 +41,11 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.2.3" />
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.Matching" Version="1.3.2" />
<PackageReference Include="SabreTools.Models" Version="1.4.10" />
<PackageReference Include="SabreTools.Serialization" Version="1.6.8" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
<PackageReference Include="SabreTools.Matching" Version="1.4.0" />
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.7.0" />
</ItemGroup>
</Project>

View File

@@ -376,7 +376,7 @@ namespace SabreTools.DatItems
switch (bucketedBy)
{
case ItemKey.CRC:
key = Constants.CRCZero;
key = ZeroHash.CRC32Str;
break;
case ItemKey.Machine:
@@ -404,27 +404,27 @@ namespace SabreTools.DatItems
break;
case ItemKey.MD5:
key = Constants.MD5Zero;
key = ZeroHash.MD5Str;
break;
case ItemKey.SHA1:
key = Constants.SHA1Zero;
key = ZeroHash.SHA1Str;
break;
case ItemKey.SHA256:
key = Constants.SHA256Zero;
key = ZeroHash.SHA256Str;
break;
case ItemKey.SHA384:
key = Constants.SHA384Zero;
key = ZeroHash.SHA384Str;
break;
case ItemKey.SHA512:
key = Constants.SHA512Zero;
key = ZeroHash.SHA512Str;
break;
case ItemKey.SpamSum:
key = Constants.SpamSumZero;
key = ZeroHash.SpamSumStr;
break;
}
@@ -451,7 +451,7 @@ namespace SabreTools.DatItems
switch (bucketedBy)
{
case ItemKey.CRC:
key = Constants.CRCZero;
key = ZeroHash.CRC32Str;
break;
case ItemKey.Machine:
@@ -475,27 +475,27 @@ namespace SabreTools.DatItems
break;
case ItemKey.MD5:
key = Constants.MD5Zero;
key = ZeroHash.MD5Str;
break;
case ItemKey.SHA1:
key = Constants.SHA1Zero;
key = ZeroHash.SHA1Str;
break;
case ItemKey.SHA256:
key = Constants.SHA256Zero;
key = ZeroHash.SHA256Str;
break;
case ItemKey.SHA384:
key = Constants.SHA384Zero;
key = ZeroHash.SHA384Str;
break;
case ItemKey.SHA512:
key = Constants.SHA512Zero;
key = ZeroHash.SHA512Str;
break;
case ItemKey.SpamSum:
key = Constants.SpamSumZero;
key = ZeroHash.SpamSumStr;
break;
}

View File

@@ -54,8 +54,8 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("crc", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("crc")]
public string? CRC
{
get { return _crc.IsNullOrEmpty() ? null : ByteArrayExtensions.ByteArrayToString(_crc); }
set { _crc = (value == "null" ? Constants.CRCZeroBytes : ByteArrayExtensions.StringToByteArray(TextHelper.NormalizeCRC32(value))); }
get { return ByteArrayExtensions.ByteArrayToString(_crc); }
set { _crc = (value == "null" ? ZeroHash.CRC32Arr : ByteArrayExtensions.StringToByteArray(TextHelper.NormalizeCRC32(value))); }
}
/// <summary>
@@ -64,7 +64,7 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("md5", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("md5")]
public string? MD5
{
get { return _md5.IsNullOrEmpty() ? null : ByteArrayExtensions.ByteArrayToString(_md5); }
get { return ByteArrayExtensions.ByteArrayToString(_md5); }
set { _md5 = ByteArrayExtensions.StringToByteArray(TextHelper.NormalizeMD5(value)); }
}
@@ -74,7 +74,7 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("sha1", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha1")]
public string? SHA1
{
get { return _sha1.IsNullOrEmpty() ? null : ByteArrayExtensions.ByteArrayToString(_sha1); }
get { return ByteArrayExtensions.ByteArrayToString(_sha1); }
set { _sha1 = ByteArrayExtensions.StringToByteArray(TextHelper.NormalizeSHA1(value)); }
}
@@ -84,7 +84,7 @@ namespace SabreTools.DatItems.Formats
[JsonProperty("sha256", DefaultValueHandling = DefaultValueHandling.Ignore), XmlElement("sha256")]
public string? SHA256
{
get { return _sha256.IsNullOrEmpty() ? null : ByteArrayExtensions.ByteArrayToString(_sha256); }
get { return ByteArrayExtensions.ByteArrayToString(_sha256); }
set { _sha256 = ByteArrayExtensions.StringToByteArray(TextHelper.NormalizeSHA256(value)); }
}
@@ -228,6 +228,19 @@ namespace SabreTools.DatItems.Formats
if (Size == null && other.Size != null)
Size = other.Size;
#if NET20
if (Matching.Extensions.IsNullOrEmpty(_crc) && !Matching.Extensions.IsNullOrEmpty(other._crc))
_crc = other._crc;
if (Matching.Extensions.IsNullOrEmpty(_md5) && !Matching.Extensions.IsNullOrEmpty(other._md5))
_md5 = other._md5;
if (Matching.Extensions.IsNullOrEmpty(_sha1) && !Matching.Extensions.IsNullOrEmpty(other._sha1))
_sha1 = other._sha1;
if (Matching.Extensions.IsNullOrEmpty(_sha256) && !Matching.Extensions.IsNullOrEmpty(other._sha256))
_sha256 = other._sha256;
#else
if (_crc.IsNullOrEmpty() && !other._crc.IsNullOrEmpty())
_crc = other._crc;
@@ -239,6 +252,7 @@ namespace SabreTools.DatItems.Formats
if (_sha256.IsNullOrEmpty() && !other._sha256.IsNullOrEmpty())
_sha256 = other._sha256;
#endif
}
/// <summary>
@@ -247,6 +261,18 @@ namespace SabreTools.DatItems.Formats
/// <returns>String representing the suffix</returns>
public string GetDuplicateSuffix()
{
#if NET20
if (!Matching.Extensions.IsNullOrEmpty(_crc))
return $"_{CRC}";
else if (!Matching.Extensions.IsNullOrEmpty(_md5))
return $"_{MD5}";
else if (!Matching.Extensions.IsNullOrEmpty(_sha1))
return $"_{SHA1}";
else if (!Matching.Extensions.IsNullOrEmpty(_sha256))
return $"_{SHA256}";
else
return "_1";
#else
if (!_crc.IsNullOrEmpty())
return $"_{CRC}";
else if (!_md5.IsNullOrEmpty())
@@ -257,6 +283,7 @@ namespace SabreTools.DatItems.Formats
return $"_{SHA256}";
else
return "_1";
#endif
}
/// <summary>
@@ -265,10 +292,17 @@ namespace SabreTools.DatItems.Formats
/// <returns>True if any hash exists, false otherwise</returns>
public bool HasHashes()
{
#if NET20
return !Matching.Extensions.IsNullOrEmpty(_crc)
|| !Matching.Extensions.IsNullOrEmpty(_md5)
|| !Matching.Extensions.IsNullOrEmpty(_sha1)
|| !Matching.Extensions.IsNullOrEmpty(_sha256);
#else
return !_crc.IsNullOrEmpty()
|| !_md5.IsNullOrEmpty()
|| !_sha1.IsNullOrEmpty()
|| !_sha256.IsNullOrEmpty();
#endif
}
/// <summary>
@@ -277,10 +311,10 @@ namespace SabreTools.DatItems.Formats
/// <returns>True if any hash matches the 0-byte value, false otherwise</returns>
public bool HasZeroHash()
{
return (_crc != null && _crc.SequenceEqual(Constants.CRCZeroBytes))
|| (_md5 != null && _md5.SequenceEqual(Constants.MD5ZeroBytes))
|| (_sha1 != null && _sha1.SequenceEqual(Constants.SHA1ZeroBytes))
|| (_sha256 != null && _sha256.SequenceEqual(Constants.SHA256ZeroBytes));
return (_crc != null && _crc.SequenceEqual(ZeroHash.CRC32Arr))
|| (_md5 != null && _md5.SequenceEqual(ZeroHash.MD5Arr))
|| (_sha1 != null && _sha1.SequenceEqual(ZeroHash.SHA1Arr))
|| (_sha256 != null && _sha256.SequenceEqual(ZeroHash.SHA256Arr));
}
/// <summary>
@@ -290,10 +324,17 @@ namespace SabreTools.DatItems.Formats
/// <returns>True if at least one hash is not mutually exclusive, false otherwise</returns>
private bool HasCommonHash(File other)
{
#if NET20
return !(Matching.Extensions.IsNullOrEmpty(_crc) ^ Matching.Extensions.IsNullOrEmpty(other._crc))
|| !(Matching.Extensions.IsNullOrEmpty(_md5) ^ Matching.Extensions.IsNullOrEmpty(other._md5))
|| !(Matching.Extensions.IsNullOrEmpty(_sha1) ^ Matching.Extensions.IsNullOrEmpty(other._sha1))
|| !(Matching.Extensions.IsNullOrEmpty(_sha256) ^ Matching.Extensions.IsNullOrEmpty(other._sha256));
#else
return !(_crc.IsNullOrEmpty() ^ other._crc.IsNullOrEmpty())
|| !(_md5.IsNullOrEmpty() ^ other._md5.IsNullOrEmpty())
|| !(_sha1.IsNullOrEmpty() ^ other._sha1.IsNullOrEmpty())
|| !(_sha256.IsNullOrEmpty() ^ other._sha256.IsNullOrEmpty());
#endif
}
/// <summary>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -10,6 +10,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -26,11 +27,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -40,9 +41,9 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.Matching" Version="1.3.2" />
<PackageReference Include="SabreTools.Models" Version="1.4.10" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
<PackageReference Include="SabreTools.Matching" Version="1.4.0" />
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
</ItemGroup>
</Project>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -10,6 +10,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -26,11 +27,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -46,9 +47,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.Matching" Version="1.3.2" />
<PackageReference Include="SabreTools.Skippers" Version="1.1.3" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
<PackageReference Include="SabreTools.Matching" Version="1.4.0" />
<PackageReference Include="SabreTools.Skippers" Version="1.2.0" />
</ItemGroup>
</Project>

View File

@@ -97,7 +97,11 @@ namespace SabreTools.FileTypes.Aaru
return false;
// If the bytes don't match, we don't have an AaruFormat
#if NET20
if (!Matching.Extensions.StartsWith(magicBytes, AaruFormatSignature))
#else
if (!magicBytes.StartsWith(AaruFormatSignature))
#endif
return false;
return true;

View File

@@ -191,6 +191,44 @@ namespace SabreTools.FileTypes
#endif
// Now try to match it to a known signature
#if NET20
if (Matching.Extensions.StartsWith(magic, SevenZipSignature))
{
outFileType = FileType.SevenZipArchive;
}
else if (Matching.Extensions.StartsWith(magic, AaruFormatSignature))
{
outFileType = FileType.AaruFormat;
}
else if (Matching.Extensions.StartsWith(magic, CHDSignature))
{
outFileType = FileType.CHD;
}
else if (Matching.Extensions.StartsWith(magic, GzSignature))
{
outFileType = FileType.GZipArchive;
}
else if (Matching.Extensions.StartsWith(magic, RarSignature)
|| Matching.Extensions.StartsWith(magic, RarFiveSignature))
{
outFileType = FileType.RarArchive;
}
else if (Matching.Extensions.StartsWith(magic, TarSignature)
|| Matching.Extensions.StartsWith(magic, TarZeroSignature))
{
outFileType = FileType.TapeArchive;
}
else if (Matching.Extensions.StartsWith(magic, XZSignature))
{
outFileType = FileType.XZArchive;
}
else if (Matching.Extensions.StartsWith(magic, ZipSignature)
|| Matching.Extensions.StartsWith(magic, ZipSignatureEmpty)
|| Matching.Extensions.StartsWith(magic, ZipSignatureSpanned))
{
outFileType = FileType.ZipArchive;
}
#else
if (magic.StartsWith(SevenZipSignature))
{
outFileType = FileType.SevenZipArchive;
@@ -227,6 +265,7 @@ namespace SabreTools.FileTypes
{
outFileType = FileType.ZipArchive;
}
#endif
return outFileType;
}

View File

@@ -1,7 +1,4 @@
using System;
using System.IO;
using System.Text;
using SabreTools.IO.Extensions;
using System.IO;
using SabreTools.Models.CHD;
namespace SabreTools.FileTypes.CHD
@@ -41,17 +38,14 @@ namespace SabreTools.FileTypes.CHD
{
try
{
// Get the detected CHD version
uint version = GetVersion(stream);
// Read and return the current CHD
return version switch
var header = Serialization.Deserializers.CHD.DeserializeStream(stream);
return header switch
{
1 => DeserializeV1(stream),
2 => DeserializeV2(stream),
3 => DeserializeV3(stream),
4 => DeserializeV4(stream),
5 => DeserializeV5(stream),
HeaderV1 v1 => new CHDFile { _header = header, MD5 = v1.MD5 },
HeaderV2 v2 => new CHDFile { _header = header, MD5 = v2.MD5 },
HeaderV3 v3 => new CHDFile { _header = header, MD5 = v3.MD5, SHA1 = v3.SHA1 },
HeaderV4 v4 => new CHDFile { _header = header, SHA1 = v4.SHA1 },
HeaderV5 v5 => new CHDFile { _header = header, SHA1 = v5.SHA1 },
_ => null,
};
}
@@ -62,213 +56,5 @@ namespace SabreTools.FileTypes.CHD
}
#endregion
#region Deserializers
/// <summary>
/// Parse and validate the header as if it's V1
/// </summary>
private static CHDFile? DeserializeV1(Stream stream)
{
var header = new HeaderV1();
byte[] tagBytes = stream.ReadBytes(8);
header.Tag = Encoding.ASCII.GetString(tagBytes);
if (header.Tag != Constants.SignatureString)
return null;
header.Length = stream.ReadUInt32BigEndian();
if (header.Length != Constants.HeaderV1Size)
return null;
header.Version = stream.ReadUInt32BigEndian();
header.Flags = (Flags)stream.ReadUInt32BigEndian();
header.Compression = (CompressionType)stream.ReadUInt32BigEndian();
if (header.Compression > CompressionType.CHDCOMPRESSION_ZLIB)
return null;
header.HunkSize = stream.ReadUInt32BigEndian();
header.TotalHunks = stream.ReadUInt32BigEndian();
header.Cylinders = stream.ReadUInt32BigEndian();
header.Heads = stream.ReadUInt32BigEndian();
header.Sectors = stream.ReadUInt32BigEndian();
header.MD5 = stream.ReadBytes(16);
header.ParentMD5 = stream.ReadBytes(16);
return new CHDFile { _header = header, MD5 = header.MD5 };
}
/// <summary>
/// Parse and validate the header as if it's V2
/// </summary>
private static CHDFile? DeserializeV2(Stream stream)
{
var header = new HeaderV2();
byte[] tagBytes = stream.ReadBytes(8);
header.Tag = Encoding.ASCII.GetString(tagBytes);
if (header.Tag != Constants.SignatureString)
return null;
header.Length = stream.ReadUInt32BigEndian();
if (header.Length != Constants.HeaderV2Size)
return null;
header.Version = stream.ReadUInt32BigEndian();
header.Flags = (Flags)stream.ReadUInt32BigEndian();
header.Compression = (CompressionType)stream.ReadUInt32BigEndian();
if (header.Compression > CompressionType.CHDCOMPRESSION_ZLIB)
return null;
header.HunkSize = stream.ReadUInt32BigEndian();
header.TotalHunks = stream.ReadUInt32BigEndian();
header.Cylinders = stream.ReadUInt32BigEndian();
header.Heads = stream.ReadUInt32BigEndian();
header.Sectors = stream.ReadUInt32BigEndian();
header.MD5 = stream.ReadBytes(16);
header.ParentMD5 = stream.ReadBytes(16);
header.BytesPerSector = stream.ReadUInt32BigEndian();
return new CHDFile { _header = header, MD5 = header.MD5 };
}
/// <summary>
/// Parse and validate the header as if it's V2
/// </summary>
private static CHDFile? DeserializeV3(Stream stream)
{
var header = new HeaderV3();
byte[] tagBytes = stream.ReadBytes(8);
header.Tag = Encoding.ASCII.GetString(tagBytes);
if (header.Tag != Constants.SignatureString)
return null;
header.Length = stream.ReadUInt32BigEndian();
if (header.Length != Constants.HeaderV3Size)
return null;
header.Version = stream.ReadUInt32BigEndian();
header.Flags = (Flags)stream.ReadUInt32BigEndian();
header.Compression = (CompressionType)stream.ReadUInt32BigEndian();
if (header.Compression > CompressionType.CHDCOMPRESSION_ZLIB_PLUS)
return null;
header.TotalHunks = stream.ReadUInt32BigEndian();
header.LogicalBytes = stream.ReadUInt64BigEndian();
header.MetaOffset = stream.ReadUInt64BigEndian();
header.MD5 = stream.ReadBytes(16);
header.ParentMD5 = stream.ReadBytes(16);
header.HunkBytes = stream.ReadUInt32BigEndian();
header.SHA1 = stream.ReadBytes(20);
header.ParentSHA1 = stream.ReadBytes(20);
return new CHDFile { _header = header, MD5 = header.MD5, SHA1 = header.SHA1 };
}
/// <summary>
/// Parse and validate the header as if it's V4
/// </summary>
private static CHDFile? DeserializeV4(Stream stream)
{
var header = new HeaderV4();
byte[] tagBytes = stream.ReadBytes(8);
header.Tag = Encoding.ASCII.GetString(tagBytes);
if (header.Tag != Constants.SignatureString)
return null;
header.Length = stream.ReadUInt32BigEndian();
if (header.Length != Constants.HeaderV4Size)
return null;
header.Version = stream.ReadUInt32BigEndian();
header.Flags = (Flags)stream.ReadUInt32BigEndian();
header.Compression = (CompressionType)stream.ReadUInt32BigEndian();
if (header.Compression > CompressionType.CHDCOMPRESSION_AV)
return null;
header.TotalHunks = stream.ReadUInt32BigEndian();
header.LogicalBytes = stream.ReadUInt64BigEndian();
header.MetaOffset = stream.ReadUInt64BigEndian();
header.HunkBytes = stream.ReadUInt32BigEndian();
header.SHA1 = stream.ReadBytes(20);
header.ParentSHA1 = stream.ReadBytes(20);
header.RawSHA1 = stream.ReadBytes(20);
return new CHDFile { _header = header, SHA1 = header.SHA1 };
}
/// <summary>
/// Parse and validate the header as if it's V5
/// </summary>
private static CHDFile? DeserializeV5(Stream stream)
{
var header = new HeaderV5();
byte[] tagBytes = stream.ReadBytes(8);
header.Tag = Encoding.ASCII.GetString(tagBytes);
if (header.Tag != Constants.SignatureString)
return null;
header.Length = stream.ReadUInt32BigEndian();
if (header.Length != Constants.HeaderV5Size)
return null;
header.Version = stream.ReadUInt32BigEndian();
header.Compressors = new uint[4];
for (int i = 0; i < header.Compressors.Length; i++)
{
header.Compressors[i] = stream.ReadUInt32BigEndian();
}
header.LogicalBytes = stream.ReadUInt64BigEndian();
header.MapOffset = stream.ReadUInt64BigEndian();
header.MetaOffset = stream.ReadUInt64BigEndian();
header.HunkBytes = stream.ReadUInt32BigEndian();
header.UnitBytes = stream.ReadUInt32BigEndian();
header.RawSHA1 = stream.ReadBytes(20);
header.SHA1 = stream.ReadBytes(20);
header.ParentSHA1 = stream.ReadBytes(20);
return new CHDFile { _header = header, SHA1 = header.SHA1 };
}
#endregion
#region Helpers
/// <summary>
/// Get the matching CHD version, if possible
/// </summary>
/// <returns>Matching version, 0 if none</returns>
private static uint GetVersion(Stream stream)
{
// Read the header values
byte[] tagBytes = stream.ReadBytes(8);
string tag = Encoding.ASCII.GetString(tagBytes);
uint length = stream.ReadUInt32BigEndian();
uint version = stream.ReadUInt32BigEndian();
// Seek back to start
stream.SeekIfPossible();
// Check the signature
if (!string.Equals(tag, Constants.SignatureString, StringComparison.Ordinal))
return 0;
// Match the version to header length
return (version, length) switch
{
(1, Constants.HeaderV1Size) => version,
(2, Constants.HeaderV2Size) => version,
(3, Constants.HeaderV3Size) => version,
(4, Constants.HeaderV4Size) => version,
(5, Constants.HeaderV5Size) => version,
_ => 0,
};
}
#endregion
}
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -26,11 +26,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
@@ -48,10 +48,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SabreTools.Hashing" Version="1.2.3" />
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.Matching" Version="1.3.2" />
<PackageReference Include="SabreTools.Skippers" Version="1.1.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
<PackageReference Include="SabreTools.Matching" Version="1.4.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.7.0" />
<PackageReference Include="SabreTools.Skippers" Version="1.2.0" />
</ItemGroup>
</Project>

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<LangVersion>latest</LangVersion>
@@ -26,15 +26,15 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SabreTools.IO" Version="1.4.13" />
<PackageReference Include="SabreTools.IO" Version="1.5.0" />
</ItemGroup>
</Project>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
@@ -11,6 +11,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -27,11 +28,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
@@ -31,8 +31,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="SabreTools.Models" Version="1.4.10" />
<PackageReference Include="SabreTools.Serialization" Version="1.6.8" />
<PackageReference Include="SabreTools.Models" Version="1.5.0" />
<PackageReference Include="SabreTools.Serialization" Version="1.7.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Assembly Properties -->
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
@@ -11,6 +11,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.1.2</Version>
<WarningsNotAsErrors>NU1902;NU1903</WarningsNotAsErrors>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>
@@ -28,11 +29,11 @@
<PropertyGroup Condition="$(TargetFramework.StartsWith(`netcoreapp`)) OR $(TargetFramework.StartsWith(`net5`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`))">
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net6`)) OR $(TargetFramework.StartsWith(`net7`)) OR $(TargetFramework.StartsWith(`net8`)) OR $(TargetFramework.StartsWith(`net9`))">
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>

View File

@@ -1,7 +1,7 @@
#!/bin/bash
# This batch file assumes the following:
# - .NET 8.0 (or newer) SDK is installed and in PATH
# - .NET 9.0 (or newer) SDK is installed and in PATH
# - zip is installed and in PATH
# - Git is installed and in PATH
#
@@ -44,18 +44,18 @@ echo " No archive (-a) $NO_ARCHIVE"
echo " "
# Create the build matrix arrays
FRAMEWORKS=("net8.0")
FRAMEWORKS=("net9.0")
RUNTIMES=("win-x86" "win-x64" "win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64")
# Use expanded lists, if requested
if [ $USE_ALL = true ]; then
FRAMEWORKS=("net48" "netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0") # TODO: Support all frameworks
FRAMEWORKS=("net48" "netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0" "net9.0") # TODO: Support all frameworks
fi
# Create the filter arrays
SINGLE_FILE_CAPABLE=("net5.0" "net6.0" "net7.0" "net8.0")
VALID_APPLE_FRAMEWORKS=("net6.0" "net7.0" "net8.0")
VALID_CROSS_PLATFORM_FRAMEWORKS=("netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0")
SINGLE_FILE_CAPABLE=("net5.0" "net6.0" "net7.0" "net8.0" "net9.0")
VALID_APPLE_FRAMEWORKS=("net6.0" "net7.0" "net8.0" "net9.0")
VALID_CROSS_PLATFORM_FRAMEWORKS=("netcoreapp3.1" "net5.0" "net6.0" "net7.0" "net8.0" "net9.0")
VALID_CROSS_PLATFORM_RUNTIMES=("win-arm64" "linux-x64" "linux-arm64" "osx-x64" "osx-arm64")
# Only build if requested

View File

@@ -1,5 +1,5 @@
# This batch file assumes the following:
# - .NET 8.0 (or newer) SDK is installed and in PATH
# - .NET 9.0 (or newer) SDK is installed and in PATH
# - 7-zip commandline (7z.exe) is installed and in PATH
# - Git for Windows is installed and in PATH
#
@@ -35,18 +35,18 @@ Write-Host " No archive (-NoArchive) $NO_ARCHIVE"
Write-Host " "
# Create the build matrix arrays
$FRAMEWORKS = @('net8.0')
$FRAMEWORKS = @('net9.0')
$RUNTIMES = @('win-x86', 'win-x64', 'win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
# Use expanded lists, if requested
if ($USE_ALL.IsPresent) {
$FRAMEWORKS = @('net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0') # TODO: Support all frameworks
$FRAMEWORKS = @('net48', 'netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0') # TODO: Support all frameworks
}
# Create the filter arrays
$SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0')
$VALID_APPLE_FRAMEWORKS = @('net6.0', 'net7.0', 'net8.0')
$VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0')
$SINGLE_FILE_CAPABLE = @('net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0')
$VALID_APPLE_FRAMEWORKS = @('net6.0', 'net7.0', 'net8.0', 'net9.0')
$VALID_CROSS_PLATFORM_FRAMEWORKS = @('netcoreapp3.1', 'net5.0', 'net6.0', 'net7.0', 'net8.0', 'net9.0')
$VALID_CROSS_PLATFORM_RUNTIMES = @('win-arm64', 'linux-x64', 'linux-arm64', 'osx-x64', 'osx-arm64')
# Only build if requested