@echo off
echo ================================================
echo   Karls DIY Dyno - Creating LittleFS binary
echo ================================================
echo.

:: Get current date in YYYY-MM-DD format
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set "currdate=%%c-%%a-%%b"
if "%currdate%"=="" for /f "tokens=1-3 delims=.-" %%a in ('echo %date%') do set "currdate=%%c-%%a-%%b"

:: Alternative: YYYYMMDD format (no dashes)
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set "currdate_compact=%%c%%a%%b"
if "%currdate_compact%"=="" for /f "tokens=1-3 delims=.-" %%a in ('echo %date%') do set "currdate_compact=%%c%%a%%b"

:: Your exact mklittlefs path
set MKLITTLEFS=C:\Users\karlj\AppData\Local\Arduino15\packages\esp32\tools\mklittlefs\4.0.2-db0513a\mklittlefs.exe

if not exist "%MKLITTLEFS%" (
    echo FEIL: Kunne ikke finne mklittlefs.exe
    echo Sjekk at stien er riktig.
    pause
    exit /b 1
)

echo Fant mklittlefs her: %MKLITTLEFS%
echo.
echo Lager LittleFS bilde fra data/ mappen...

:: Create filename with date
set FILENAME=Dashboard_update_%currdate_compact%.bin

"%MKLITTLEFS%" -c data -s 1048576 -b 4096 -p 256 %FILENAME%

if %errorlevel% equ 0 (
    echo.
    echo SUKSESS! %FILENAME% ble opprettet.
    echo.
    echo Du kan n? laste opp denne filen via "HMI / Web Files Update" p? dynoen.
) else (
    echo.
    echo FEIL: Kunne ikke lage LittleFS bilde.
)

echo.
pause