@echo off
rem ===========================================================================
rem  GameNet branch server - double-click installer.
rem
rem  install-branch-server.ps1 does the real work; this exists because handing a
rem  cafe owner "open an elevated PowerShell and paste this" fails three ways on
rem  a stock Windows box, and all three are silent-ish:
rem
rem    1. ExecutionPolicy on Windows client defaults to Restricted -> the .ps1
rem       does not run at all, with a wall of red that reads like a virus warning.
rem    2. A .ps1 extracted from a downloaded .zip carries the Mark of the Web, so
rem       even RemoteSigned refuses it as unsigned. Unblock-File clears it.
rem    3. Nobody opens PowerShell "as administrator" on the first try.
rem
rem  ponytail: ASCII-only English on purpose. A .cmd is read in the console's OEM
rem  codepage, and Persian here comes out as mojibake on some boxes; chcp 65001
rem  plus a BOM-less save is a second footgun. The PowerShell script it launches
rem  does the talking - this file only has to get us there elevated.
rem
rem  Usage: double-click, or  install.cmd <token>
rem ===========================================================================
setlocal
cd /d "%~dp0"

rem --- elevate, carrying the token through if one was passed ---------------
net session >nul 2>&1
if not "%errorlevel%"=="0" (
  echo Asking for administrator rights...
  powershell -NoProfile -ExecutionPolicy Bypass -Command ^
    "Start-Process -FilePath '%~f0' -ArgumentList '%1' -WorkingDirectory '%~dp0' -Verb RunAs"
  exit /b
)

echo.
echo   GameNet - branch server installer
echo   ---------------------------------
echo.

set "TOKEN=%~1"
if "%TOKEN%"=="" (
  echo   Paste the branch token from the signup page ^(right-click pastes^),
  echo   then press Enter.
  echo.
  set /p "TOKEN=  Token: "
)
if "%TOKEN%"=="" (
  echo.
  echo   No token given - nothing to do.
  echo   Lost it? Rotate a fresh one in the dashboard: branch card - "chakhesh token".
  goto :done
)

rem Clears the Mark of the Web the .zip stamped on the script.
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "Get-ChildItem -Path '%~dp0' -Recurse -Include *.ps1 | Unblock-File" >nul 2>&1

powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0install-branch-server.ps1" ^
  -CloudUrl https://gamebaan.ir -CloudToken "%TOKEN%"

:done
echo.
echo   Leave this window open until you have written down the login above.
echo.
pause
endlocal
