public Packfile(Stream stream) { stream.Seek(0, SeekOrigin.Begin); FileData = stream.ReadStruct<PackfileFileData>(); m_Files = new List<IPackfileEntry>(); stream.Seek(GetEntryDataOffset(), SeekOrigin.Begin); List<PackfileEntryFileData> entryFileData = new List<PackfileEntryFileData>(); for (int i = 0; i < FileData.NumFiles; i++) { var fileData = stream.ReadStruct<PackfileEntryFileData>(); entryFileData.Add(fileData); } uint runningPosition = 0; List<string> fileNames = new List<string>(); for (int i = 0; i < FileData.NumFiles; i++) { var fileData = entryFileData[i]; stream.Seek(CalculateEntryNamesOffset() + fileData.Name, SeekOrigin.Begin); string name = stream.ReadAsciiNullTerminatedString(); //stream.Seek(CalculateExtensionsOffset() + fileData., SeekOrigin.Begin); //string extension = stream.ReadAsciiNullTerminatedString(); if (IsCondensed && IsCompressed) { fileData.Start = runningPosition; runningPosition += fileData.Size.Align(64); } else if (IsCondensed) { fileData.Start = runningPosition; runningPosition += fileData.Size.Align(16); } else if (IsCompressed) { fileData.Start = runningPosition; runningPosition += fileData.CompressedSize.Align(2048); } m_Files.Add(new PackfileEntry(this, fileData, name)); } if (IsCondensed && IsCompressed) { stream.Seek(CalculateDataStartOffset(), SeekOrigin.Begin); DataOffset = 0; byte[] compressedData = new byte[FileData.CompressedDataSize]; stream.Read(compressedData, 0, (int)FileData.CompressedDataSize); using (MemoryStream tempStream = new MemoryStream(compressedData)) { using (Stream s = new ZlibStream(tempStream, CompressionMode.Decompress, true)) { byte[] uncompressedData = new byte[FileData.DataSize]; s.Read(uncompressedData, 0, (int)FileData.DataSize); DataStream = new MemoryStream(uncompressedData); } } DataStream.Seek(0, SeekOrigin.Begin); } else { DataStream = stream; DataOffset = CalculateDataStartOffset(); } }
public Packfile() { FileData = new PackfileFileData(); m_Files = new List<IPackfileEntry>(); m_Streams = new Dictionary<string, Stream>(); }