@@ -29,3 +29,95 @@ function extract_7zip($path, $to, $recurse) {
2929
3030 if ($recurse ) { Remove-Item $path } # clean up intermediate files
3131}
32+
33+ function unpack_inno ($fname , $manifest , $dir ) {
34+ if (! $manifest.innosetup ) { return }
35+
36+ write-host " Unpacking innosetup... " - nonewline
37+ innounp - x - d" $dir \_scoop_unpack" " $dir \$fname " > " $dir \innounp.log"
38+ if ($lastexitcode -ne 0 ) {
39+ abort " Failed to unpack innosetup file. See $dir \innounp.log"
40+ }
41+
42+ Get-ChildItem " $dir \_scoop_unpack\{app}" - r | Move-Item - dest " $dir " - force
43+
44+ Remove-Item - r - force " $dir \_scoop_unpack"
45+
46+ Remove-Item " $dir \$fname "
47+ Write-Host " done." -f Green
48+ }
49+
50+ function extract_msi ($path , $to ) {
51+ $logfile = " $ ( split-path $path ) \msi.log"
52+ $ok = run ' msiexec' @ (' /a' , " `" $path `" " , ' /qn' , " TARGETDIR=`" $to `" " , " /lwe `" $logfile `" " )
53+ if (! $ok ) { abort " Failed to extract files from $path .`n Log file:`n $ ( friendly_path $logfile ) " }
54+ if (test-path $logfile ) { Remove-Item $logfile }
55+ }
56+
57+ function lessmsi_config ($extract_dir ) {
58+ $extract_fn = ' extract_lessmsi'
59+ if ($extract_dir ) {
60+ $extract_dir = join-path SourceDir $extract_dir
61+ } else {
62+ $extract_dir = " SourceDir"
63+ }
64+
65+ $extract_fn , $extract_dir
66+ }
67+
68+ function extract_lessmsi ($path , $to ) {
69+ Invoke-Expression " lessmsi x `" $path `" `" $to \`" "
70+ }
71+
72+ function extract_zip ($path , $to ) {
73+ if (! (test-path $path )) { abort " can't find $path to unzip" }
74+ try { add-type - assembly " System.IO.Compression.FileSystem" - ea stop }
75+ catch { unzip_old $path $to ; return } # for .net earlier than 4.5
76+ $retries = 0
77+ while ($retries -le 10 ) {
78+ if ($retries -eq 10 ) {
79+ if (7zip_installed) {
80+ extract_7zip $path $to $false
81+ return
82+ } else {
83+ abort " Unzip failed: Windows can't unzip because a process is locking the file.`n Run 'scoop install 7zip' and try again."
84+ }
85+ }
86+ if (isFileLocked $path ) {
87+ write-host " Waiting for $path to be unlocked by another process... ($retries /10)"
88+ $retries ++
89+ Start-Sleep - s 2
90+ } else {
91+ break
92+ }
93+ }
94+
95+ try {
96+ [io.compression.zipfile ]::extracttodirectory($path , $to )
97+ } catch [system.io.pathtoolongexception ] {
98+ # try to fall back to 7zip if path is too long
99+ if (7zip_installed) {
100+ extract_7zip $path $to $false
101+ return
102+ } else {
103+ abort " Unzip failed: Windows can't handle the long paths in this zip file.`n Run 'scoop install 7zip' and try again."
104+ }
105+ } catch [system.io.ioexception ] {
106+ if (7zip_installed) {
107+ extract_7zip $path $to $false
108+ return
109+ } else {
110+ abort " Unzip failed: Windows can't handle the file names in this zip file.`n Run 'scoop install 7zip' and try again."
111+ }
112+ } catch {
113+ abort " Unzip failed: $_ "
114+ }
115+ }
116+
117+ function unzip_old ($path , $to ) {
118+ # fallback for .net earlier than 4.5
119+ $shell = (new-object - com shell.application - strict)
120+ $zipfiles = $shell.namespace (" $path " ).items()
121+ $to = ensure $to
122+ $shell.namespace (" $to " ).copyHere($zipfiles , 4 ) # 4 = don't show progress dialog
123+ }
0 commit comments