﻿@echo off
setlocal
chcp 65001 >nul
title AI-fanstapi ChatGPT Combined Installer
echo AI-fanstapi ChatGPT combined installer
echo Version: combined1-20260730-imagegenprompt1
echo.
set "BOOTSTRAP_URL=https://vip.rapidapi.top/downloads/win-bootstrap-5c63fccd385fc83f-AI-fanstapi-Windows-Installer.ps1"
set "BOOTSTRAP_PS1=%TEMP%\AI-fanstapi-Codex-Windows-Installer-20260730-imagegenprompt1.ps1"
set "BOOTSTRAP_SHA256=cafa16b5ff90dd9e081b04b4c48d8c72ea58b6cfb052037a58f0cdaa8e3cffaa"
set "PACKAGE_URL=https://vip.rapidapi.top/downloads/win-package-48fa011b1402aef1-AI-fanstapi-Codex-Windows.zip"
set "PACKAGE_SHA256=3cad493308771b7755293008309b3a5a19b6e15847e66d26e14b3e53840f7767"
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
)
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -Command "$actual=(Get-FileHash -Algorithm SHA256 -LiteralPath '%BOOTSTRAP_PS1%').Hash.ToLowerInvariant(); if ($actual -ne '%BOOTSTRAP_SHA256%') { Write-Error ('launcher SHA256 mismatch: ' + $actual); exit 1 }"
if errorlevel 1 (
  echo [error] launcher verification 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 "ChatGPT" -PackageUrl "%PACKAGE_URL%" -ExpectedSha256 "%PACKAGE_SHA256%"
echo.
echo Finished. Press any key to close this window.
pause >nul

