1
- using System . Diagnostics ;
2
- using System . Diagnostics . CodeAnalysis ;
1
+ using System . Diagnostics . CodeAnalysis ;
3
2
using System . Text ;
4
3
using System . Text . RegularExpressions ;
5
4
using NLog ;
@@ -59,8 +58,8 @@ public static string SevenZipFileName
59
58
public static async Task < ArchiveInfo > TestArchive ( string archivePath )
60
59
{
61
60
var process = ProcessRunner . StartAnsiProcess ( SevenZipPath , new [ ] { "t" , archivePath } ) ;
62
- await process . WaitForExitAsync ( ) ;
63
- var output = await process . StandardOutput . ReadToEndAsync ( ) ;
61
+ await process . WaitForExitAsync ( ) . ConfigureAwait ( false ) ;
62
+ var output = await process . StandardOutput . ReadToEndAsync ( ) . ConfigureAwait ( false ) ;
64
63
var matches = Regex7ZOutput ( ) . Matches ( output ) ;
65
64
var size = ulong . Parse ( matches [ 0 ] . Value ) ;
66
65
var compressed = ulong . Parse ( matches [ 1 ] . Value ) ;
@@ -86,11 +85,11 @@ public static async Task AddToArchive7Z(string archivePath, string sourceDirecto
86
85
87
86
public static async Task < ArchiveInfo > Extract7Z ( string archivePath , string extractDirectory )
88
87
{
88
+ var args =
89
+ $ "x { ProcessRunner . Quote ( archivePath ) } -o{ ProcessRunner . Quote ( extractDirectory ) } -y";
90
+
89
91
var result = await ProcessRunner
90
- . GetProcessResultAsync (
91
- SevenZipPath ,
92
- new [ ] { "x" , archivePath , "-o" + ProcessRunner . Quote ( extractDirectory ) , "-y" }
93
- )
92
+ . GetProcessResultAsync ( SevenZipPath , args )
94
93
. ConfigureAwait ( false ) ;
95
94
96
95
result . EnsureSuccessExitCode ( ) ;
@@ -185,7 +184,7 @@ public static async Task<ArchiveInfo> Extract7ZTar(string archivePath, string ex
185
184
throw new ArgumentException ( "Archive must be a zipped tar." ) ;
186
185
}
187
186
// Extract the tar.gz to tar
188
- await Extract7Z ( archivePath , extractDirectory ) ;
187
+ await Extract7Z ( archivePath , extractDirectory ) . ConfigureAwait ( false ) ;
189
188
190
189
// Extract the tar
191
190
var tarPath = Path . Combine ( extractDirectory , Path . GetFileNameWithoutExtension ( archivePath ) ) ;
@@ -196,7 +195,7 @@ public static async Task<ArchiveInfo> Extract7ZTar(string archivePath, string ex
196
195
197
196
try
198
197
{
199
- return await Extract7Z ( tarPath , extractDirectory ) ;
198
+ return await Extract7Z ( tarPath , extractDirectory ) . ConfigureAwait ( false ) ;
200
199
}
201
200
finally
202
201
{
@@ -215,11 +214,11 @@ public static async Task<ArchiveInfo> Extract7ZAuto(string archivePath, string e
215
214
{
216
215
if ( archivePath . EndsWith ( ".tar.gz" ) )
217
216
{
218
- return await Extract7ZTar ( archivePath , extractDirectory ) ;
217
+ return await Extract7ZTar ( archivePath , extractDirectory ) . ConfigureAwait ( false ) ;
219
218
}
220
219
else
221
220
{
222
- return await Extract7Z ( archivePath , extractDirectory ) ;
221
+ return await Extract7Z ( archivePath , extractDirectory ) . ConfigureAwait ( false ) ;
223
222
}
224
223
}
225
224
@@ -241,7 +240,7 @@ public static async Task Extract(
241
240
var count = 0ul ;
242
241
243
242
// Get true size
244
- var ( total , _) = await TestArchive ( archivePath ) ;
243
+ var ( total , _) = await TestArchive ( archivePath ) . ConfigureAwait ( false ) ;
245
244
246
245
// If not available, use the size of the archive file
247
246
if ( total == 0 )
@@ -266,32 +265,34 @@ public static async Task Extract(
266
265
} ;
267
266
}
268
267
269
- await Task . Factory . StartNew (
270
- ( ) =>
271
- {
272
- var extractOptions = new ExtractionOptions
268
+ await Task . Factory
269
+ . StartNew (
270
+ ( ) =>
273
271
{
274
- Overwrite = true ,
275
- ExtractFullPath = true ,
276
- } ;
277
- using var stream = File . OpenRead ( archivePath ) ;
278
- using var archive = ReaderFactory . Open ( stream ) ;
272
+ var extractOptions = new ExtractionOptions
273
+ {
274
+ Overwrite = true ,
275
+ ExtractFullPath = true ,
276
+ } ;
277
+ using var stream = File . OpenRead ( archivePath ) ;
278
+ using var archive = ReaderFactory . Open ( stream ) ;
279
279
280
- // Start the progress reporting timer
281
- progressMonitor ? . Start ( ) ;
280
+ // Start the progress reporting timer
281
+ progressMonitor ? . Start ( ) ;
282
282
283
- while ( archive . MoveToNextEntry ( ) )
284
- {
285
- var entry = archive . Entry ;
286
- if ( ! entry . IsDirectory )
283
+ while ( archive . MoveToNextEntry ( ) )
287
284
{
288
- count += ( ulong ) entry . CompressedSize ;
285
+ var entry = archive . Entry ;
286
+ if ( ! entry . IsDirectory )
287
+ {
288
+ count += ( ulong ) entry . CompressedSize ;
289
+ }
290
+ archive . WriteEntryToDirectory ( outputDirectory , extractOptions ) ;
289
291
}
290
- archive . WriteEntryToDirectory ( outputDirectory , extractOptions ) ;
291
- }
292
- } ,
293
- TaskCreationOptions . LongRunning
294
- ) ;
292
+ } ,
293
+ TaskCreationOptions . LongRunning
294
+ )
295
+ . ConfigureAwait ( false ) ;
295
296
296
297
progress ? . Report ( new ProgressReport ( progress : 1 , message : "Done extracting" ) ) ;
297
298
progressMonitor ? . Stop ( ) ;
@@ -305,7 +306,7 @@ await Task.Factory.StartNew(
305
306
public static async Task ExtractManaged ( string archivePath , string outputDirectory )
306
307
{
307
308
await using var stream = File . OpenRead ( archivePath ) ;
308
- await ExtractManaged ( stream , outputDirectory ) ;
309
+ await ExtractManaged ( stream , outputDirectory ) . ConfigureAwait ( false ) ;
309
310
}
310
311
311
312
/// <summary>
@@ -381,7 +382,7 @@ public static async Task ExtractManaged(Stream stream, string outputDirectory)
381
382
// Write file
382
383
await using var entryStream = reader . OpenEntryStream ( ) ;
383
384
await using var fileStream = File . Create ( outputPath ) ;
384
- await entryStream . CopyToAsync ( fileStream ) ;
385
+ await entryStream . CopyToAsync ( fileStream ) . ConfigureAwait ( false ) ;
385
386
}
386
387
}
387
388
}
0 commit comments