Пример #1
0
        protected virtual T FillHeader <T>() where T : SIDBasicHeader, new()
        {
            T retValue = new T();

            if (HeaderLength > sidStream.Length)
            {
                return(null);
            }

            byte[] headerBuff = new byte[HeaderLength];
            sidStream.Read(headerBuff, 0, HeaderLength);
            binaryReader = new EndianAwareBinaryReader(new MemoryStream(headerBuff), encoding);
            string fileType = Encoding.ASCII.GetString(binaryReader.ReadBytes(4));

            retValue.FileType = (SIDByteType)(Enum.IsDefined(typeof(SIDByteType), fileType) ? Enum.Parse(typeof(SIDByteType), fileType) : SIDByteType.Unknown);
            //if (retValue.FileType == SidByteType.Unknown) throw new Exception("Not a valid SID File"); // To throw or not to throw :P
            retValue.Version = binaryReader.ReadUInt16BigEndian();
            return(retValue);
        }