@echo off
setlocal

set "PACKAGE_DIR=%~1"

if "%PACKAGE_DIR%"=="" (
  echo Usage: InstallWindowsDemoLaunchers.bat PACKAGE_DIR
  exit /b 1
)

if not exist "%PACKAGE_DIR%\AgrarianGame.exe" (
  echo Packaged AgrarianGame.exe was not found in:
  echo %PACKAGE_DIR%
  exit /b 1
)

set "DEFAULT_LAUNCHER=%PACKAGE_DIR%\Start Agrarian Demo.cmd"
set "DX12_LAUNCHER=%PACKAGE_DIR%\Start Agrarian Demo - DX12.cmd"
set "DX11_LAUNCHER=%PACKAGE_DIR%\Start Agrarian Demo - Compatibility DX11.cmd"
set "PREREQ_LAUNCHER=%PACKAGE_DIR%\Install Prerequisites.cmd"
set "README_FILE=%PACKAGE_DIR%\README-Investor-Demo.txt"
set "DEMO_VERSION=Investor Demo v0.1.L - Build 2026.05.18"

> "%DEFAULT_LAUNCHER%" echo @echo off
>> "%DEFAULT_LAUNCHER%" echo cd /d "%%~dp0"
>> "%DEFAULT_LAUNCHER%" echo echo Starting Agrarian investor demo...
>> "%DEFAULT_LAUNCHER%" echo echo.
>> "%DEFAULT_LAUNCHER%" echo "AgrarianGame.exe" -windowed -ResX=1280 -ResY=720
>> "%DEFAULT_LAUNCHER%" echo if errorlevel 1 ^(
>> "%DEFAULT_LAUNCHER%" echo   echo.
>> "%DEFAULT_LAUNCHER%" echo   echo Agrarian did not start cleanly.
>> "%DEFAULT_LAUNCHER%" echo   echo Run "Install Prerequisites.cmd", then try "Start Agrarian Demo - Compatibility DX11.cmd".
>> "%DEFAULT_LAUNCHER%" echo   pause
>> "%DEFAULT_LAUNCHER%" echo ^)

> "%DX12_LAUNCHER%" echo @echo off
>> "%DX12_LAUNCHER%" echo cd /d "%%~dp0"
>> "%DX12_LAUNCHER%" echo echo Starting Agrarian investor demo with DX12...
>> "%DX12_LAUNCHER%" echo echo.
>> "%DX12_LAUNCHER%" echo "AgrarianGame.exe" -d3d12 -windowed -ResX=1280 -ResY=720
>> "%DX12_LAUNCHER%" echo if errorlevel 1 ^(
>> "%DX12_LAUNCHER%" echo   echo.
>> "%DX12_LAUNCHER%" echo   echo DX12 startup failed on this machine/session.
>> "%DX12_LAUNCHER%" echo   echo Try "Start Agrarian Demo - Compatibility DX11.cmd".
>> "%DX12_LAUNCHER%" echo   pause
>> "%DX12_LAUNCHER%" echo ^)

> "%DX11_LAUNCHER%" echo @echo off
>> "%DX11_LAUNCHER%" echo cd /d "%%~dp0"
>> "%DX11_LAUNCHER%" echo echo Starting Agrarian investor demo with DX11 compatibility mode...
>> "%DX11_LAUNCHER%" echo echo.
>> "%DX11_LAUNCHER%" echo "AgrarianGame.exe" -d3d11 -windowed -ResX=1280 -ResY=720
>> "%DX11_LAUNCHER%" echo if errorlevel 1 ^(
>> "%DX11_LAUNCHER%" echo   echo.
>> "%DX11_LAUNCHER%" echo   echo Agrarian did not start cleanly in compatibility mode.
>> "%DX11_LAUNCHER%" echo   echo Run "Install Prerequisites.cmd" and make sure the entire WindowsDevelopment folder was copied together.
>> "%DX11_LAUNCHER%" echo   pause
>> "%DX11_LAUNCHER%" echo ^)

> "%PREREQ_LAUNCHER%" echo @echo off
>> "%PREREQ_LAUNCHER%" echo cd /d "%%~dp0"
>> "%PREREQ_LAUNCHER%" echo set "REDIST=Engine\Extras\Redist\en-us\vc_redist.x64.exe"
>> "%PREREQ_LAUNCHER%" echo if not exist "%%REDIST%%" ^(
>> "%PREREQ_LAUNCHER%" echo   echo Required installer was not found:
>> "%PREREQ_LAUNCHER%" echo   echo %%CD%%\%%REDIST%%
>> "%PREREQ_LAUNCHER%" echo   pause
>> "%PREREQ_LAUNCHER%" echo   exit /b 1
>> "%PREREQ_LAUNCHER%" echo ^)
>> "%PREREQ_LAUNCHER%" echo echo Installing Microsoft Visual C++ runtime...
>> "%PREREQ_LAUNCHER%" echo "%%REDIST%%" /install /quiet /norestart
>> "%PREREQ_LAUNCHER%" echo echo.
>> "%PREREQ_LAUNCHER%" echo echo Done. If Windows requested administrator approval, approve it and rerun this if needed.
>> "%PREREQ_LAUNCHER%" echo pause

> "%README_FILE%" echo Agrarian investor demo
>> "%README_FILE%" echo.
>> "%README_FILE%" echo Version: %DEMO_VERSION%
>> "%README_FILE%" echo.
>> "%README_FILE%" echo Start with: Start Agrarian Demo.cmd
>> "%README_FILE%" echo.
>> "%README_FILE%" echo Important: copy or keep this entire WindowsDevelopment folder together. AgrarianGame.exe needs the AgrarianGame and Engine folders beside it.
>> "%README_FILE%" echo.
>> "%README_FILE%" echo If the demo does not open, run: Install Prerequisites.cmd
>> "%README_FILE%" echo Then run: Start Agrarian Demo - Compatibility DX11.cmd
>> "%README_FILE%" echo.
>> "%README_FILE%" echo This investor build defaults to the Windows compatibility renderer so it opens reliably across more demo machines and remote sessions.
>> "%README_FILE%" echo The main project remains DX12-first for future Unreal 5 rendering work.
>> "%README_FILE%" echo If you specifically want to test DX12, use: Start Agrarian Demo - DX12.cmd

echo Installed investor demo launchers in:
echo %PACKAGE_DIR%
exit /b 0
