Skip to content

Commit 17253e4

Browse files
authored
Add Expand-DarkArchive and some other dependency features (#3450)
- Add `Expand-DarkArchive` helper function - Allow `dark.exe` from wixtoolset and `7zip-zstd` as valid helpers - Add warnings to 'scoop checkup' for missing unpackers - Auto detect dependencies from `pre_install`/`post_install` and `installer.script` by simply searching for the function names.
2 parents 5d5c7fa + 8463119 commit 17253e4

File tree

4 files changed

+95
-6
lines changed

4 files changed

+95
-6
lines changed

lib/core.ps1

+18-5
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,26 @@ function Get-HelperPath {
248248
$Helper
249249
)
250250

251+
$HelperPath = $null
251252
switch ($Helper) {
252-
'7zip' { Get-AppFilePath '7zip' '7z.exe' }
253-
'Lessmsi' { Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
254-
'Innounp' { Get-AppFilePath 'innounp' 'innounp.exe' }
255-
'Dark' { Get-AppFilePath 'dark' 'dark.exe' }
256-
'Aria2' { Get-AppFilePath 'aria2' 'aria2c.exe' }
253+
'7zip' {
254+
$HelperPath = Get-AppFilePath '7zip' '7z.exe'
255+
if([String]::IsNullOrEmpty($HelperPath)) {
256+
$HelperPath = Get-AppFilePath '7zip-zstd' '7z.exe'
257+
}
258+
}
259+
'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
260+
'Innounp' { $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe' }
261+
'Dark' {
262+
$HelperPath = Get-AppFilePath 'dark' 'dark.exe'
263+
if([String]::IsNullOrEmpty($HelperPath)) {
264+
$HelperPath = Get-AppFilePath 'wixtoolset' 'dark.exe'
265+
}
266+
}
267+
'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }
257268
}
269+
270+
return $HelperPath
258271
}
259272

260273
function Test-HelperInstalled {

lib/decompress.ps1

+26
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,32 @@ function Expand-ZipArchive {
202202
}
203203
}
204204

205+
function Expand-DarkArchive {
206+
[CmdletBinding()]
207+
param(
208+
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
209+
[String]
210+
$Path,
211+
[Parameter(Position = 1)]
212+
[String]
213+
$DestinationPath = (Split-Path $Path),
214+
[Switch]
215+
$Removal
216+
)
217+
$LogLocation = "$(Split-Path $Path)\dark.log"
218+
& (Get-HelperPath -Helper Dark) -nologo -x "$DestinationPath" "$Path" | Out-File $LogLocation
219+
if ($LASTEXITCODE -ne 0) {
220+
abort "Failed to extract files from $Path.`nLog file:`n $(friendly_path $LogLocation)"
221+
}
222+
if (Test-Path $LogLocation) {
223+
Remove-Item $LogLocation -Force
224+
}
225+
if ($Removal) {
226+
# Remove original archive file
227+
Remove-Item $Path -Force
228+
}
229+
}
230+
205231
function extract_7zip($path, $to, $removal) {
206232
Show-DeprecatedWarning $MyInvocation 'Expand-7zipArchive'
207233
Expand-7zipArchive -Path $path -DestinationPath $to -Removal:$removal @args

lib/depends.ps1

+36-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,31 @@ function runtime_deps($manifest) {
4949
if ($manifest.depends) { return $manifest.depends }
5050
}
5151

52+
function script_deps($script) {
53+
$deps = @()
54+
if($script -is [Array]) {
55+
$script = $script -join "`n"
56+
}
57+
if([String]::IsNullOrEmpty($script)) {
58+
return $deps
59+
}
60+
61+
if($script -like '*Expand-7zipArchive *' -or $script -like '*extract_7zip *') {
62+
$deps += '7zip'
63+
}
64+
if($script -like '*Expand-MsiArchive *' -or $script -like '*extract_msi *') {
65+
$deps += 'lessmsi'
66+
}
67+
if($script -like '*Expand-InnoArchive *' -or $script -like '*unpack_inno *') {
68+
$deps += 'innounp'
69+
}
70+
if($script -like '*Expand-DarkArchive *') {
71+
$deps += 'dark'
72+
}
73+
74+
return $deps
75+
}
76+
5277
function install_deps($manifest, $arch) {
5378
$deps = @()
5479

@@ -61,6 +86,16 @@ function install_deps($manifest, $arch) {
6186
if (!(Test-HelperInstalled -Helper Innounp) -and $manifest.innosetup) {
6287
$deps += 'innounp'
6388
}
89+
if (!(Test-HelperInstalled -Helper Dark)) {
90+
$deps += 'dark'
91+
}
6492

65-
return $deps
93+
$pre_install = arch_specific 'pre_install' $manifest $arch
94+
$installer = arch_specific 'installer' $manifest $arch
95+
$post_install = arch_specific 'post_install' $manifest $arch
96+
$deps += script_deps $pre_install
97+
$deps += script_deps $installer.script
98+
$deps += script_deps $post_install
99+
100+
return $deps | Select-Object -Unique
66101
}

libexec/scoop-checkup.ps1

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ $issues += !(check_windows_defender $true)
1313
$issues += !(check_main_bucket)
1414
$issues += !(check_long_paths)
1515

16+
if (!(Test-HelperInstalled -Helper 7zip)) {
17+
error "'7-Zip' is not installed! It's required for unpacking most programs. Please Run 'scoop install 7zip' or 'scoop install 7zip-zstd'."
18+
$issues++
19+
}
20+
21+
if (!(Test-HelperInstalled -Helper Innounp)) {
22+
error "'Inno Setup Unpacker' is not installed! It's required for unpacking InnoSetup files. Please run 'scoop install innounp'."
23+
$issues++
24+
}
25+
26+
if (!(Test-HelperInstalled -Helper Dark)) {
27+
error "'dark' is not installed! It's require for unpacking installers created with the WiX Toolset. Please run 'scoop install dark' or 'scoop install wixtoolset'."
28+
$issues++
29+
}
30+
1631
$globaldir = New-Object System.IO.DriveInfo($globaldir)
1732
if($globaldir.DriveFormat -ne 'NTFS') {
1833
error "Scoop requires an NTFS volume to work! Please point `$env:SCOOP_GLOBAL or 'globalPath' variable in '~/.config/scoop/config.json' to another Drive."

0 commit comments

Comments
 (0)