1
- function Test-7zipRequirement {
2
- [CmdletBinding (DefaultParameterSetName = " URL" )]
3
- [OutputType ([Boolean ])]
4
- param (
5
- [Parameter (Mandatory = $true , ParameterSetName = " URL" )]
6
- [String []]
7
- $URL ,
8
- [Parameter (Mandatory = $true , ParameterSetName = " File" )]
9
- [String ]
10
- $File
11
- )
12
- if ($URL ) {
13
- if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) {
14
- return $false
15
- } else {
16
- return ($URL | Where-Object { Test-7zipRequirement - File $_ }).Count -gt 0
17
- }
18
- } else {
19
- return $File -match ' \.((gz)|(tar)|(t[abgpx]z2?)|(lzma)|(bz2?)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))(\.[^.]+)?$'
20
- }
21
- }
22
-
23
- function Test-ZstdRequirement {
24
- [CmdletBinding (DefaultParameterSetName = " URL" )]
25
- [OutputType ([Boolean ])]
26
- param (
27
- [Parameter (Mandatory = $true , ParameterSetName = " URL" )]
28
- [String []]
29
- $URL ,
30
- [Parameter (Mandatory = $true , ParameterSetName = " File" )]
31
- [String ]
32
- $File
33
- )
34
- if ($URL ) {
35
- return ($URL | Where-Object { Test-ZstdRequirement - File $_ }).Count -gt 0
36
- } else {
37
- return $File -match ' \.zst$'
38
- }
39
- }
40
-
41
- function Test-LessmsiRequirement {
42
- [CmdletBinding ()]
43
- [OutputType ([Boolean ])]
44
- param (
45
- [Parameter (Mandatory = $true )]
46
- [String []]
47
- $URL
48
- )
49
- if ((get_config MSIEXTRACT_USE_LESSMSI)) {
50
- return ($URL | Where-Object { $_ -match ' \.msi$' }).Count -gt 0
51
- } else {
52
- return $false
53
- }
54
- }
55
-
56
1
function Expand-7zipArchive {
57
2
[CmdletBinding ()]
58
3
param (
@@ -67,17 +12,17 @@ function Expand-7zipArchive {
67
12
[Parameter (ValueFromRemainingArguments = $true )]
68
13
[String ]
69
14
$Switches ,
70
- [ValidateSet (" All" , " Skip" , " Rename" )]
15
+ [ValidateSet (' All' , ' Skip' , ' Rename' )]
71
16
[String ]
72
17
$Overwrite ,
73
18
[Switch ]
74
19
$Removal
75
20
)
76
21
if ((get_config 7ZIPEXTRACT_USE_EXTERNAL)) {
77
22
try {
78
- $7zPath = (Get-Command ' 7z' - CommandType Application | Select-Object - First 1 ).Source
23
+ $7zPath = (Get-Command ' 7z' - CommandType Application - ErrorAction Stop | Select-Object - First 1 ).Source
79
24
} catch [System.Management.Automation.CommandNotFoundException ] {
80
- 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."
25
+ abort " `n 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."
81
26
}
82
27
} else {
83
28
$7zPath = Get-HelperPath - Helper 7zip
@@ -92,9 +37,9 @@ function Expand-7zipArchive {
92
37
$ArgList += (-split $Switches )
93
38
}
94
39
switch ($Overwrite ) {
95
- " All" { $ArgList += " -aoa" }
96
- " Skip" { $ArgList += " -aos" }
97
- " Rename" { $ArgList += " -aou" }
40
+ ' All' { $ArgList += ' -aoa' }
41
+ ' Skip' { $ArgList += ' -aos' }
42
+ ' Rename' { $ArgList += ' -aou' }
98
43
}
99
44
$Status = Invoke-ExternalCommand $7zPath $ArgList - LogPath $LogPath
100
45
if (! $Status ) {
@@ -187,7 +132,7 @@ function Expand-MsiArchive {
187
132
[Switch ]
188
133
$Removal
189
134
)
190
- $DestinationPath = $DestinationPath.TrimEnd (" \ " )
135
+ $DestinationPath = $DestinationPath.TrimEnd (' \ ' )
191
136
if ($ExtractDir ) {
192
137
$OriDestinationPath = $DestinationPath
193
138
$DestinationPath = " $DestinationPath \_tmp"
@@ -248,9 +193,9 @@ function Expand-InnoArchive {
248
193
$LogPath = " $ ( Split-Path $Path ) \innounp.log"
249
194
$ArgList = @ (' -x' , " -d`" $DestinationPath `" " , " `" $Path `" " , ' -y' )
250
195
switch - Regex ($ExtractDir ) {
251
- " ^[^{].*" { $ArgList += " -c{app}\$ExtractDir " }
252
- " ^{.*" { $ArgList += " -c$ExtractDir " }
253
- Default { $ArgList += " -c{app}" }
196
+ ' ^[^{].*' { $ArgList += " -c{app}\$ExtractDir " }
197
+ ' ^{.*' { $ArgList += " -c$ExtractDir " }
198
+ Default { $ArgList += ' -c{app}' }
254
199
}
255
200
if ($Switches ) {
256
201
$ArgList += (-split $Switches )
@@ -286,34 +231,7 @@ function Expand-ZipArchive {
286
231
$OriDestinationPath = $DestinationPath
287
232
$DestinationPath = " $DestinationPath \_tmp"
288
233
}
289
- # All methods to unzip the file require .NET4.5+
290
- if ($PSVersionTable.PSVersion.Major -lt 5 ) {
291
- Add-Type - AssemblyName System.IO.Compression.FileSystem
292
- try {
293
- [System.IO.Compression.ZipFile ]::ExtractToDirectory($Path , $DestinationPath )
294
- } catch [System.IO.PathTooLongException ] {
295
- # try to fall back to 7zip if path is too long
296
- if (Test-HelperInstalled - Helper 7zip) {
297
- Expand-7zipArchive $Path $DestinationPath - Removal
298
- return
299
- } else {
300
- abort " Unzip failed: Windows can't handle the long paths in this zip file.`n Run 'scoop install 7zip' and try again."
301
- }
302
- } catch [System.IO.IOException ] {
303
- if (Test-HelperInstalled - Helper 7zip) {
304
- Expand-7zipArchive $Path $DestinationPath - Removal
305
- return
306
- } else {
307
- abort " Unzip failed: Windows can't handle the file names in this zip file.`n Run 'scoop install 7zip' and try again."
308
- }
309
- } catch {
310
- abort " Unzip failed: $_ "
311
- }
312
- } else {
313
- # Use Expand-Archive to unzip in PowerShell 5+
314
- # Compatible with Pscx (https://github.com/Pscx/Pscx)
315
- Microsoft.PowerShell.Archive\Expand-Archive - Path $Path - DestinationPath $DestinationPath - Force
316
- }
234
+ Expand-Archive - Path $Path - DestinationPath $DestinationPath - Force
317
235
if ($ExtractDir ) {
318
236
movedir " $DestinationPath \$ExtractDir " $OriDestinationPath | Out-Null
319
237
Remove-Item $DestinationPath - Recurse - Force
@@ -356,23 +274,3 @@ function Expand-DarkArchive {
356
274
Remove-Item $Path - Force
357
275
}
358
276
}
359
-
360
- function extract_7zip ($path , $to , $removal ) {
361
- Show-DeprecatedWarning $MyInvocation ' Expand-7zipArchive'
362
- Expand-7zipArchive - Path $path - DestinationPath $to - Removal:$removal @args
363
- }
364
-
365
- function extract_msi ($path , $to , $removal ) {
366
- Show-DeprecatedWarning $MyInvocation ' Expand-MsiArchive'
367
- Expand-MsiArchive - Path $path - DestinationPath $to - Removal:$removal
368
- }
369
-
370
- function unpack_inno ($path , $to , $removal ) {
371
- Show-DeprecatedWarning $MyInvocation ' Expand-InnoArchive'
372
- Expand-InnoArchive - Path $path - DestinationPath $to - Removal:$removal @args
373
- }
374
-
375
- function extract_zip ($path , $to , $removal ) {
376
- Show-DeprecatedWarning $MyInvocation ' Expand-ZipArchive'
377
- Expand-ZipArchive - Path $path - DestinationPath $to - Removal:$removal
378
- }
0 commit comments