public GMAHeader ReadHeader() { BaseStream.Seek(0, SeekOrigin.Begin); // Magic constant "GMAD" byte[] magicConstant = ReadBytes(4); if (Encoding.ASCII.GetString(magicConstant) != "GMAD") { throw new Exception("Invalid file type"); } byte gmaVersion = ReadByte(); if (gmaVersion > 3) { throw new Exception("Unsupported GMA version " + gmaVersion); } GMAHeader header = new GMAHeader { SteamID = ReadUInt64(), Timestamp = ReadInt64(), RequiredContent = ReadNullTerminatedString(), Name = ReadNullTerminatedString(), Description = ReadNullTerminatedString(), Author = ReadNullTerminatedString(), Version = ReadInt32() }; List <GMAFileHeader> files = new List <GMAFileHeader>(); long curOffset = 0; while (ReadUInt32() > 0) { GMAFileHeader curFile = new GMAFileHeader { Path = ReadNullTerminatedString(), Size = ReadInt64(), CRC = ReadUInt32(), FileNumber = files.Count, Offset = curOffset }; curOffset += curFile.Size; files.Add(curFile); } header.DataStart = BaseStream.Position; header.Files = files.ToArray(); return(header); }
public GMAFile(string path) { _reader = new GMAReader(File.Open(path, FileMode.Open)); _header = _reader.ReadHeader(); _fileDataCache = new Dictionary <int, byte[]>(); }