|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Diagnostics; |
|
|
|
|
|
|
|
using System.Diagnostics.CodeAnalysis; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using NLog; |
|
|
|
using NLog; |
|
|
@ -80,14 +81,33 @@ public static partial class ArchiveHelper |
|
|
|
{ |
|
|
|
{ |
|
|
|
var args = |
|
|
|
var args = |
|
|
|
$"x {ProcessRunner.Quote(archivePath)} -o{ProcessRunner.Quote(extractDirectory)} -y"; |
|
|
|
$"x {ProcessRunner.Quote(archivePath)} -o{ProcessRunner.Quote(extractDirectory)} -y"; |
|
|
|
var process = ProcessRunner.StartProcess(SevenZipPath, args); |
|
|
|
|
|
|
|
|
|
|
|
Logger.Debug($"Starting process '{SevenZipPath}' with arguments '{args}'"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using var process = new Process(); |
|
|
|
|
|
|
|
process.StartInfo = new ProcessStartInfo(SevenZipPath, args) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
RedirectStandardOutput = true, |
|
|
|
|
|
|
|
RedirectStandardError = true, |
|
|
|
|
|
|
|
UseShellExecute = false, |
|
|
|
|
|
|
|
CreateNoWindow = true |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await ProcessRunner.WaitForExitConditionAsync(process); |
|
|
|
await ProcessRunner.WaitForExitConditionAsync(process); |
|
|
|
var output = await process.StandardOutput.ReadToEndAsync(); |
|
|
|
var output = await process.StandardOutput.ReadToEndAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
var matches = Regex7ZOutput().Matches(output); |
|
|
|
var matches = Regex7ZOutput().Matches(output); |
|
|
|
var size = ulong.Parse(matches[0].Value); |
|
|
|
var size = ulong.Parse(matches[0].Value); |
|
|
|
var compressed = ulong.Parse(matches[1].Value); |
|
|
|
var compressed = ulong.Parse(matches[1].Value); |
|
|
|
return new ArchiveInfo(size, compressed); |
|
|
|
return new ArchiveInfo(size, compressed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new Exception($"Could not parse 7z output [{e.Message}]: {output.ToRepr()}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static async Task<ArchiveInfo> Extract7Z(string archivePath, string extractDirectory, IProgress<ProgressReport> progress) |
|
|
|
public static async Task<ArchiveInfo> Extract7Z(string archivePath, string extractDirectory, IProgress<ProgressReport> progress) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -110,18 +130,27 @@ public static partial class ArchiveHelper |
|
|
|
// Need -bsp1 for progress reports |
|
|
|
// Need -bsp1 for progress reports |
|
|
|
var args = |
|
|
|
var args = |
|
|
|
$"x {ProcessRunner.Quote(archivePath)} -o{ProcessRunner.Quote(extractDirectory)} -y -bsp1"; |
|
|
|
$"x {ProcessRunner.Quote(archivePath)} -o{ProcessRunner.Quote(extractDirectory)} -y -bsp1"; |
|
|
|
var process = ProcessRunner.StartProcess(SevenZipPath, args, outputDataReceived: onOutput); |
|
|
|
Logger.Debug($"Starting process '{SevenZipPath}' with arguments '{args}'"); |
|
|
|
|
|
|
|
|
|
|
|
await process.WaitForExitAsync(); |
|
|
|
var process = ProcessRunner.StartProcess(SevenZipPath, args, outputDataReceived: onOutput); |
|
|
|
|
|
|
|
await ProcessRunner.WaitForExitConditionAsync(process); |
|
|
|
|
|
|
|
|
|
|
|
progress.Report(new ProgressReport(1, "Finished extracting", type: ProgressType.Extract)); |
|
|
|
progress.Report(new ProgressReport(1, "Finished extracting", type: ProgressType.Extract)); |
|
|
|
|
|
|
|
|
|
|
|
var output = outputStore.ToString(); |
|
|
|
var output = outputStore.ToString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
var matches = Regex7ZOutput().Matches(output); |
|
|
|
var matches = Regex7ZOutput().Matches(output); |
|
|
|
var size = ulong.Parse(matches[0].Value); |
|
|
|
var size = ulong.Parse(matches[0].Value); |
|
|
|
var compressed = ulong.Parse(matches[1].Value); |
|
|
|
var compressed = ulong.Parse(matches[1].Value); |
|
|
|
return new ArchiveInfo(size, compressed); |
|
|
|
return new ArchiveInfo(size, compressed); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
throw new Exception($"Could not parse 7z output [{e.Message}]: {output.ToRepr()}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
|
/// Extracts a zipped tar (i.e. '.tar.gz') archive. |
|
|
|
/// Extracts a zipped tar (i.e. '.tar.gz') archive. |
|
|
|