@echo off
setlocal
chcp 65001 >nul
title malasci Codex Combined Installer
echo malasci Codex combined installer
echo Version: combined1-prelinks2
echo.
set "BOOTSTRAP_URL=https://download.malasci.com/launchers/windows-installer.ps1?v=20260709-prelinks2"
set "BOOTSTRAP_PS1=%TEMP%\malasci-Windows-Installer-prelinks2.ps1"
set "PACKAGE_URL=https://download.malasci.com/packages/malasci-windows.zip?v=20260709-prelinks2"
set "PACKAGE_SHA256=82e8773e99e2b07249672fa058d66d958264ac91cb3f7131582d5d55d730ace7"
if exist "%BOOTSTRAP_PS1%" del /f /q "%BOOTSTRAP_PS1%" >nul 2>nul
echo [prepare] downloading launcher...
set "BOOTSTRAP_FULL_URL=%BOOTSTRAP_URL%&cb=%RANDOM%%RANDOM%%RANDOM%"
if exist "%SystemRoot%\System32\curl.exe" (
  "%SystemRoot%\System32\curl.exe" -fL --retry 3 --connect-timeout 30 -H "Cache-Control: no-cache" -o "%BOOTSTRAP_PS1%" "%BOOTSTRAP_FULL_URL%"
) else (
  "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; $u='%BOOTSTRAP_FULL_URL%'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Headers @{'Cache-Control'='no-cache'} -Uri $u -OutFile '%BOOTSTRAP_PS1%'"
)
if errorlevel 1 (
  echo [prepare] curl download failed, retrying with PowerShell...
  "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; $u='%BOOTSTRAP_FULL_URL%'; [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Headers @{'Cache-Control'='no-cache'} -Uri $u -OutFile '%BOOTSTRAP_PS1%'"
)
if errorlevel 1 (
  echo [error] launcher download failed.
  pause
  exit /b 1
)
findstr /C:"Version: combined1" "%BOOTSTRAP_PS1%" >nul
if errorlevel 1 (
  echo [error] downloaded launcher is not combined1.
  echo [debug] %BOOTSTRAP_PS1%
  type "%BOOTSTRAP_PS1%"
  pause
  exit /b 1
)
findstr /C:"Expand-ZipSafely" "%BOOTSTRAP_PS1%" >nul
if errorlevel 1 (
  echo [error] downloaded launcher does not contain safe unzip code.
  echo [debug] %BOOTSTRAP_PS1%
  type "%BOOTSTRAP_PS1%"
  pause
  exit /b 1
)
echo [prepare] launcher downloaded.
echo.
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%BOOTSTRAP_PS1%" -Mode "codex" -ProductName "Codex" -PackageUrl "%PACKAGE_URL%" -ExpectedSha256 "%PACKAGE_SHA256%"
echo.
echo Finished. Press any key to close this window.
pause >nul
