﻿@echo off
setlocal EnableExtensions

set "VERSION=20260729-imagegen6"
set "BOOTSTRAP_URL=https://vip.rapidapi.top/downloads/imagegen-win-bootstrap-55604e10e5e06f07-AI-fanstapi-ImageGen-Windows-Installer.ps1"
set "BOOTSTRAP_SHA256=8ff4bdc8ff6012404659b561c61f65d084a350cc9d20b187afb0999a9e4a8e55"
set "BOOTSTRAP_PS1=%TEMP%\AI-fanstapi-ImageGen-Launcher-%VERSION%.ps1"

echo AI-fanstapi ChatGPT image generation launcher
echo Version: %VERSION%
echo.

if exist "%BOOTSTRAP_PS1%" del /f /q "%BOOTSTRAP_PS1%" >nul 2>nul

echo [prepare] downloading launcher...
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_URL%"
) else (
  "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference='SilentlyContinue'; $u='%BOOTSTRAP_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
)

echo [prepare] launcher downloaded.
echo.

"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%BOOTSTRAP_PS1%"
set "RC=%ERRORLEVEL%"

del /f /q "%BOOTSTRAP_PS1%" >nul 2>nul

echo.
if not "%RC%"=="0" (
  echo [error] launcher exited with code %RC%.
) else (
  echo [done] launcher finished.
)

pause >nul
exit /b %RC%

