예제 #1
0
        /// <summary>
        /// Creates a new instance of a RomMetadataBlock by inflating it from a BinaryReader.
        /// </summary>
        /// <param name="reader">The binary reader containing the data to deserialize to create the object.</param>
        /// <returns>A new instance of a RomMetadataBlock.</returns>
        /// <remarks>It is assumed that the reader is currently positioned at the beginning of a serialized ROM metadata block.</remarks>
        public static RomMetadataBlock Inflate(INTV.Core.Utility.BinaryReader reader)
        {
            RomMetadataBlock metadataBlock = null;
            int additionalBytesInPayloadLength;
            var payloadLength     = DecodeLength(reader, out additionalBytesInPayloadLength);
            var metadataBlockType = (RomMetadataIdTag)reader.ReadByte();

            switch (metadataBlockType)
            {
            case RomMetadataIdTag.Title:
            case RomMetadataIdTag.ShortTitle:
            case RomMetadataIdTag.License:
            case RomMetadataIdTag.Description:
            case RomMetadataIdTag.Version:
            case RomMetadataIdTag.UrlContactInfo:
                metadataBlock = new RomMetadataString(payloadLength, metadataBlockType);
                break;

            case RomMetadataIdTag.ReleaseDate:
            case RomMetadataIdTag.BuildDate:
                metadataBlock = new RomMetadataDate(payloadLength, metadataBlockType);
                break;

            case RomMetadataIdTag.Features:
                metadataBlock = new RomMetadataFeatures(payloadLength);
                break;

            case RomMetadataIdTag.Publisher:
                metadataBlock = new RomMetadataPublisher(payloadLength);
                break;

            case RomMetadataIdTag.Credits:
                metadataBlock = new RomMetadataCredits(payloadLength);
                break;

            case RomMetadataIdTag.ControllerBindings:
                metadataBlock = new RomMetadataControllerBindings(payloadLength);
                break;

            default:
                metadataBlock = new RomMetadataBlock(payloadLength, metadataBlockType);
                break;
            }
            metadataBlock._deserializeByteCount = (int)payloadLength + additionalBytesInPayloadLength + 1 + CrcByteCount + sizeof(RomMetadataIdTag);
            metadataBlock.Deserialize(reader);

            // Re-reading the block is more expensive than having a running CRC16 but it's easier to implement. :P
            var numBytesInForCrc = metadataBlock._deserializeByteCount - CrcByteCount;

            reader.BaseStream.Seek(-numBytesInForCrc, System.IO.SeekOrigin.Current);
            var payload = reader.ReadBytes(numBytesInForCrc);

            metadataBlock.Crc = (ushort)(((int)reader.ReadByte() << 8) | reader.ReadByte());
            metadataBlock.ValidatePayloadCrc(payload);

            return(metadataBlock);
        }
예제 #2
0
        /// <summary>
        /// Creates a new instance of a RomMetadataBlock by inflating it from a Stream.
        /// </summary>
        /// <param name="stream">The stream containing the data to deserialize to create the object.</param>
        /// <returns>A new instance of a RomMetadataBlock.</returns>
        public static RomMetadataBlock Inflate(System.IO.Stream stream)
        {
            RomMetadataBlock metadataBlock = null;

            using (var reader = new INTV.Core.Utility.BinaryReader(stream))
            {
                metadataBlock = Inflate(reader);
            }
            return(metadataBlock);
        }