1
1
function Test-7zipRequirement {
2
2
[CmdletBinding (DefaultParameterSetName = " URL" )]
3
3
[OutputType ([Boolean ])]
4
- param (
4
+ param (
5
5
[Parameter (Mandatory = $true , ParameterSetName = " URL" )]
6
6
[String []]
7
7
$URL ,
@@ -23,7 +23,7 @@ function Test-7zipRequirement {
23
23
function Test-LessmsiRequirement {
24
24
[CmdletBinding ()]
25
25
[OutputType ([Boolean ])]
26
- param (
26
+ param (
27
27
[Parameter (Mandatory = $true )]
28
28
[String []]
29
29
$URL
@@ -37,48 +37,53 @@ function Test-LessmsiRequirement {
37
37
38
38
function Expand-7zipArchive {
39
39
[CmdletBinding ()]
40
- param (
40
+ param (
41
41
[Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )]
42
42
[String ]
43
43
$Path ,
44
44
[Parameter (Position = 1 )]
45
45
[String ]
46
46
$DestinationPath = (Split-Path $Path ),
47
- [ValidateSet (" All" , " Skip" , " Rename" )]
48
- [String ]
49
- $Overwrite ,
50
47
[Parameter (ValueFromRemainingArguments = $true )]
51
48
[String ]
52
49
$Switches ,
50
+ [ValidateSet (" All" , " Skip" , " Rename" )]
51
+ [String ]
52
+ $Overwrite ,
53
53
[Switch ]
54
54
$Removal
55
55
)
56
- $LogLocation = " $ ( Split-Path $Path ) \7zip.log"
57
- switch ($Overwrite ) {
58
- " All" { $Switches += " -aoa" }
59
- " Skip" { $Switches += " -aos" }
60
- " Rename" { $Switches += " -aou" }
61
- }
62
56
if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) {
63
57
try {
64
- 7z x " $Path " - o " $DestinationPath " ( -split $Switches ) - y | Out-File $LogLocation
58
+ $7zPath = ( Get-Command ' 7z ' - CommandType Application | Select-Object - First 1 ).Source
65
59
} catch [System.Management.Automation.CommandNotFoundException ] {
66
60
abort " Cannot find external 7-Zip (7z.exe) while '7ZIPEXTRACT_USE_EXTERNAL' is 'true'!`n Run 'scoop config 7ZIPEXTRACT_USE_EXTERNAL false' or install 7-Zip manually and try again."
67
61
}
68
62
} else {
69
- & (Get-HelperPath - Helper 7zip) x " $Path " - o" $DestinationPath " (-split $Switches ) - y | Out-File $LogLocation
63
+ $7zPath = Get-HelperPath - Helper 7zip
64
+ }
65
+ $LogPath = " $ ( Split-Path $Path ) \7zip.log"
66
+ $ArgList = @ (' x' , " `" $Path `" " , " -o`" $DestinationPath `" " , ' -y' )
67
+ if ($Switches ) {
68
+ $ArgList += (-split $Switches )
70
69
}
71
- if ($LASTEXITCODE -ne 0 ) {
72
- abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogLocation ) "
70
+ switch ($Overwrite ) {
71
+ " All" { $ArgList += " -aoa" }
72
+ " Skip" { $ArgList += " -aos" }
73
+ " Rename" { $ArgList += " -aou" }
74
+ }
75
+ $Status = Invoke-ExternalCommand $7zPath $ArgList - LogPath $LogPath
76
+ if (! $Status ) {
77
+ abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogPath ) "
73
78
}
74
- if (Test-Path $LogLocation ) {
75
- Remove-Item $LogLocation - Force
79
+ if (Test-Path $LogPath ) {
80
+ Remove-Item $LogPath - Force
76
81
}
77
- if ((strip_ext $Path ) -match ' \.tar$' -or $Path -match ' \.tgz $' ) {
82
+ if ((strip_ext $Path ) -match ' \.tar$' -or $Path -match ' \.t[abgpx]z2? $' ) {
78
83
# Check for tar
79
- $ArchivedFile = & ( Get-HelperPath - Helper 7zip) l " $Path "
80
- if ($LASTEXITCODE -eq 0 ) {
81
- $TarFile = $ArchivedFile [ -3 ] -replace ' .{53}(.*)' , ' $1' # get inner tar file name
84
+ $Status = Invoke-ExternalCommand $7zPath @ ( ' l ' , " `" $Path `" " ) - LogPath $LogPath
85
+ if ($Status ) {
86
+ $TarFile = ( Get-Content - Path $LogPath )[ -4 ] -replace ' .{53}(.*)' , ' $1' # get inner tar file name
82
87
Expand-7zipArchive " $DestinationPath \$TarFile " $DestinationPath - Removal
83
88
} else {
84
89
abort " Failed to list files in $Path .`n Not a 7-Zip supported archive file."
@@ -92,34 +97,42 @@ function Expand-7zipArchive {
92
97
93
98
function Expand-MsiArchive {
94
99
[CmdletBinding ()]
95
- param (
100
+ param (
96
101
[Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )]
97
102
[String ]
98
103
$Path ,
99
104
[Parameter (Position = 1 )]
100
105
[String ]
101
106
$DestinationPath = (Split-Path $Path ),
107
+ [Parameter (ValueFromRemainingArguments = $true )]
108
+ [String ]
109
+ $Switches ,
102
110
[Switch ]
103
111
$Removal
104
112
)
105
- $LogLocation = " $ ( Split-Path $Path ) \msi.log"
106
113
if ((get_config MSIEXTRACT_USE_LESSMSI)) {
107
- & (Get-HelperPath - Helper Lessmsi) x " $Path " " $DestinationPath \" | Out-File $LogLocation
108
- if ($LASTEXITCODE -ne 0 ) {
109
- abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogLocation ) "
110
- }
111
- if (Test-Path " $DestinationPath \SourceDir" ) {
112
- movedir " $DestinationPath \SourceDir" " $DestinationPath " | Out-Null
113
- }
114
+ $MsiPath = Get-HelperPath - Helper Lessmsi
115
+ $ArgList = @ (' x' , " `" $Path `" " , " `" $DestinationPath \\`" " )
114
116
} else {
115
- $ok = run ' msiexec' @ (' /a' , " `" $Path `" " , ' /qn' , " TARGETDIR=`" $DestinationPath `" " , " /lwe `" $LogLocation `" " )
116
- if (! $ok ) {
117
- abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogLocation ) "
118
- }
117
+ $MsiPath = ' msiexec.exe'
118
+ $ArgList = @ (' /a' , " `" $Path `" " , ' /qn' , " TARGETDIR=`" $DestinationPath `" " )
119
+ }
120
+ $LogPath = " $ ( Split-Path $Path ) \msi.log"
121
+ if ($Switches ) {
122
+ $ArgList += (-split $Switches )
123
+ }
124
+ $Status = Invoke-ExternalCommand $MsiPath $ArgList - LogPath $LogPath
125
+ if (! $Status ) {
126
+ abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogPath ) "
127
+ }
128
+ if (Test-Path " $DestinationPath \SourceDir" ) {
129
+ movedir " $DestinationPath \SourceDir" " $DestinationPath " | Out-Null
130
+ }
131
+ if (($DestinationPath -ne (Split-Path $Path )) -and (Test-Path " $DestinationPath \$ ( fname $Path ) " )) {
119
132
Remove-Item " $DestinationPath \$ ( fname $Path ) " - Force
120
133
}
121
- if (Test-Path $LogLocation ) {
122
- Remove-Item $LogLocation - Force
134
+ if (Test-Path $LogPath ) {
135
+ Remove-Item $LogPath - Force
123
136
}
124
137
if ($Removal ) {
125
138
# Remove original archive file
@@ -129,7 +142,7 @@ function Expand-MsiArchive {
129
142
130
143
function Expand-InnoArchive {
131
144
[CmdletBinding ()]
132
- param (
145
+ param (
133
146
[Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )]
134
147
[String ]
135
148
$Path ,
@@ -142,13 +155,17 @@ function Expand-InnoArchive {
142
155
[Switch ]
143
156
$Removal
144
157
)
145
- $LogLocation = " $ ( Split-Path $Path ) \innounp.log"
146
- & ( Get-HelperPath - Helper Innounp) - x - d " $DestinationPath " - c ' {app} ' " $Path " ( -split $Switches ) - y | Out-File $LogLocation
147
- if ($LASTEXITCODE -ne 0 ) {
148
- abort " Failed to extract files from $Path . `n Log file: `n $ ( friendly_path $LogLocation ) "
158
+ $LogPath = " $ ( Split-Path $Path ) \innounp.log"
159
+ $ArgList = @ ( ' -x ' , " -d ` "$DestinationPath `" " , " -c` {app`} " , " `" $Path `" " , ' -y ' )
160
+ if ($Switches ) {
161
+ $ArgList += ( -split $Switches )
149
162
}
150
- if (Test-Path $LogLocation ) {
151
- Remove-Item $LogLocation - Force
163
+ $Status = Invoke-ExternalCommand (Get-HelperPath - Helper Innounp) $ArgList - LogPath $LogPath
164
+ if (! $Status ) {
165
+ abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogPath ) "
166
+ }
167
+ if (Test-Path $LogPath ) {
168
+ Remove-Item $LogPath - Force
152
169
}
153
170
if ($Removal ) {
154
171
# Remove original archive file
@@ -158,7 +175,7 @@ function Expand-InnoArchive {
158
175
159
176
function Expand-ZipArchive {
160
177
[CmdletBinding ()]
161
- param (
178
+ param (
162
179
[Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )]
163
180
[String ]
164
181
$Path ,
@@ -211,16 +228,23 @@ function Expand-DarkArchive {
211
228
[Parameter (Position = 1 )]
212
229
[String ]
213
230
$DestinationPath = (Split-Path $Path ),
231
+ [Parameter (ValueFromRemainingArguments = $true )]
232
+ [String ]
233
+ $Switches ,
214
234
[Switch ]
215
235
$Removal
216
236
)
217
- $LogLocation = " $ ( Split-Path $Path ) \dark.log"
218
- & (Get-HelperPath - Helper Dark) - nologo - x " $Path " " $DestinationPath " | Out-File $LogLocation
219
- if ($LASTEXITCODE -ne 0 ) {
220
- abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogLocation ) "
237
+ $LogPath = " $ ( Split-Path $Path ) \dark.log"
238
+ $ArgList = @ (' -nologo' , " -x `" $DestinationPath `" " , " `" $Path `" " )
239
+ if ($Switches ) {
240
+ $ArgList += (-split $Switches )
241
+ }
242
+ $Status = Invoke-ExternalCommand (Get-HelperPath - Helper Dark) $ArgList - LogPath $LogPath
243
+ if (! $Status ) {
244
+ abort " Failed to extract files from $Path .`n Log file:`n $ ( friendly_path $LogPath ) "
221
245
}
222
- if (Test-Path $LogLocation ) {
223
- Remove-Item $LogLocation - Force
246
+ if (Test-Path $LogPath ) {
247
+ Remove-Item $LogPath - Force
224
248
}
225
249
if ($Removal ) {
226
250
# Remove original archive file
0 commit comments