@echo off
chcp 65001 >nul
setlocal
cd /d "%~dp0"

set NEED_VC=0
reg query "HKLM\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" /v Installed >nul 2>&1
if errorlevel 1 set NEED_VC=1
if %NEED_VC%==0 (
    reg query "HKLM\SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" /v Installed 2>nul | find "0x1" >nul
    if errorlevel 1 set NEED_VC=1
)

if %NEED_VC%==1 (
    if exist "vc_redist.x64.exe" (
        echo Installing required Visual C++ libraries (one time)...
        vc_redist.x64.exe /install /quiet /norestart
        timeout /t 3 /nobreak >nul
    ) else (
        echo.
        echo [ERROR] Visual C++ Runtime is missing.
        echo Run install_vcredist.bat first, or install from Microsoft:
        echo https://aka.ms/vs/17/release/vc_redist.x64.exe
        echo.
        pause
        exit /b 1
    )
)

start "" "%~dp0yarmenu_accounting.exe"
exit /b 0
