-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decompress.ps1: Refactored (w/ install.ps1, core.ps1)
- Loading branch information
Showing
4 changed files
with
94 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,109 @@ | ||
function requires_7zip($manifest, $architecture) { | ||
foreach($dlurl in @(url $manifest $architecture)) { | ||
if(file_requires_7zip $dlurl) { return $true } | ||
foreach ($dlurl in @(url $manifest $architecture)) { | ||
if (file_requires_7zip $dlurl) { return $true } | ||
} | ||
} | ||
|
||
function requires_lessmsi ($manifest, $architecture) { | ||
$useLessMsi = get_config MSIEXTRACT_USE_LESSMSI | ||
if (!$useLessMsi) { return $false } | ||
|
||
$(url $manifest $architecture | Where-Object { | ||
$_ -match '\.(msi)$' | ||
} | Measure-Object | Select-Object -exp count) -gt 0 | ||
$_ -match '\.(msi)$' | ||
} | Measure-Object | Select-Object -exp count) -gt 0 | ||
} | ||
|
||
function file_requires_7zip($fname) { | ||
$fname -match '\.((gz)|(tar)|(tgz)|(lzma)|(bz)|(bz2)|(7z)|(rar)|(iso)|(xz)|(lzh)|(nupkg))$' | ||
} | ||
|
||
function extract_7zip($path, $to, $recurse) { | ||
$output = 7z x "$path" -o"$to" -y | ||
if($lastexitcode -ne 0) { abort "Exit code was $lastexitcode." } | ||
$output = &(file_path 7zip 7z.exe) x "$path" -o"$to" -y | ||
if ($lastexitcode -ne 0) { abort "Exit code was $lastexitcode." } | ||
|
||
# check for tar | ||
$tar = (split-path $path -leaf) -replace '\.[^\.]*$', '' | ||
if($tar -match '\.tar$') { | ||
if(test-path "$to\$tar") { extract_7zip "$to\$tar" $to $true } | ||
if ($tar -match '\.tar$') { | ||
if (test-path "$to\$tar") { extract_7zip "$to\$tar" $to $true } | ||
} | ||
|
||
if($recurse) { Remove-Item $path } # clean up intermediate files | ||
if ($recurse) { Remove-Item $path -Force } # clean up intermediate files | ||
} | ||
|
||
function extract_msi($path, $to, $recurse) { | ||
$logfile = "$(split-path $path)\msi.log" | ||
$ok = run 'msiexec' @('/a', "`"$path`"", '/qn', "TARGETDIR=`"$to`"", "/lwe `"$logfile`"") | ||
if (!$ok) { abort "Failed to extract files from $path.`nLog file:`n $(friendly_path $logfile)" } | ||
if (test-path $logfile) { Remove-Item $logfile } | ||
if ($recurse) { Remove-Item $path -Force } | ||
} | ||
|
||
function extract_lessmsi($path, $to, $recurse) { | ||
&(file_path lessmsi lessmsi.exe) x "$path" "$to\" | ||
Move-Item "$to\SourceDir\*" "$to" -Force | ||
Remove-Item "$to\SourceDir" -Force | ||
if ($recurse) { Remove-Item $path -Force } | ||
} | ||
|
||
function extract_inno($path, $to, $recurse) { | ||
$logfile = "$(split-path $path)\innounp.log" | ||
&(file_path innounp innounp.exe) -x -d"$to" -c"{app}" "$path" > "$logfile" | ||
if ($lastexitcode -ne 0) { | ||
abort "Failed to extract files from $path.`nLog file:`n $(friendly_path $logfile)" | ||
} | ||
if (test-path $logfile) { Remove-Item $logfile } | ||
if ($recurse) { Remove-Item $path -Force } | ||
} | ||
|
||
function extract_zip($path, $to, $recurse) { | ||
if (!(test-path $path)) { abort "can't find $path to unzip"} | ||
try { add-type -assembly "System.IO.Compression.FileSystem" -ea stop } | ||
catch { unzip_old $path $to; return } # for .net earlier than 4.5 | ||
$retries = 0 | ||
while ($retries -le 10) { | ||
if ($retries -eq 10) { | ||
if (7zip_installed) { | ||
extract_7zip $path $to $false | ||
return | ||
} else { | ||
abort "Unzip failed: Windows can't unzip because a process is locking the file.`nRun 'scoop install 7zip' and try again." | ||
} | ||
} | ||
if (isFileLocked $path) { | ||
write-host "Waiting for $path to be unlocked by another process... ($retries/10)" | ||
$retries++ | ||
Start-Sleep -s 2 | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
try { | ||
[io.compression.zipfile]::extracttodirectory($path, $to) | ||
} catch [system.io.pathtoolongexception] { | ||
# try to fall back to 7zip if path is too long | ||
if (7zip_installed) { | ||
extract_7zip $path $to $false | ||
return | ||
} else { | ||
abort "Unzip failed: Windows can't handle the long paths in this zip file.`nRun 'scoop install 7zip' and try again." | ||
} | ||
} catch [system.io.ioexception] { | ||
if (7zip_installed) { | ||
extract_7zip $path $to $false | ||
return | ||
} else { | ||
abort "Unzip failed: Windows can't handle the file names in this zip file.`nRun 'scoop install 7zip' and try again." | ||
} | ||
} catch { | ||
abort "Unzip failed: $_" | ||
} | ||
if ($recurse) { Remove-Item $path -Force } | ||
} | ||
|
||
function unzip_old($path, $to) { | ||
# fallback for .net earlier than 4.5 | ||
$shell = (new-object -com shell.application -strict) | ||
$zipfiles = $shell.namespace("$path").items() | ||
$to = ensure $to | ||
$shell.namespace("$to").copyHere($zipfiles, 4) # 4 = don't show progress dialog | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters