private byte[] CheckAndDecompress(BinaryReader reader, GpkPackage package) { logger.Trace("checkAndDecompress start"); if (package.Header.ChunkHeaders.Count == 0) { return(null); } byte[] completeFile = new byte[package.UncompressedSize]; //should be the complete file size for (int i = 0; i < package.Header.ChunkHeaders.Count; i++) { GpkCompressedChunkHeader header = package.Header.ChunkHeaders[i]; reader.BaseStream.Seek(header.CompressedOffset, SeekOrigin.Begin); PackageChunkBlock chunk = new PackageChunkBlock(); chunk.signature = reader.ReadInt32(); chunk.blocksize = reader.ReadInt32(); chunk.compressedSize = reader.ReadInt32(); chunk.uncompressedSize_chunkheader = reader.ReadInt32(); int blockCount = Convert.ToInt32(Math.Ceiling(chunk.uncompressedSize_chunkheader / (double)chunk.blocksize)); byte[] uncompressedBytes = new byte[header.UncompressedSize]; chunk.Decompress(uncompressedBytes, blockCount, reader, package.Header.CompressionFlags); Array.ConstrainedCopy(uncompressedBytes, 0, completeFile, header.UncompressedOffset, header.UncompressedSize); logger.Trace("ChunkData {0}: BlockCount {1}, BlockSize {2}, compressedSize {3}, uncompressedSize_chunkheader {4}", i, blockCount, chunk.blocksize, chunk.compressedSize, chunk.uncompressedSize_chunkheader); } if (CoreSettings.Default.Debug) { //dump uncompressed file string path = String.Format("{0}\\decomp_{1}", Directory.GetCurrentDirectory(), package.Filename); //Task.Factory.StartNew(() => File.WriteAllBytes(path, completeFile)); } return(completeFile); }
private byte[] CheckAndDecompress(BinaryReader reader, GpkPackage package) { logger.Trace("checkAndDecompress start"); if (package.Header.ChunkHeaders.Count == 0) { return(null); } byte[] completeFile = new byte[package.UncompressedSize]; //should be the complete file size foreach (var header in package.Header.ChunkHeaders) { reader.BaseStream.Seek(header.CompressedOffset, SeekOrigin.Begin); PackageChunkBlock block = new PackageChunkBlock(); block.signature = reader.ReadInt32(); block.blocksize = reader.ReadInt32(); block.compressedSize = reader.ReadInt32(); block.uncompressedSize_chunkheader = reader.ReadInt32(); int chunkCount = (block.uncompressedSize_chunkheader + block.blocksize - 1) / block.blocksize; byte[] uncompressedBytes = new byte[header.UncompressedSize]; block.Decompress(uncompressedBytes, chunkCount, reader, package.Header.CompressionFlags); Array.ConstrainedCopy(uncompressedBytes, 0, completeFile, header.UncompressedOffset, header.UncompressedSize); } if (Settings.Default.Debug) { //dump uncompressed file string path = String.Format("{0}\\decomp_{1}", Directory.GetCurrentDirectory(), package.Filename); Task.Factory.StartNew(() => File.WriteAllBytes(path, completeFile)); } return(completeFile); }