private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress, CancellationToken cancellationToken, string destinationDirPath = null) { string destPath = Path.Combine(destinationDirPath == null ? _destinationDirPath : destinationDirPath, file.Name + _suffix); DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath); if (file.Size == null) { throw new NullReferenceException("File size cannot be null for regular file."); } if (file.Offset == null) { throw new NullReferenceException("File offset cannot be null for regular file."); } Files.CreateParents(destPath); var rijn = new RijndaelManaged { Mode = CipherMode.CBC, Padding = PaddingMode.None, KeySize = 256 }; var aesAlg = new AesCryptoServiceProvider { IV = _iv, Key = _key }; ICryptoTransform decryptor = aesAlg.CreateDecryptor( aesAlg.Key, aesAlg.IV); DecompressorCreator decompressorCreator = ResolveDecompressor(_metaData); using (var fs = new FileStream(_packagePath, FileMode.Open)) { fs.Seek(file.Offset.Value - _range.Start, SeekOrigin.Begin); using (var limitedStream = new BufferedStream(new LimitedStream(fs, file.Size.Value), 2 * 1024 * 1024)) { //using (var bufferedLimitedStream = new ThreadBufferedStream(limitedStream, 8 * 1024 * 1024)) { using (var target = new FileStream(destPath, FileMode.Create)) { ExtractFileFromStream(limitedStream, target, file.Size.Value, decryptor, decompressorCreator, onProgress, cancellationToken); } } if (Platform.IsPosix()) { Chmod.SetMode(file.Mode.Substring(3), destPath); } } } DebugLogger.Log("File " + file.Name + " unpacked successfully!"); }
private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress) { string destPath = Path.Combine(_destinationDirPath, file.Name + _suffix); DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath); Files.CreateParents(destPath); RijndaelManaged rijn = new RijndaelManaged { Mode = CipherMode.CBC, Padding = PaddingMode.None, KeySize = 256 }; using (var fs = new FileStream(_packagePath, FileMode.Open)) { fs.Seek(file.Offset.Value, SeekOrigin.Begin); using (var limitedStream = new LimitedStream(fs, file.Size.Value)) { ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv); using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read)) { using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) { using (var fileWritter = new FileStream(destPath, FileMode.Create)) { long bytesProcessed = 0; const int bufferSize = 131072; var buffer = new byte[bufferSize]; int count; while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) { fileWritter.Write(buffer, 0, count); bytesProcessed += count; onProgress(bytesProcessed / (double)file.Size.Value); } if (Platform.IsPosix()) { Chmod.SetMode(file.Mode.Substring(3), destPath); } } } } } } DebugLogger.Log("File " + file.Name + " unpacked successfully!"); }
private void UnpackRegularFile(Pack1Meta.FileEntry file) { string destPath = Path.Combine(_destinationDirPath, file.Name); DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath); Files.CreateParents(destPath); RijndaelManaged rijn = new RijndaelManaged { Mode = CipherMode.CBC, Padding = PaddingMode.None, KeySize = 256 }; using (var fs = new FileStream(_packagePath, FileMode.Open)) { fs.Seek(file.Offset.Value, SeekOrigin.Begin); using (var limitedStream = new LimitedStream(fs, file.Size.Value)) { ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv); using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read)) { using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) { using (var fileWritter = new FileStream(destPath, FileMode.Create)) { Streams.Copy(gzipStream, fileWritter); if (Platform.IsPosix()) { Chmod.SetMode(file.Mode.Substring(3), destPath); } } } } } } DebugLogger.Log("File " + file.Name + " unpacked successfully!"); }
private void UnpackRegularFile(Pack1Meta.FileEntry file, Action <double> onProgress) { string destPath = Path.Combine(_destinationDirPath, file.Name + _suffix); DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath); Files.CreateParents(destPath); RijndaelManaged rijn = new RijndaelManaged { Mode = CipherMode.CBC, Padding = PaddingMode.None, KeySize = 256 }; using (var fs = new FileStream(_packagePath, FileMode.Open)) { fs.Seek(file.Offset.Value, SeekOrigin.Begin); using (var limitedStream = new LimitedStream(fs, file.Size.Value)) { ICryptoTransform decryptor = rijn.CreateDecryptor(_key, _iv); using (var cryptoStream = new CryptoStream(limitedStream, decryptor, CryptoStreamMode.Read)) { using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) { try { using (var fileWritter = new FileStream(destPath, FileMode.Create)) { long bytesProcessed = 0; const int bufferSize = 131072; var buffer = new byte[bufferSize]; int count; while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) { fileWritter.Write(buffer, 0, count); bytesProcessed += count; onProgress(bytesProcessed / (double)file.Size.Value); } if (Platform.IsPosix()) { Chmod.SetMode(file.Mode.Substring(3), destPath); } } } catch (Exception e) { DebugLogger.LogException(e); var ravenClient = new RavenClient("https://*****:*****@sentry.io/175617"); var sentryEvent = new SentryEvent(e); var logManager = PatcherLogManager.Instance; PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString()); ravenClient.Capture(sentryEvent); throw; } } } } } DebugLogger.Log("File " + file.Name + " unpacked successfully!"); }