using System; using System.IO; using System.Diagnostics; namespace TwlBackupBlock { /// /// ヘッダブロック中のTMDReserved。 /// Normal, Legacy 共に共通。 /// public class TmdReserved { private const int TMD_RESERVED_SIZE = 62; public const int RESERVED8_SIZE = 3; public const int PARENTAL_CONTROL_SIZE = 16; public const int RESERVED_SIZE = 30; public UInt32 publicSaveSize; public UInt32 privateSaveSize; public UInt32 reserved32; public Byte flags; public readonly Byte[] reserved8; public readonly Byte[] parentalControl; public readonly Byte[] reserved; public TmdReserved() { reserved8 = new Byte[RESERVED8_SIZE]; parentalControl = new Byte[PARENTAL_CONTROL_SIZE]; reserved = new Byte[RESERVED_SIZE]; } public byte[] GetBytes() { byte[] bytes = new byte[TMD_RESERVED_SIZE]; using (var ms = new MemoryStream(bytes)) using (var bw = new BinaryWriter(ms)) { bw.Write(publicSaveSize); bw.Write(privateSaveSize); bw.Write(reserved32); bw.Write(flags); bw.Write(reserved8); bw.Write(parentalControl); bw.Write(reserved); Debug.Assert(ms.Position == TMD_RESERVED_SIZE); } return bytes; } public void SetBytes(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException("bytes"); } if (bytes.Length != TMD_RESERVED_SIZE) { string message = string.Format("bytes.Length != {0} (bytes.Length:{1})", TMD_RESERVED_SIZE, bytes.Length); throw new ArgumentException("bytes", message); } using (var ms = new MemoryStream(bytes)) using (var br = new ExtBinaryReader(ms)) { br.Read(ref publicSaveSize); br.Read(ref privateSaveSize); br.Read(ref reserved32); br.Read(ref flags); br.Read(reserved8); br.Read(parentalControl); br.Read(reserved); Debug.Assert(ms.Position == TMD_RESERVED_SIZE); } } } }