diff --git a/lib/decompress.ps1 b/lib/decompress.ps1 index cc585dac14..1117d98975 100644 --- a/lib/decompress.ps1 +++ b/lib/decompress.ps1 @@ -44,18 +44,29 @@ function Expand-7ZipArchive { [Parameter(Position = 1)] [String] $DestinationPath = (Split-Path $Path), + [ValidateSet("All", "Skip", "Rename")] + [String] + $Overwrite, + [Parameter(ValueFromRemainingArguments = $true)] + [String] + $Switches, [Switch] $Removal ) $LogLocation = "$(Split-Path $Path)\7zip.log" + switch ($Overwrite) { + "All" { $Switches += " -aoa" } + "Skip" { $Switches += " -aos" } + "Rename" { $Switches += " -aou" } + } if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) { try { - 7z x "$Path" -o"$DestinationPath" -y | Out-File $LogLocation + 7z x "$Path" -o"$DestinationPath" (-split $Switches) -y | Out-File $LogLocation } catch [System.Management.Automation.CommandNotFoundException] { abort "Cannot find external 7Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`nRun 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7Zip manually and try again." } } else { - &(file_path 7zip 7z.exe) x "$Path" -o"$DestinationPath" -y | Out-File $LogLocation + &(file_path 7zip 7z.exe) x "$Path" -o"$DestinationPath" (-split $Switches) -y | Out-File $LogLocation } if ($LASTEXITCODE -ne 0) { abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" @@ -125,11 +136,14 @@ function Expand-InnoArchive { [Parameter(Position = 1)] [String] $DestinationPath = (Split-Path $Path), + [Parameter(ValueFromRemainingArguments = $true)] + [String] + $Switches, [Switch] $Removal ) $LogLocation = "$(Split-Path $Path)\innounp.log" - &(file_path innounp innounp.exe) -x -d"$DestinationPath" -c'{app}' "$Path" -y | Out-File $LogLocation + &(file_path innounp innounp.exe) -x -d"$DestinationPath" -c'{app}' "$Path" (-split $Switches) -y | Out-File $LogLocation if ($LASTEXITCODE -ne 0) { abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)" } @@ -189,7 +203,7 @@ function Expand-ZipArchive { function extract_7zip($path, $to, $removal) { Show-DeprecatedWarning $MyInvocation 'Expand-7ZipArchive' - Expand-7ZipArchive -Path $path -DestinationPath $to -Removal:$removal + Expand-7ZipArchive -Path $path -DestinationPath $to -Removal:$removal @args } function extract_msi($path, $to, $removal) { @@ -199,7 +213,7 @@ function extract_msi($path, $to, $removal) { function unpack_inno($path, $to, $removal) { Show-DeprecatedWarning $MyInvocation 'Expand-InnoArchive' - Expand-InnoArchive -Path $path -DestinationPath $to -Removal:$removal + Expand-InnoArchive -Path $path -DestinationPath $to -Removal:$removal @args } function extract_zip($path, $to, $removal) {