Skip to content

Commit 217d3ea

Browse files
authored
Improve install.bat to support PowerShell 7 and handle missing Expand-Archive gracefully (#1800)
1 parent 3d0f29a commit 217d3ea

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

install.bat

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,16 @@ if not exist "%otp_dir%\bin" (
139139
curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1
140140

141141
echo unpacking %tmp_dir%\%otp_zip%
142-
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%"
142+
powershell -NoProfile -Command ^
143+
"$ErrorActionPreference='Stop';" ^
144+
"try {" ^
145+
" if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue)) {" ^
146+
" Add-Type -AssemblyName System.IO.Compression.FileSystem;" ^
147+
" [System.IO.Compression.ZipFile]::ExtractToDirectory('%tmp_dir%\%otp_zip%', '%otp_dir%')" ^
148+
" } else {" ^
149+
" Expand-Archive -LiteralPath '%tmp_dir%\%otp_zip%' -DestinationPath '%otp_dir%' -Force" ^
150+
" }" ^
151+
"} catch { Write-Error $_; exit 1 }"
143152
del /f /q "%tmp_dir%\%otp_zip%"
144153
cd /d "%otp_dir%"
145154

@@ -166,7 +175,16 @@ if not exist "%elixir_dir%\bin" (
166175
curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1
167176

168177
echo unpacking %tmp_dir%\%elixir_zip%
169-
powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%"
178+
powershell -NoProfile -Command ^
179+
"$ErrorActionPreference='Stop';" ^
180+
"try {" ^
181+
" if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue)) {" ^
182+
" Add-Type -AssemblyName System.IO.Compression.FileSystem;" ^
183+
" [System.IO.Compression.ZipFile]::ExtractToDirectory('%tmp_dir%\%elixir_zip%', '%elixir_dir%')" ^
184+
" } else {" ^
185+
" Expand-Archive -LiteralPath '%tmp_dir%\%elixir_zip%' -DestinationPath '%elixir_dir%' -Force" ^
186+
" }" ^
187+
"} catch { Write-Error $_; exit 1 }"
170188
del /f /q %tmp_dir%\%elixir_zip%
171189
)
172190
goto :eof

0 commit comments

Comments
 (0)