public void load(string file) { FileName = file; using (var stream = new System.IO.FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var reader = new BinaryReader(stream); var dataOffset = reader.ReadInt16() + 2; var headers = new List <DaxFileHeaderEntry>(); const int headerEntrySize = 9; for (var i = 0; i < ((dataOffset - 2) / headerEntrySize); i++) { var dhe = new DaxFileHeaderEntry { Id = reader.ReadByte(), Offset = reader.ReadInt32(), RawSize = reader.ReadUInt16(), CompressedSize = reader.ReadUInt16() }; headers.Add(dhe); } _blocks = new List <DaxFileBlock>(headers.Count); foreach (var dhe in headers) { byte[] compressedBytes; if (dhe.RawSize <= 0) { reader.BaseStream.Seek(dataOffset + dhe.Offset, SeekOrigin.Begin); compressedBytes = reader.ReadBytes(dhe.CompressedSize); _blocks.Add(new DaxFileBlock(FileName, dhe.Id, compressedBytes)); } else { var raw = new byte[dhe.RawSize]; reader.BaseStream.Seek(dataOffset + dhe.Offset, SeekOrigin.Begin); compressedBytes = reader.ReadBytes(dhe.CompressedSize); if (compressedBytes.Length == 0) { continue; } decodeCompressedBytes(dhe.CompressedSize, raw, compressedBytes); _blocks.Add(new DaxFileBlock(FileName, dhe.Id, raw)); } } } }
public void load(string file) { FileName = file; using (var stream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var reader = new BinaryReader(stream); var dataOffset = reader.ReadInt16() + 2; var headers = new List<DaxFileHeaderEntry>(); const int headerEntrySize = 9; for (var i = 0; i < ((dataOffset - 2) / headerEntrySize); i++) { var dhe = new DaxFileHeaderEntry { Id = reader.ReadByte(), Offset = reader.ReadInt32(), RawSize = reader.ReadUInt16(), CompressedSize = reader.ReadUInt16() }; headers.Add(dhe); } _blocks = new List<DaxFileBlock>(headers.Count); foreach (var dhe in headers) { byte[] compressedBytes; if (dhe.RawSize <= 0) { reader.BaseStream.Seek(dataOffset + dhe.Offset, SeekOrigin.Begin); compressedBytes = reader.ReadBytes(dhe.CompressedSize); _blocks.Add(new DaxFileBlock(FileName, dhe.Id, compressedBytes)); } else { var raw = new byte[dhe.RawSize]; reader.BaseStream.Seek(dataOffset + dhe.Offset, SeekOrigin.Begin); compressedBytes = reader.ReadBytes(dhe.CompressedSize); if (compressedBytes.Length == 0) continue; decodeCompressedBytes(dhe.CompressedSize, raw, compressedBytes); _blocks.Add(new DaxFileBlock(FileName, dhe.Id, raw)); } } } }