mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add .NET 9 to target frameworks
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user