Make CHD headers (mostly) serializable

This commit is contained in:
Matt Nadareski
2024-11-12 12:31:23 -05:00
parent dd6b79a21b
commit f73ff87922
6 changed files with 84 additions and 46 deletions

View File

@@ -1,21 +1,25 @@
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public abstract class Header
{
/// <summary>
/// 'MComprHD'
/// </summary>
public string? Tag { get; set; }
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
public string? Tag;
/// <summary>
/// Length of header (including tag and length fields)
/// </summary>
public uint Length { get; set; }
public uint Length;
/// <summary>
/// Drive format version
/// </summary>
public uint Version { get; set; }
public uint Version;
}
}

View File

@@ -1,51 +1,58 @@
namespace SabreTools.Models.CHD
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class HeaderV1 : Header
{
/// <summary>
/// Flags
/// </summary>
public Flags Flags { get; set; }
[MarshalAs(UnmanagedType.U4)]
public Flags Flags;
/// <summary>
/// Compression type
/// </summary>
public CompressionType Compression { get; set; }
[MarshalAs(UnmanagedType.U4)]
public CompressionType Compression;
/// <summary>
/// 512-byte sectors per hunk
/// </summary>
public uint HunkSize { get; set; }
public uint HunkSize;
/// <summary>
/// Total # of hunks represented
/// </summary>
public uint TotalHunks { get; set; }
public uint TotalHunks;
/// <summary>
/// Number of cylinders on hard disk
/// </summary>
public uint Cylinders { get; set; }
public uint Cylinders;
/// <summary>
/// Number of heads on hard disk
/// </summary>
public uint Heads { get; set; }
public uint Heads;
/// <summary>
/// Number of sectors on hard disk
/// </summary>
public uint Sectors { get; set; }
public uint Sectors;
/// <summary>
/// MD5 checksum of raw data
/// </summary>
public byte[]? MD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] MD5 = new byte[16];
/// <summary>
/// MD5 checksum of parent file
/// </summary>
public byte[]? ParentMD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[] ParentMD5 = new byte[16];
}
}

View File

@@ -1,56 +1,63 @@
namespace SabreTools.Models.CHD
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class HeaderV2 : Header
{
/// <summary>
/// Flags
/// </summary>
public Flags Flags { get; set; }
[MarshalAs(UnmanagedType.U4)]
public Flags Flags;
/// <summary>
/// Compression type
/// </summary>
public CompressionType Compression { get; set; }
[MarshalAs(UnmanagedType.U4)]
public CompressionType Compression;
/// <summary>
/// Seclen-byte sectors per hunk
/// </summary>
public uint HunkSize { get; set; }
public uint HunkSize;
/// <summary>
/// Total # of hunks represented
/// </summary>
public uint TotalHunks { get; set; }
public uint TotalHunks;
/// <summary>
/// Number of cylinders on hard disk
/// </summary>
public uint Cylinders { get; set; }
public uint Cylinders;
/// <summary>
/// Number of heads on hard disk
/// </summary>
public uint Heads { get; set; }
public uint Heads;
/// <summary>
/// Number of sectors on hard disk
/// </summary>
public uint Sectors { get; set; }
public uint Sectors;
/// <summary>
/// MD5 checksum of raw data
/// </summary>
public byte[]? MD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? MD5 = new byte[16];
/// <summary>
/// MD5 checksum of parent file
/// </summary>
public byte[]? ParentMD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? ParentMD5 = new byte[16];
/// <summary>
/// Number of bytes per sector
/// </summary>
public uint BytesPerSector { get; set; }
public uint BytesPerSector;
}
}

View File

@@ -1,56 +1,65 @@
namespace SabreTools.Models.CHD
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class HeaderV3 : Header
{
/// <summary>
/// Flags
/// </summary>
public Flags Flags { get; set; }
[MarshalAs(UnmanagedType.U4)]
public Flags Flags;
/// <summary>
/// Compression type
/// </summary>
public CompressionType Compression { get; set; }
[MarshalAs(UnmanagedType.U4)]
public CompressionType Compression;
/// <summary>
/// Total # of hunks represented
/// </summary>
public uint TotalHunks { get; set; }
public uint TotalHunks;
/// <summary>
/// Logical size of the data (in bytes)
/// </summary>
public ulong LogicalBytes { get; set; }
public ulong LogicalBytes;
/// <summary>
/// Offset to the first blob of metadata
/// </summary>
public ulong MetaOffset { get; set; }
public ulong MetaOffset;
/// <summary>
/// MD5 checksum of raw data
/// </summary>
public byte[]? MD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? MD5 = new byte[16];
/// <summary>
/// MD5 checksum of parent file
/// </summary>
public byte[]? ParentMD5 { get; set; } = new byte[16];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
public byte[]? ParentMD5 = new byte[16];
/// <summary>
/// Number of bytes per hunk
/// </summary>
public uint HunkBytes { get; set; }
public uint HunkBytes;
/// <summary>
/// SHA1 checksum of raw data
/// </summary>
public byte[]? SHA1 { get; set; } = new byte[20];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? SHA1 = new byte[20];
/// <summary>
/// SHA1 checksum of parent file
/// </summary>
public byte[]? ParentSHA1 { get; set; } = new byte[20];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ParentSHA1 = new byte[20];
}
}

View File

@@ -1,51 +1,59 @@
namespace SabreTools.Models.CHD
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class HeaderV4 : Header
{
/// <summary>
/// Flags
/// </summary>
public Flags Flags { get; set; }
[MarshalAs(UnmanagedType.U4)]
public Flags Flags;
/// <summary>
/// Compression type
/// </summary>
public CompressionType Compression { get; set; }
[MarshalAs(UnmanagedType.U4)]
public CompressionType Compression;
/// <summary>
/// Total # of hunks represented
/// </summary>
public uint TotalHunks { get; set; }
public uint TotalHunks;
/// <summary>
/// Logical size of the data (in bytes)
/// </summary>
public ulong LogicalBytes { get; set; }
public ulong LogicalBytes;
/// <summary>
/// Offset to the first blob of metadata
/// </summary>
public ulong MetaOffset { get; set; }
public ulong MetaOffset;
/// <summary>
/// Number of bytes per hunk
/// </summary>
public uint HunkBytes { get; set; }
public uint HunkBytes;
/// <summary>
/// Combined raw+meta SHA1
/// </summary>
public byte[]? SHA1 { get; set; } = new byte[20];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? SHA1 = new byte[20];
/// <summary>
/// Combined raw+meta SHA1 of parent
/// </summary>
public byte[]? ParentSHA1 { get; set; } = new byte[20];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? ParentSHA1 = new byte[20];
/// <summary>
/// Raw data SHA1
/// </summary>
public byte[]? RawSHA1 { get; set; } = new byte[20];
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[]? RawSHA1 = new byte[20];
}
}

View File

@@ -1,6 +1,9 @@
namespace SabreTools.Models.CHD
using System.Runtime.InteropServices;
namespace SabreTools.Models.CHD
{
/// <see href="https://github.com/mamedev/mame/blob/master/src/lib/util/chd.h"/>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class HeaderV5 : Header
{
/// <summary>