From 344555c0ea256120965e48a19b8c9080988ff123 Mon Sep 17 00:00:00 2001 From: Mohsen Nasiri Date: Wed, 9 Apr 2025 04:44:14 +0330 Subject: [PATCH] Improve install.bat to support PowerShell 7 and handle missing Expand-Archive gracefully --- install.bat | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/install.bat b/install.bat index 386fba2d0..ffc0ed92c 100755 --- a/install.bat +++ b/install.bat @@ -139,7 +139,16 @@ if not exist "%otp_dir%\bin" ( curl.exe -fsSLo %tmp_dir%\%otp_zip% "!otp_url!" || exit /b 1 echo unpacking %tmp_dir%\%otp_zip% - powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%otp_zip% -DestinationPath %otp_dir%" + powershell -NoProfile -Command ^ + "$ErrorActionPreference='Stop';" ^ + "try {" ^ + " if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue)) {" ^ + " Add-Type -AssemblyName System.IO.Compression.FileSystem;" ^ + " [System.IO.Compression.ZipFile]::ExtractToDirectory('%tmp_dir%\%otp_zip%', '%otp_dir%')" ^ + " } else {" ^ + " Expand-Archive -LiteralPath '%tmp_dir%\%otp_zip%' -DestinationPath '%otp_dir%' -Force" ^ + " }" ^ + "} catch { Write-Error $_; exit 1 }" del /f /q "%tmp_dir%\%otp_zip%" cd /d "%otp_dir%" @@ -166,7 +175,16 @@ if not exist "%elixir_dir%\bin" ( curl.exe -fsSLo "%tmp_dir%\%elixir_zip%" "!elixir_url!" || exit /b 1 echo unpacking %tmp_dir%\%elixir_zip% - powershell -Command "Expand-Archive -LiteralPath %tmp_dir%\%elixir_zip% -DestinationPath %elixir_dir%" + powershell -NoProfile -Command ^ + "$ErrorActionPreference='Stop';" ^ + "try {" ^ + " if (-not (Get-Command Expand-Archive -ErrorAction SilentlyContinue)) {" ^ + " Add-Type -AssemblyName System.IO.Compression.FileSystem;" ^ + " [System.IO.Compression.ZipFile]::ExtractToDirectory('%tmp_dir%\%elixir_zip%', '%elixir_dir%')" ^ + " } else {" ^ + " Expand-Archive -LiteralPath '%tmp_dir%\%elixir_zip%' -DestinationPath '%elixir_dir%' -Force" ^ + " }" ^ + "} catch { Write-Error $_; exit 1 }" del /f /q %tmp_dir%\%elixir_zip% ) goto :eof