@echo off
chcp 65001 >nul
setlocal EnableDelayedExpansion

set "VCVARS=C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

if not exist "!VCVARS!" (
    echo [ERROR] MSVC Build Tools not found at !VCVARS!
    echo Please change the VCVARS path in build.bat to match your VS installation.
    exit /b 1
)

call "!VCVARS!"

set SOURCE=progress_demo.c
set PROGRAM=progress_demo.exe

if not exist "%SOURCE%" (
    echo [ERROR] %SOURCE% not found.
    exit /b 1
)

echo [BUILD] Compiling %SOURCE% with eduwin.lib...
rc /nologo app.rc
cl /nologo /W3 /utf-8 /std:c17 /I..\..\eduwin\include /c "%SOURCE%"
link /nologo "%SOURCE:.c=.obj%" app.res ..\..\eduwin\lib\eduwin.lib user32.lib gdi32.lib gdiplus.lib comctl32.lib comdlg32.lib shell32.lib winmm.lib ole32.lib oleaut32.lib version.lib advapi32.lib /out:"%PROGRAM%" /subsystem:windows /entry:mainCRTStartup

if %errorlevel%==0 (
    echo.
    echo [OK] Build success! Run: %PROGRAM%
)
