@echo off
setlocal
chcp 65001 >nul
set "RESULT=0"
set "ROOT=%~dp0"
set "MANAGER=%ROOT%bin\zfile-manager.exe"
set "PENDING=%ROOT%bin\zfile-manager.new.exe"
if exist "%PENDING%" (
    move /Y "%PENDING%" "%MANAGER%" >nul
    if errorlevel 1 (
        echo Error: unable to activate the updated ZFile manager. 1>&2
        set "RESULT=1"
        goto :finish
    )
)
if not exist "%MANAGER%" (
    echo Error: ZFile manager not found: "%MANAGER%" 1>&2
    set "RESULT=1"
    goto :finish
)
"%MANAGER%" %*
set "RESULT=%ERRORLEVEL%"

:finish
if not "%RESULT%"=="0" if not defined ZFILE_NO_PAUSE pause
exit /b %RESULT%
