2020-07-15 09:41:59 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
2024-04-24 13:45:38 -04:00
|
|
|
|
using SabreTools.IO.Extensions;
|
2024-10-20 00:03:29 -04:00
|
|
|
|
using SabreTools.Models.CHD;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2020-12-08 14:53:49 -08:00
|
|
|
|
namespace SabreTools.FileTypes.CHD
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// CHD V5 File
|
|
|
|
|
|
/// </summary>
|
2020-12-19 15:53:19 -08:00
|
|
|
|
public class CHDFileV5 : CHDFile
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
2024-10-20 00:11:15 -04:00
|
|
|
|
internal const int HeaderSize = 124;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Parse and validate the header as if it's V5
|
|
|
|
|
|
/// </summary>
|
2024-10-20 00:11:15 -04:00
|
|
|
|
internal static CHDFileV5? Deserialize(Stream stream)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
2024-10-20 00:03:29 -04:00
|
|
|
|
var header = new HeaderV5();
|
2020-07-15 09:41:59 -07:00
|
|
|
|
|
2024-10-20 00:03:29 -04:00
|
|
|
|
byte[] tagBytes = stream.ReadBytes(8);
|
|
|
|
|
|
header.Tag = Encoding.ASCII.GetString(tagBytes);
|
|
|
|
|
|
if (header.Tag != Signature)
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
header.Length = stream.ReadUInt32BigEndian();
|
|
|
|
|
|
if (header.Length != HeaderSize)
|
|
|
|
|
|
return null;
|
2020-07-19 21:59:34 -07:00
|
|
|
|
|
2024-10-20 00:03:29 -04:00
|
|
|
|
header.Version = stream.ReadUInt32BigEndian();
|
|
|
|
|
|
header.Compressors = new uint[4];
|
|
|
|
|
|
for (int i = 0; i < header.Compressors.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
header.Compressors[i] = stream.ReadUInt32BigEndian();
|
2020-07-15 09:41:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-20 00:03:29 -04:00
|
|
|
|
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 CHDFileV5 { _header = header, SHA1 = header.SHA1 };
|
2020-07-15 09:41:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|