Beispiel #1
0
        //internal override void Reconstruct()
        //{
        //    MemoryStream newStream = new MemoryStream();
        //    BinaryWriter writer = new BinaryWriter(newStream);
        //    writer.Write((byte)0);
        //    ReadAllStrings();
        //    foreach (var readString in readStrings)
        //    {
        //        byte[] bytes = Encoding.Unicode.GetBytes(readString.Value);
        //        NETGlobals.WriteCompressedUInt32(writer, (uint)bytes.Length + 1); // length + terminator length
        //        writer.Write(bytes); // data
        //        writer.Write((byte)0); // terminator
        //    }
        //    binaryreader.Dispose();
        //    stream.Dispose();
        //    stream = newStream;
        //    binaryreader = new BinaryReader(newStream);
        //    this.streamHeader.Size = (uint)newStream.Length;
        //    this.contents = newStream.ToArray();
        //}

        internal void ReadAllStrings()
        {
            _mainStream.Seek(0, SeekOrigin.Begin);

            uint lastPosition = (uint)_mainStream.Position;

            while (_mainStream.Position + 1 < _mainStream.Length)
            {
                // TODO: write string.empty strings..

                bool   alreadyExisted = _readStrings.ContainsKey((uint)_mainStream.Position + 1);
                string value          = GetStringByOffset((uint)_mainStream.Position + 1);


                int length = value.Length * 2;
                if (length == 0 && lastPosition == (uint)_mainStream.Position)
                {
                    _mainStream.Seek(1, SeekOrigin.Current);
                }
                if (alreadyExisted)
                {
                    _mainStream.Seek(length + NETGlobals.GetCompressedUInt32Size((uint)length) + 1, SeekOrigin.Current);
                }

                lastPosition = (uint)_mainStream.Position;
            }

            _hasReadAllStrings = true;
            _newEntryOffset    = (uint)_mainStream.Length;
        }
Beispiel #2
0
        internal void ReadAllBlobs()
        {
            _mainStream.Seek(1, SeekOrigin.Begin);
            while (_mainStream.Position < _mainStream.Length)
            {
                bool   alreadyExisted = _readBlobs.ContainsKey((uint)_mainStream.Position);
                byte[] value          = GetBlob((uint)_mainStream.Position);

                int length = value.Length;
                if (length == 0)
                {
                    break;
                }
                if (alreadyExisted)
                {
                    _mainStream.Seek(length + NETGlobals.GetCompressedUInt32Size((uint)length), SeekOrigin.Current);
                }
            }
        }