private void ReadChunkHeader(Bitstream stream) { header = new ChunkedHeader(); header.IsFile = stream.ReadBool(); if (header.IsFile) { var filenameLength = stream.ReadUInt32(); var filename = new byte[filenameLength + 1]; // semantically wrong. should be // 0x104 stream.Read(filename, 0, (int) filenameLength); // and then read to end of string filename[filenameLength] = 0; // whatever header.Filename = Encoding.UTF8.GetString(filename); throw new NotImplementedException(); } header.IsCompressed = stream.ReadBool(); if (header.IsCompressed) { header.DecompressedLength = stream.ReadBits(26); } header.ByteLength = stream.ReadBits(26); header.ChunkCount = (header.ByteLength + DotaGameConnection.BYTES_PER_CHUNK - 1)/ DotaGameConnection.BYTES_PER_CHUNK; Receiving = true; dataIn = new byte[header.ByteLength]; dataReceived = new bool[header.ChunkCount]; countReceived = 0; }
private void ReadChunkHeader(Bitstream stream) { header = new ChunkedHeader(); header.IsFile = stream.ReadBool(); if (header.IsFile) { var filenameLength = stream.ReadUInt32(); var filename = new byte[filenameLength + 1]; // semantically wrong. should be // 0x104 stream.Read(filename, 0, (int)filenameLength); // and then read to end of string filename[filenameLength] = 0; // whatever header.Filename = Encoding.UTF8.GetString(filename); throw new NotImplementedException(); } header.IsCompressed = stream.ReadBool(); if (header.IsCompressed) { header.DecompressedLength = stream.ReadBits(26); } header.ByteLength = stream.ReadBits(26); header.ChunkCount = (header.ByteLength + DotaGameConnection.BYTES_PER_CHUNK - 1) / DotaGameConnection.BYTES_PER_CHUNK; Receiving = true; dataIn = new byte[header.ByteLength]; dataReceived = new bool[header.ChunkCount]; countReceived = 0; }
public Chunked(Stream input, bool keepOpen = false, ChunkManager manager = null) { if (manager == null) { manager = Manager; } else { Manager = manager; } Chunks = new List <IChunk>(); entrees = new List <ChunkedEntry>(); entryOffsets = new List <long>(); if (input == null) { return; } start = input.Position; using (BinaryReader reader = new BinaryReader(input, System.Text.Encoding.Default, keepOpen)) { Header = reader.Read <ChunkedHeader>(); if (Header.magic != ChunkMagic) { return; } long next = input.Position; while (next < Header.size) { ChunkedEntry entry = reader.Read <ChunkedEntry>(); long offset = input.Position; next = offset + entry.size; IChunk chunk = manager.NewChunk(entry.StringIdentifier, Header.StringIdentifier); if (chunk != null) { MemoryStream dataStream = new MemoryStream(entry.size); CopyBytes(input, dataStream, entry.size); dataStream.Position = 0; chunk.Parse(dataStream); try { dataStream.Dispose(); } catch { } } Chunks.Add(chunk); entrees.Add(entry); entryOffsets.Add(offset); input.Position = next; } } }
private void ReadChunkHeader(Bitstream stream) { header = new ChunkedHeader(); header.IsFile = stream.ReadBool(); if (header.IsFile) { uint filenameLength = stream.ReadUInt32(); byte[] filename = new byte[filenameLength + 1]; // semantically wrong. should be // 0x104 stream.Read(filename, 0, (int)filenameLength); // and then read to end of string filename[filenameLength] = 0; // whatever header.Filename = Encoding.UTF8.GetString(filename); log.ErrorFormat("read filename: \"{0}\" ({1})", filenameLength, header.Filename); throw new NotImplementedException(); } header.IsCompressed = stream.ReadBool(); if (header.IsCompressed) { header.DecompressedLength = stream.ReadBits(26); log.DebugFormat( "chunkheader compressed: decompressed len {0}", header.DecompressedLength); } header.ByteLength = stream.ReadBits(26); header.ChunkCount = (header.ByteLength + Connection.BYTES_PER_CHUNK - 1) / Connection.BYTES_PER_CHUNK; log.DebugFormat( "chunkheader len {0} expecting {1} chunks", header.ByteLength, header.ChunkCount); Receiving = true; dataIn = new byte[header.ByteLength]; dataReceived = new bool[header.ChunkCount]; countReceived = 0; }