Ejemplo n.º 1
0
        public static byte[] CreateWrappedArchive(string basePath, string[] includes, string[] excludes)
        {
            using (MemoryStream inStream = new MemoryStream()) {
                var zipOut = new SevenZipCompressor();
                zipOut.ArchiveFormat = OutArchiveFormat.Zip;
                zipOut.CompressionLevel = SevenZip.CompressionLevel.None;

                List<string> FileList = new List<string>(Search.FindFiles(
                    basePath, includes, excludes, SearchOption.AllDirectories
                ));

                SevenZipBase.SetLibraryPath(Inits.EnsureBinaries());
                zipOut.CompressFileDictionary(
                    FileList.ToDictionary(f => f.Replace(basePath, null), f => f),
                    inStream
                );

                inStream.Position = 0;

                using (var outStream = new MemoryStream()) {
                    using (var LzmaStream = new LzmaEncodeStream(outStream)) {
                        int byt = 0;
                        while ((byt = inStream.ReadByte()) != -1)
                            LzmaStream.WriteByte((byte)byt);
                    }
                    return outStream.ToArray();
                }
            }
        }
        void CloseWriter()
        {
            Debug.WriteLine("BsonFileFingerprintStore.CloseWriter()");

            var jsonWriter = _jsonWriter;
            _jsonWriter = null;

            var bufferStream = _bufferStream;
            _bufferStream = null;

            var lzmaEncodeStream = _lzmaEncodeStream;
            _lzmaEncodeStream = null;

            var bsonFile = _bsonFile;
            _bsonFile = null;

            if (null != jsonWriter)
            {
                jsonWriter.Flush();

                jsonWriter.Close();
            }

            bufferStream?.Close();

            lzmaEncodeStream?.Close();

            bsonFile?.Close();
        }
Ejemplo n.º 3
0
        private static IDictionary<string, string> BuildRenameDict(string bsaName)
        {
            var dictPath = Path.Combine(InDir, "TTW Patches", bsaName, "RenameFiles.dict");
            if (File.Exists(dictPath))
            {
                var renameDict = Util.ReadOldDatabase(dictPath);
                var newRenPath = Path.Combine(OutDir, Path.ChangeExtension(bsaName, ".ren"));
                if (!File.Exists(newRenPath))
                    using (var fileStream = File.OpenWrite(newRenPath))
                    using (var lzmaStream = new LzmaEncodeStream(fileStream))
                    using (var writer = new BinaryWriter(lzmaStream))
                    {
                        writer.Write(renameDict.Count);
                        foreach (var kvp in renameDict)
                        {
                            writer.Write(kvp.Key);
                            writer.Write(kvp.Value);
                        }
                    }

                return renameDict;
            }

            return new Dictionary<string, string>();
        }
        void OpenWriter()
        {
            Debug.WriteLine("BsonFileFingerprintStore.OpenWriter()");

            if (null == _bsonFile)
            {
                var fi = _fileSequence.NewFile();
                _bsonFile = OpenBsonFileForWrite(fi);
            }

            if (null == _lzmaEncodeStream)
                _lzmaEncodeStream = new LzmaEncodeStream(_bsonFile);

            if (null == _bufferStream)
                _bufferStream = new BufferedStream(_lzmaEncodeStream, 512 * 1024);

            if (null == _jsonWriter)
                _jsonWriter = new BsonWriter(_bufferStream) { DateTimeKindHandling = DateTimeKind.Utc };
        }