Exemplo n.º 1
0
        /// <summary>
        /// Exports the current header to a 512 byte array
        /// </summary>
        /// <remarks>
        /// This will not validate the disk or update the header.
        /// Use <see cref="Validate"/> and <see cref="ComputeChecksum"/> before exporting
        /// </remarks>
        /// <returns>Raw header data</returns>
        public byte[] Export()
        {
            using (var MS = new MemoryStream())
            {
                using (var BW = new BinaryWriter(MS))
                {
                    BW.Write(Encoding.Default.GetBytes(Cookie));
                    BW.Write(Tools.ToNetwork((uint)Features));
                    BW.Write(Tools.ToNetwork((ushort)FileFormatVersion.Major));
                    BW.Write(Tools.ToNetwork((ushort)FileFormatVersion.Minor));
                    BW.Write(Tools.ToNetwork(DataOffset));
                    BW.Write(Tools.ToNetwork((int)VHD.ToDiskTimestamp(TimeStamp)));

                    BW.Write(Encoding.Default.GetBytes(CreatorApplication));
                    BW.Write(Tools.ToNetwork((ushort)CreatorVersion.Major));
                    BW.Write(Tools.ToNetwork((ushort)CreatorVersion.Minor));
                    BW.Write(Encoding.Default.GetBytes(CreatorHostOS));

                    BW.Write(Tools.ToNetwork(OriginalSize));
                    BW.Write(Tools.ToNetwork(CurrentSize));

                    BW.Write(Tools.ToNetwork((ushort)DiskGeometry.Cylinders));
                    BW.Write((byte)DiskGeometry.Heads);
                    BW.Write((byte)DiskGeometry.SectorsPerTrack);

                    BW.Write(Tools.ToNetwork((uint)DiskType));

                    BW.Write(Tools.ToNetwork(Checksum));

                    BW.Write(DiskId.ToByteArray());
                    BW.Write((byte)(SavedState ? 1 : 0));
                    BW.Write(Reserved);

                    BW.Flush();

                    return(MS.ToArray());
                }
            }
        }