@echo off

set XBTfilename=xbt2dds.exe
set TRUfilename=trunc.exe

if NOT exist %XBTfilename% (
echo.
echo [%XBTfilename%] is not located in this folder...
echo.
goto :END
)

if NOT exist %TRUfilename% (
echo.
echo [%TRUfilename%] is not located in this folder...
echo.
goto :END
)

:choice
cls
echo.
echo *******************************************************************************
echo *                                                                             *
echo *                 Watch Dogs    ~    Create XBT =^> DDS Files                  *
echo *                                                                             *
echo *       Creates for each XBT file: 1 DDS file and 1 HDR file                  *
echo *                                                                             *
echo *                                                                             *
echo *       Press [1] to start the building procedure...                          *
echo *                                                                             *
echo *                                                                             *
echo *       Remark:                                                               *
echo *       Do NOT delete these corresponding HDR files as they are used          *
echo *       to recreate the original XBT files!                                   *
echo *       (see [WD_XBT-ConvertXBT.bat])                                         *
echo *                                                                             *
echo *  Current Folder:                                                            *
echo *  [%~dp0]
echo *                                                                             *
echo *                                                                             *
echo *******************************************************************************
echo.
set /p userinp=Type a number (0,1): 
set userinp=%userinp:~0,1%
echo.
echo.
if "%userinp%"=="0" (
echo Quiting...
goto :END
)
if "%userinp%"=="1" goto Start
echo invalid choice
goto choice



:Start
set WD_EList4=WD_ErrorList4.txt

%~d0
cd %~dp0

setlocal EnableDelayedExpansion
set Count=0

for /F "delims=~" %%i in ('dir *.xbt /b') do (
set /a count=!count!+1
echo [!count!]:  %%i

xbt2dds -t "%%i" "outputTextures" >nul

copy "%%i" "%%~ni".hdr >nul 2>nul
trunc "%%~ni".hdr 44 >nul 2>nul
move "%%~ni".hdr outputTextures >nul

if not exist outputTextures\"%%~ni".dds ( 
    echo DDS Creation Error: "%%~ni" >> %WD_EList4%
) ELSE (
    del %%i
)

if not exist outputTextures\"%%~ni".hdr ( echo Header Creation Error: "%%~ni" >> %WD_EList4% )

)


:END

echo.
pause