@echo off

set CRNfilename=crunch_x64.exe
set CGPfilename=WD_XBT-ConvertGraphicProc.bat

set WD_Alist=WD_AlphaList.txt
set WD_FinalList=WD_FinalList.txt

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

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

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

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


:choice
cls
echo.
echo *******************************************************************************
echo *                                                                             *
echo *                 Watch Dogs    ~    Convert DDS to CRN                       *
echo *                                                                             *
echo *                                                                             *
echo *       Step 01: Convert all Alpha graphic files                              *
echo *       Step 02: Convert all other graphic files                              *
echo *                                                                             *
echo *       Press [1] to start the conversion procedure...                        *
echo *                                                                             *
echo *                                                                             *
echo *       Remark:                                                               *
echo *       [WD_AlphaList.txt] and [WD_FinalList.txt] must exist in the           *
echo *       current folder!                                                       *
echo *       Created by [WD_XBT-ConvertList_DDS.bat]                               *
echo *                                                                             *
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 TotalFile=0

%~d0
cd %~dp0

setlocal EnableDelayedExpansion
set Count=0
set mCount=-1
set CountDiv=0
set CountDiv1=0

For /F "delims=~" %%i in (%WD_Alist%) do (
Set /a Count=!Count!+1
set TotalFile=!Count!
)

set Count=0
for /F "delims=~+~" %%i in (%WD_Alist%) do (

Set /a Count=!Count!+1
Set /a mCount=!mCount!+1

rem *** show progress as this can take awhile...
set /a CountDiv=!Count!/10
set /a CountDiv1=!mCount!/10
if !Count!==1 (<NUL set /p=* [%TotalFile% Alpha files] Compression in progress)
if !CountDiv!==!CountDiv1! (<NUL set /p=.) ELSE (<NUL set /p=!Count!)
rem echo [!CountDiv!]  ~  {!CountDiv1!}    ~   !Count!

if exist %%i (

rem *** CRN = Compress file...
set WinTitle=Compressing DDS file [!Count!/%TotalFile%]...
start "!WinTitle!" /WAIT /MIN WD_XBT-ConvertGraphicProc.bat %%i DXT5A CRN

)
)
echo.

set Count=0
set mCount=-1
set CountDiv=0
set CountDiv1=0

For /F "delims=~" %%i in (%WD_FinalList%) do (
Set /a Count=!Count!+1
set TotalFile=!Count!
)

set Count=0
For /F "tokens=1,2 delims=~+~" %%i in (%WD_FinalList%) do (

Set /a Count=!Count!+1
Set /a mCount=!mCount!+1

rem *** show progress as this can take awhile...
set /a CountDiv=!Count!/10
set /a CountDiv1=!mCount!/10
if !Count!==1 (<NUL set /p=* [%TotalFile% graphic files] Compression in progress)
if !CountDiv!==!CountDiv1! (<NUL set /p=.) ELSE (<NUL set /p=!Count!)

if exist %%i (

set WinTitle=Compressing DDS file [!Count!/%TotalFile%]...
start "!WinTitle!" /WAIT /MIN WD_XBT-ConvertGraphicProc.bat %%i %%j CRN

)
)


goto END

:END

echo.
pause