@echo off
title %DOWNLOADER_TITLE%

echo %HORIZON%
echo 丂%TDENC_NAME%  ToolDownloader
echo %HORIZON%
echo;


rem ################弶婜張棟################
if not exist ..\Archives mkdir ..\Archives
set AVS=f
set DSS=f
set DIL=f
set FSS=f
set QTS=f
set MIF=f
set YDF=f
set A2P=f
set WVI=f
set NERO=f
set X264=f
call :file_check_sub
echo %AVS%%DSS%%DIL%%FSS%%QTS%%MIF%%YDF%%A2P%%WVI%%NERO%%X264% | findstr "f">nul
if "%ERRORLEVEL%"=="1" exit

rem ################儌乕僪慖戰################
:download_mode
echo ^>^>%DOWNLOADER_ANNOUNCE%
echo;

:auto_mode
echo ^>^>%DOWNLOADER_QUESTION1%
echo ^>^>%DOWNLOADER_QUESTION2%
set /p AUTO=^>^>

:auto_main
if /i "%AUTO%"=="y" goto auto_mode_on
if /i "%AUTO%"=="n" goto auto_mode_off

echo;
echo ^>^>%RETURN_MESSAGE1%
echo;
goto auto_mode


rem ################帺摦儌乕僪################
:auto_mode_on
if "%AVS%"=="f" (
    echo ^>^>Avisynth
    .\curl.exe --connect-timeout 5 -f -o %AVS_PATH% -L %AVS_URL%
    echo;
)
if "%DSS%"=="f" (
    echo ^>^>DirectShowSource
    .\curl.exe --connect-timeout 5 -f -o %DSS_PATH% -L %DSS_URL%
    echo;
)
if "%DIL%"=="f" (
    echo ^>^>DevIL
    .\curl.exe --connect-timeout 5 -f -o %DIL_PATH% -L %DIL_URL%
    echo;
)

if "%FSS%"=="f" (
    echo ^>^>FFMpegSource
    .\curl.exe --connect-timeout 5 -f -o %FSS_PATH% -L %FSS_URL%
    echo;
)
if "%QTS%"=="f" (
    echo ^>^>QTSource
    .\curl.exe --connect-timeout 5 -f -o %QTS_PATH% -L %QTS_URL%
    echo;
)
if "%MIF%"=="f" (
    echo ^>^>MediaInfo
    .\curl.exe --connect-timeout 5 -f -o %MIF_PATH% -L %MIF_URL%
    echo;
)
if "%YDF%"=="f" (
    echo ^>^>Yadif
    .\curl.exe --connect-timeout 5 -f -o %YDF_PATH% -L %YDF_URL%
    echo;
)
if "%A2P%"=="f" (
    echo ^>^>avs2pipe
    .\curl.exe --connect-timeout 5 -f -o %A2P_PATH% -L %A2P_URL%
    echo;
)
if "%WVI%"=="f" (
    echo ^>^>wavi
    .\curl.exe --connect-timeout 5 -f -o %WVI_PATH% -L %WVI_URL%
    echo;
)
if "%X264%"=="f" (
    echo ^>^>x264
    .\curl.exe --connect-timeout 5 -f -o %X264_PATH% -L %X264_URL%
    echo;
)
if "%NERO%"=="t" goto check
echo;
echo;
echo;
echo ^>^>%NERO_LICENSE1%
echo ^>^>%NERO_LICENSE2%
echo ^>^>%NERO_LICENSE3%
echo;
echo ^>^>%PAUSE_MESSAGE2%
pause>nul
echo;
start rundll32 url.dll,FileProtocolHandler "http://www.nero.com/jpn/downloads-nerodigital-nero-aac-codec.php"

:agree
echo ^>^>%NERO_QUESTION%
set /p AGREE=^>^>

if /i "%AGREE%"=="y" goto agree_main
if /i "%AGREE%"=="n" exit

echo;
echo ^>^>%RETURN_MESSAGE1%
echo;
goto agree

:agree_main
echo ^>^>neroAacEnc
.\curl.exe --connect-timeout 5 -f -o %NERO_PATH% -L %NERO_URL%
echo;

