@echo off
if exist runpatch.bat del runpatch.bat
echo set QUAKE_DIR=%QUAKE_DIR%>quakedir.bat
if "%QUAKE_DIR%"=="" goto quakedir_not_set
goto check_quakedir
:quakedir_not_set
:reget_quakedir
call quakedir.bat
rem Previous line in case QUAKE_DIR was set and user aborts
echonl set QUAKE_DIR=>temp.bat
echonl Please enter your Quake directory (Default "c:\quake"):
echosp
askutil c:\quake>>temp.bat
if errorlevel 1 goto end
call temp.bat
if not exist %QUAKE_DIR%\nul echo Error finding Quake dir, make sure you don't include a trailing backslash.
if not exist %QUAKE_DIR%\nul echo.
:check_quakedir
if not exist %QUAKE_DIR%\nul goto reget_quakedir

:askreplace
echonl set NEW=>temp.bat
echonl Do you wish to replace your existing maps (answering no will make backups)?
echosp
askutil N>>temp.bat
if errorlevel 1 goto end
call temp.bat
if "%NEW%"=="Y" goto replace_gotanswer
if "%NEW%"=="y" goto replace_gotanswer
if "%NEW%"=="N" goto replace_gotanswer
if "%NEW%"=="n" goto replace_gotanswer
echo Please answer "Y" or "N"
goto askreplace
:replace_gotanswer

if "%NEW%"=="Y" SET NEW=
if "%NEW%"=="y" SET NEW=
if "%NEW%"=="N" SET NEW=-new
if "%NEW%"=="n" SET NEW=-new

for %%f in (*.vis) do call instpack %%f
:end
call quakedir.bat
rem Sets whatever Quakedir user had before
del quakedir.bat
if exist temp.bat del temp.bat
rem If user ctrl-c'd the input

if not exist runpatch.bat goto error
echo.
echonl Press a key to begin the patching process (may take a few minutes).
pause>nul
echo.
call runpatch.bat
del runpatch.bat
goto realend
:error
echo No patch files (*.vis) found, or all patches were skipped.
echo Please download a patch file and rerun.
:realend
