@echo off
:: ===========================================================================
::  MUNDUS ONLINE
::
::  This is the whole thing. Double-click it.
::
::  It is deliberately tiny: all it does is fetch the current launcher from the
::  server and run it. That means it never goes out of date, and a fix on our
::  side reaches you the next time you open it -- you never download this again.
::
::  It does not need administrator rights, and it does not install itself
::  anywhere. Delete it whenever you like.
:: ===========================================================================
setlocal
title Mundus Online

set "SITE=https://mundus-online.com"
set "WORK=%LOCALAPPDATA%\Mundus"
set "PS1=%WORK%\mundus-launcher.ps1"

color 0B
cls
echo.
echo    ==========================================================
echo                     M U N D U S   O N L I N E
echo    ==========================================================
echo.
echo      Fetching the launcher...
echo.

if not exist "%WORK%" mkdir "%WORK%" >nul 2>&1

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ErrorActionPreference='Stop';" ^
  "try {" ^
  "  [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ^
  "  (New-Object System.Net.WebClient).DownloadFile('%SITE%/mundus-launcher.ps1','%PS1%');" ^
  "  exit 0" ^
  "} catch { Write-Host ('    ' + $_.Exception.Message) -ForegroundColor Red; exit 1 }"

if errorlevel 1 (
  echo.
  echo      Could not reach the Mundus server.
  echo.
  echo      Either it is down, or something on this machine is blocking it.
  echo      Tell Peter -- there is nothing for you to fix here.
  echo.
  pause
  exit /b 1
)

if not exist "%PS1%" (
  echo      The launcher did not arrive. Tell Peter.
  pause
  exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -File "%PS1%" -Site "%SITE%"
