@echo off
setlocal

if "%ACEVO_SERVER_EXE%"=="" (
    set "ACEVO_SERVER_EXE=C:\Program Files (x86)\Steam\steamapps\common\Assetto Corsa EVO Dedicated Server\ServerLauncher.exe"
)

if "%ACEVO_LOG_FILE%"=="" (
    set "ACEVO_LOG_FILE=%~dp0..\logs\acevo-server.log"
)

if not exist "%ACEVO_SERVER_EXE%" (
    echo Server executable wurde nicht gefunden: %ACEVO_SERVER_EXE%
    exit /b 1
)

for %%I in ("%ACEVO_SERVER_EXE%") do set "ACEVO_SERVER_DIR=%%~dpI"
for %%I in ("%ACEVO_LOG_FILE%") do set "ACEVO_LOG_DIR=%%~dpI"

if not exist "%ACEVO_LOG_DIR%" mkdir "%ACEVO_LOG_DIR%"

pushd "%ACEVO_SERVER_DIR%"
start "" /B "%ACEVO_SERVER_EXE%" >> "%ACEVO_LOG_FILE%" 2>&1
popd

exit /b 0
