@@ -223,18 +223,30 @@ private void UnpackRegularFile(Pack1Meta.FileEntry file, Action<double> onProgre
223223 KeySize = 256
224224 } ;
225225
226- ICryptoTransform decryptor = rijn . CreateDecryptor ( _key , _iv ) ;
226+ var aesAlg = new AesCryptoServiceProvider
227+ {
228+ IV = _iv ,
229+ Key = _key
230+ } ;
231+
232+ ICryptoTransform decryptor = aesAlg . CreateDecryptor (
233+ aesAlg . Key ,
234+ aesAlg . IV ) ;
235+
227236 DecompressorCreator decompressorCreator = ResolveDecompressor ( _metaData ) ;
228237
229238 using ( var fs = new FileStream ( _packagePath , FileMode . Open ) )
230239 {
231240 fs . Seek ( file . Offset . Value - _range . Start , SeekOrigin . Begin ) ;
232241
233- using ( var limitedStream = new LimitedStream ( fs , file . Size . Value ) )
242+ using ( var limitedStream = new BufferedStream ( new LimitedStream ( fs , file . Size . Value ) , 2 * 1024 * 1024 ) )
234243 {
235- using ( var target = new FileStream ( destPath , FileMode . Create ) )
244+ // using (var bufferedLimitedStream = new ThreadBufferedStream(limitedStream, 8 * 1024 * 1024 ))
236245 {
237- ExtractFileFromStream ( limitedStream , target , file . Size . Value , decryptor , decompressorCreator , onProgress , cancellationToken ) ;
246+ using ( var target = new FileStream ( destPath , FileMode . Create ) )
247+ {
248+ ExtractFileFromStream ( limitedStream , target , file . Size . Value , decryptor , decompressorCreator , onProgress , cancellationToken ) ;
249+ }
238250 }
239251
240252 if ( Platform . IsPosix ( ) )
@@ -265,7 +277,7 @@ private Stream CreateGzipDecompressor(Stream source)
265277 }
266278
267279 private void ExtractFileFromStream (
268- LimitedStream sourceStream ,
280+ Stream sourceStream ,
269281 Stream targetStream ,
270282 long fileSize ,
271283 ICryptoTransform decryptor ,
@@ -275,44 +287,50 @@ private void ExtractFileFromStream(
275287 {
276288 using ( var cryptoStream = new CryptoStream ( sourceStream , decryptor , CryptoStreamMode . Read ) )
277289 {
278- using ( var wrapperStream = new GZipReadWrapperStream ( cryptoStream ) )
290+ using ( var bufferedCryptoStream = new BufferedStream ( new ThreadBufferedStream ( cryptoStream , 2 * 1024 * 1024 ) , 2 * 1024 * 1024 ) )
279291 {
280- using ( Stream decompressionStream = createDecompressor ( wrapperStream ) )
292+ // using (var wrapperStream = new GZipReadWrapperStream(bufferedCryptoStream ))
281293 {
282- try
294+ using ( Stream decompressionStream = createDecompressor ( bufferedCryptoStream ) )
283295 {
284- const int bufferSize = 128 * 1024 ;
285- var buffer = new byte [ bufferSize ] ;
286- int count ;
287-
288- while ( ( count = decompressionStream . Read ( buffer , 0 , buffer . Length ) ) > 0 )
296+ using ( var bufferedDecompressionStream = new ThreadBufferedStream ( decompressionStream , 4 * 1024 * 1024 ) )
289297 {
290- cancellationToken . ThrowIfCancellationRequested ( ) ;
291- targetStream . Write ( buffer , 0 , count ) ;
292-
293- long bytesProcessed = sourceStream . Limit - sourceStream . BytesLeft ;
294- onProgress ( bytesProcessed / ( double ) fileSize ) ;
298+ try
299+ {
300+ const int bufferSize = 2 * 1024 * 1024 ;
301+ var buffer = new byte [ bufferSize ] ;
302+ int count ;
303+
304+ while ( ( count = bufferedDecompressionStream . Read ( buffer , 0 , buffer . Length ) ) > 0 )
305+ {
306+ cancellationToken . ThrowIfCancellationRequested ( ) ;
307+ targetStream . Write ( buffer , 0 , count ) ;
308+
309+ long bytesProcessed = sourceStream . Position ;
310+ onProgress ( bytesProcessed / ( double ) fileSize ) ;
311+ }
312+ }
313+ catch ( OperationCanceledException )
314+ {
315+ throw ;
316+ }
317+ catch ( Exception e )
318+ {
319+ DebugLogger . LogException ( e ) ;
320+
321+ PatcherLogManager logManager = PatcherLogManager . Instance ;
322+ PatcherLogSentryRegistry sentryRegistry = logManager . SentryRegistry ;
323+ RavenClient ravenClient = sentryRegistry . RavenClient ;
324+
325+ var sentryEvent = new SentryEvent ( e ) ;
326+ PatcherLogSentryRegistry . AddDataToSentryEvent ( sentryEvent ,
327+ logManager . Storage . Guid . ToString ( ) ) ;
328+ ravenClient . Capture ( sentryEvent ) ;
329+
330+ throw ;
331+ }
295332 }
296333 }
297- catch ( OperationCanceledException )
298- {
299- throw ;
300- }
301- catch ( Exception e )
302- {
303- DebugLogger . LogException ( e ) ;
304-
305- PatcherLogManager logManager = PatcherLogManager . Instance ;
306- PatcherLogSentryRegistry sentryRegistry = logManager . SentryRegistry ;
307- RavenClient ravenClient = sentryRegistry . RavenClient ;
308-
309- var sentryEvent = new SentryEvent ( e ) ;
310- PatcherLogSentryRegistry . AddDataToSentryEvent ( sentryEvent , logManager . Storage . Guid . ToString ( ) ) ;
311- ravenClient . Capture ( sentryEvent ) ;
312-
313- throw ;
314- }
315-
316334 }
317335 }
318336 }
0 commit comments