Exemple #1
0
        private byte[] createReplayData()
        {
            byte[] content = new ASCIIEncoding().GetBytes(replayStringContent);

            using (var outStream = new MemoryStream())
            {
                using (var lzma = new LzmaStream(new LzmaEncoderProperties(false, 1 << 21, 255), false, outStream))
                {
                    outStream.Write(lzma.Properties);

                    long fileSize = content.Length;
                    for (int i = 0; i < 8; i++)
                    {
                        outStream.WriteByte((byte)(fileSize >> (8 * i)));
                    }

                    lzma.Write(content);
                }

                return(outStream.ToArray());
            }
        }
Exemple #2
0
        private void CloseWriting7Zip()
        {
            if (_compressed)
            {
                _lzmaStream.Close();
            }

            _packStreamSize = (ulong)_zipFs.Position - _packStreamStart;

            Create7ZStructure();

            byte[] newHeaderByte;
            using (Stream headerMem = new MemoryStream())
            {
                using (BinaryWriter headerBw = new BinaryWriter(headerMem, Encoding.UTF8, true))
                {
                    _header.WriteHeader(headerBw);

                    newHeaderByte      = new byte[headerMem.Length];
                    headerMem.Position = 0;
                    headerMem.Read(newHeaderByte, 0, newHeaderByte.Length);
                }
            }

            uint mainHeaderCRC = CRC.CalculateDigest(newHeaderByte, 0, (uint)newHeaderByte.Length);

            #region Header Compression
            long packedHeaderPos        = _zipFs.Position;
            LzmaEncoderProperties ep    = new LzmaEncoderProperties(true, GetDictionarySizeFromUncompressedSize((ulong)newHeaderByte.Length), 64);
            LzmaStream            lzs   = new LzmaStream(ep, false, _zipFs);
            byte[] lzmaStreamProperties = lzs.Properties;
            lzs.Write(newHeaderByte, 0, newHeaderByte.Length);
            lzs.Close();

            StreamsInfo streamsInfo = new StreamsInfo
            {
                PackPosition = (ulong)(packedHeaderPos - _baseOffset),
                Folders      = new[] {
                    new Folder {
                        BindPairs = new BindPair[0],
                        Coders    = new [] {
                            new Coder {
                                Method        = new byte[] { 3, 1, 1 },
                                NumInStreams  = 1,
                                NumOutStreams = 1,
                                Properties    = lzmaStreamProperties
                            }
                        },
                        UnpackedStreamSizes = new[] { (ulong)newHeaderByte.Length },
                        UnpackCRC           = mainHeaderCRC
                    }
                },
                PackedStreams = new[] {
                    new PackedStreamInfo
                    {
                        PackedSize     = (ulong)(_zipFs.Position - packedHeaderPos),
                        StreamPosition = 0
                    }
                }
            };

            using (Stream headerMem = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(headerMem, Encoding.UTF8, true))
                {
                    bw.Write((byte)HeaderProperty.kEncodedHeader);
                    streamsInfo.WriteHeader(bw);

                    newHeaderByte      = new byte[headerMem.Length];
                    headerMem.Position = 0;
                    headerMem.Read(newHeaderByte, 0, newHeaderByte.Length);
                }
            }
            mainHeaderCRC = CRC.CalculateDigest(newHeaderByte, 0, (uint)newHeaderByte.Length);
            #endregion


            using (BinaryWriter bw = new BinaryWriter(_zipFs, Encoding.UTF8, true))
            {
                ulong headerPosition = (ulong)_zipFs.Position + 32; //tzip header is 32 bytes
                WriteRomVault7Zip(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);

                _zipFs.Write(newHeaderByte, 0, newHeaderByte.Length);
                _signatureHeader.WriteFinal(bw, headerPosition, (ulong)newHeaderByte.Length, mainHeaderCRC);
            }
            _zipFs.Flush();
            _zipFs.Close();
            _zipFs.Dispose();
        }
Exemple #3
0
 /// <summary>
 ///     使用回放数据,数据长度和表示生命值图像的字符串构造一个AdditionalRepalyData对象
 /// </summary>
 /// <param name="data"></param>
 /// <param name="len"></param>
 /// <param name="lifebarGraphStr"></param>
 public AdditionalRepalyData(byte[] data, int len, string lifebarGraphStr)
 {
     LzmaStream.Write(data, 0, len);
     ReplayDataLength = len;
     _l = new LifeBarGraphCollection(lifebarGraphStr);
 }