Skip to content

Commit

Permalink
Patch(decompress): Allow other args to be passthrough (#3411)
Browse files Browse the repository at this point in the history
ref: ScoopInstaller/Extras#2021 (comment), #3204 (comment)

- Add new param `Overwrite` to `Expand-7ZipArchive`, with following values
  - "All": 7z param `-aoa`, overwrite All existing files without prompt, behave the same with default
  - "Skip": 7z param `-aos`, Skip extracting of existing files
  - "Rename": 7z param `-aou`, aUto rename extracting file
- Add new param `Switches` to `Expand-7ZipArchive` and `Expand-InnoArchive`
  - It could pass all unrecognized params to `7z` and `innounp`
- Patch `extract_7zip` and `unpack_inno` to adapt to `Expand-XXX`

Usage: ScoopInstaller/Extras#2021, ScoopInstaller/Extras#2070
  • Loading branch information
niheaven authored and r15ch13 committed Apr 29, 2019
1 parent 70d6d9c commit 34c26aa
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/decompress.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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)"
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 34c26aa

Please sign in to comment.