/// <summary> /// Reads from a .ppx file. /// </summary> /// <param name="Filename">The filename of the .ppx file.</param> protected void ReadFromFile(string Filename) { this.Filename = Filename; using (FileStream arc = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BinaryReader reader = new BinaryReader(arc)) { string magic = Encoding.ASCII.GetString(reader.ReadBytes(4)); //Check magic if (Magic != magic) { throw new PpexException("Supplied file is not an extended PP archive.", PpexException.PpexErrorCode.FileNotPPXArchive); } //Check version ushort version = reader.ReadUInt16(); if (version != Version) { throw new PpexException($"Supplied extended PP archive is of version {version}; was expecting version {Version}", PpexException.PpexErrorCode.IncorrectVersionNumber); } //Read the title ushort strlen = reader.ReadUInt16(); Title = Encoding.Unicode.GetString(reader.ReadBytes((int)strlen)); //Read chunk and file headers TableInfoOffset = (ulong)arc.Position; ChunkTableOffset = reader.ReadUInt64(); FileTableOffset = reader.ReadUInt64(); reader.BaseStream.Position = (long)ChunkTableOffset; uint number = reader.ReadUInt32(); for (int i = 0; i < number; i++) { var chunk = ExtendedArchiveChunk.ReadFromTable(reader, this); chunks.Add(chunk); } reader.BaseStream.Position = (long)FileTableOffset; number = reader.ReadUInt32(); for (int i = 0; i < number; i++) { var source = ArchiveFileSource.ReadFromTable(reader, this); RawFiles.Add(source); Files.Add(new ArchiveSubfile(source)); } } }
internal static ExtendedArchiveChunk ReadFromTable(BinaryReader reader, ExtendedArchive archive) { ExtendedArchiveChunk chunk = new ExtendedArchiveChunk(); chunk.baseArchive = archive; chunk.ID = reader.ReadUInt32(); chunk.Compression = (ArchiveChunkCompression)reader.ReadByte(); chunk.CRC32 = reader.ReadUInt32(); chunk.Offset = reader.ReadUInt64(); chunk.CompressedLength = reader.ReadUInt64(); chunk.UncompressedLength = reader.ReadUInt64(); return(chunk); }