@echo off
setlocal

set "SCRIPT_URL=https://g99g.com/word-addin/windows/Install-CoE-KSU-Thesis-Validator.ps1"
set "LOCAL_SCRIPT=%~dp0Install-CoE-KSU-Thesis-Validator.ps1"
set "TEMP_SCRIPT=%TEMP%\Install-CoE-KSU-Thesis-Validator.ps1"

if exist "%LOCAL_SCRIPT%" (
  powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%LOCAL_SCRIPT%"
  exit /b %ERRORLEVEL%
)

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ErrorActionPreference='Stop';" ^
  "$url='%SCRIPT_URL%';" ^
  "$target='%TEMP_SCRIPT%';" ^
  "Invoke-WebRequest -Uri $url -OutFile $target -UseBasicParsing -TimeoutSec 30;" ^
  "& $target"

exit /b %ERRORLEVEL%
