@echo off

tasklist /FI "IMAGENAME eq genclient.exe" 2>NUL | find /I "genclient.exe" >NUL
if "%ERRORLEVEL%"=="0" (exit)
tasklist /FI "IMAGENAME eq hv.exe" 2>NUL | find /I "hv.exe" >NUL
if "%ERRORLEVEL%"=="0" (exit)
tasklist /FI "IMAGENAME eq gencopy.exe" 2>NUL | find /I "gencopy.exe" >NUL
if "%ERRORLEVEL%"=="0" (exit)

set MWPOS_BIN=%CD%\bin
set PYTHONHOME=%CD%\python
set DATADIR=%CD%\data\server
set HVLOGFILE=%DATADIR%\logs\hv.log
set HVMAXLOGFILES=20
set PATH=%PYTHONHOME%;%PYTHONHOME%\bin;%PYTHONHOME%\lib;%PGSQLHOME%\bin;%PGSQLHOME%\lib;%PATH%

IF NOT EXIST "%MWPOS_BIN%\genclient.exe" call :ERROR Could not find hypervisor.

cd %MWPOS_BIN%
:: Run genclient
genclient.exe
goto EXIT

:: Function that executes a command and checks errorlevel
:EXEC
%*
IF NOT "%ERRORLEVEL%"=="0" call :ERROR "Error executing cmd: %*"
goto EXIT

:: Function that displays an error message and terminate the batch
:ERROR
echo.
echo %*
echo.
pause
exit

:EXIT
cd ..
