示例#1
0
        internal override void SaveData(BinaryWriter writer)
        {
            var position = writer.BaseStream.Position;

            WriteString(writer, Name);

            uint realSize;
            var  compressed = false;

            byte[] data;
            using (var stream = new MemoryStream()) {
                var dataWriter = new BinaryWriter(stream);
                foreach (var subRecord in this.SubRecords)
                {
                    subRecord.SaveData(dataWriter);
                }

                realSize = (uint)stream.Length;

                if (Properties.Settings.Default.UseDefaultRecordCompression)
                {
                    compressed = ((Flags1 & 0x00040000) != 0) || (Properties.Settings.Default.EnableAutoCompress && Compressor.CompressRecord(Name)) ||
                                 (Properties.Settings.Default.EnableCompressionLimit && (realSize >= Properties.Settings.Default.CompressionLimit));
                }

                data = stream.ToArray();
                if (compressed)
                {
                    data = ZLib.Compress(data);
                }
            }

            var dataSize = (uint)data.Length;
            var flags    = this.Flags1 & ~0x00040000U;

            if (compressed)
            {
                dataSize += 4;
                flags    |= 0x00040000;

                Debug.WriteLineIf(this.dataSize != dataSize, string.Format("COMPRESSED RECORD [NAME={0} AT POSITION={1}] SIZE DIFFERS FROM ORIGINAL: ORIGINAL={2} ACTUAL={3}, RAW RECORD SIZE={4}", this.Name, position, this.dataSize, dataSize, realSize));
            }

            writer.Write(dataSize); // Size of compressed section + length
            writer.Write(flags);
            writer.Write(FormID);
            writer.Write(Flags2);
            writer.Write(Flags3);
            if (compressed)
            {
                writer.Write(realSize);
            }

            writer.Write(data, 0, data.Length);
        }
示例#2
0
 internal override void SaveData(BinaryWriter bw)
 {
     Compressor.Init();
     foreach (Rec r in Records) r.SaveData(bw);
     Compressor.Close();
 }