goto check


rem ################庤摦儌乕僪################
:auto_mode_off
echo ^>^>%DOWNLOADER_MANUAL%
echo;
if "%AVS%"=="f" echo Avisynth仺%AVS_URL%
if "%DSS%"=="f" echo DirectShowSource仺%DSS_URL%
if "%DIL%"=="f" echo DevIL仺%DIL_URL%
if "%FSS%"=="f" echo FFmpegSource仺%FSS_URL%
if "%QTS%"=="f" echo QTSource仺%QTS_URL%
if "%MIF%"=="f" echo MediaInfo仺%MIF_URL%
if "%YDF%"=="f" echo yadif仺%YDF_URL%
if "%A2P%"=="f" echo avs2pipe仺%A2P_URL%
if "%WVI%"=="f" echo wavi仺%WVI_URL%
if "%NERO%"=="f" echo NeroDigitalAudio仺%NERO_URL%
if "%X264%"=="f" echo x264仺%X264_URL%
echo;


echo ^>^>%PAUSE_MESSAGE2%
pause>nul
exit


rem ################棊偲偣偨偐偳偆偐傪僠僃僢僋################
:check
call :file_check_sub
date /t>nul
echo %AVS%%DSS%%DIL%%FSS%%QTS%%MIF%%YDF%%A2P%%WVI%%NERO%%X264% | findstr "f">nul
if "%ERRORLEVEL%"=="0" goto dl_fail


rem ################惉岟################
echo;
echo ^>^>%DOWNLOADER_END%
echo;
echo ^>^>%PAUSE_MESSAGE2%
pause>nul
exit


rem ################幐攕################
:dl_fail
set DL_STATUS=fail
echo;
echo ^>^>%DOWNLOADER_ERROR1%
echo ^>^>%DOWNLOADER_ERROR2%
echo;
if "%AVS%"=="f" echo Avisynth
if "%DSS%"=="f" echo DirectShowSource
if "%DIL%"=="f" echo DevIL
if "%FSS%"=="f" echo FFmpegSource
if "%QTS%"=="f" echo QTSource
if "%MIF%"=="f" echo MediaInfo
if "%YDF%"=="f" echo yadif
if "%A2P%"=="f" echo avs2pipe
if "%WVI%"=="f" echo wavi
if "%NERO%"=="f" echo NeroDigitalAudio
if "%X264%"=="f" echo x264
echo;
echo;
echo ^>^>%DOWNLOADER_ERROR3%
echo ^>^>%DOWNLOADER_ERROR4%
echo;
echo ^>^>%PAUSE_MESSAGE2%
pause>nul
exit


rem ################僼傽僀儖僠僃僢僋偺僒僽儖乕僠儞################
:file_check_sub
for %%i in (%AVS_PATH%) do if %%~zi EQU %AVS_SIZE% set AVS=t
for %%i in (%DSS_PATH%) do if %%~zi EQU %DSS_SIZE% set DSS=t
for %%i in (%DIL_PATH%) do if %%~zi EQU %DIL_SIZE% set DIL=t
for %%i in (%FSS_PATH%) do if %%~zi EQU %FSS_SIZE% set FSS=t
for %%i in (%QTS_PATH%) do if %%~zi EQU %QTS_SIZE% set QTS=t
for %%i in (%MIF_PATH%) do if %%~zi EQU %MIF_SIZE% set MIF=t
for %%i in (%YDF_PATH%) do if %%~zi EQU %YDF_SIZE% set YDF=t
for %%i in (%A2P_PATH%) do if %%~zi EQU %A2P_SIZE% set A2P=t
for %%i in (%WVI_PATH%) do if %%~zi EQU %WVI_SIZE% set WVI=t
for %%i in (%NERO_PATH%) do if %%~zi EQU %NERO_SIZE% set NERO=t
if not exist %X264_PATH% exit /b
%X264_PATH% --version>"%TEMP_DIR%\x264_version.txt" 2>nul
date /t>nul
findstr /i "%X264_VERSION%" "%TEMP_DIR%\x264_version.txt">nul 2>&1
if "%ERRORLEVEL%"=="0" set X264=t
exit /b
