@echo off
setlocal

:loop
.\jre\bin\java.exe -server -cp "dependency\*" ru.p5277.controller.Main -l 2 -siteid 1 -P TCP -dse

if %errorlevel% equ 2 (
    for /d %%i in (*) do (
        if /i not "%%i"=="jre" (
            if /i not "%%i"=="last_ver.dir" (
                rmdir /s /q "%%i" 2>nul
            )
        )
    )

    for %%f in (*) do (
        if /i not "%%f"=="update.cmd" (
            if /i not "%%f"=="output.log" (
                del /q "%%f" 2>nul
            )
        )
    )

    xcopy "last_ver.dir\c5277\*" "." /E /H /K /Y /I /R > nul
    if exist update.sh_cur move /y update.sh_cur update.sh > nul
    rmdir /s /q last_ver.dir
)

timeout /t 3 /nobreak > nul
goto loop