@echo off

set old_path=%path%

set temp_file=_xx__zyq

:noTEMP
echo hi > c:\%temp_file%
if not exist c:\%temp_file% goto DDrive
del c:\%temp_file%
set temp_dir=C:\
goto foundtmp

:DDrive
echo hi > d:\%temp_file%
if not exist d:\%temp_file% goto ADrive
del d:\%temp_file%
set temp_dir=D:\
goto foundtmp

:ADrive
echo hi > a:\%temp_file%
if not exist a:\%temp_file% goto fail
del a:\%temp_file%
set temp_dir=A:\
goto foundtmp

:fail
echo Sorry, I can not find any drive to copy in.
goto end

:foundtmp

if m%1 == m goto hint

:DIRTOOL will change directory to %1 in full-path style if possible
tools\DIRTOOL %1 > %temp_dir%%temp_file%.bat
if errorlevel 1 goto end
:DIRTOOL-gened xxs_e_t.bat will setenv SRC_PATH and DEST_PATH for me :p
call %temp_dir%%temp_file%.bat
del %temp_dir%%temp_file%.bat

mkdir %DEST_PATH%Ritouch
echo Copy files...
copy /y %SRC_PATH%drivers\*.* %DEST_PATH%Ritouch > nul
copy /y %SRC_PATH%readme.txt %DEST_PATH%Ritouch > nul
echo Copy files...Done

if exist C:\AUTOEXEC.RIT copy /y C:\AUTOEXEC.RIT C:\AUTOEXEC.BAT > nul
if not exist C:\AUTOEXEC.BAT goto no_auto_1
	copy /y C:\AUTOEXEC.BAT C:\AUTOEXEC.RIT > nul
:no_auto_1
echo Append settings to C:\AUTOEXEC.BAT...
if not exist C:\AUTOEXEC.BAT goto no_auto_2
	echo (Original C:\AUTOEXEC.BAT is saved as AUTOEXEC.RIT)
:no_auto_2
echo. >> C:\AUTOEXEC.BAT
echo set path=%%path%%;%DEST_PATH%Ritouch >> C:\AUTOEXEC.BAT
echo RITOUCH.EXE >> C:\AUTOEXEC.BAT
echo rem Execute "RITOUCH /?" to list options >> C:\AUTOEXEC.BAT
echo.
echo Installation OK, please REBOOT.
goto end

:hint
cls
echo *************************************
echo *                                   *
echo *    Ritouch for DOS Installer      *
echo *                                   *
echo *************************************
echo.
echo syntax: INSTALL dest_dir
echo.
echo ex. "INSTALL C:\DIR" will install driver into C:\DIR\Ritouch
echo.
goto end
:end
set path=%old_path%
set old_path=
set temp_file=
set temp_dir=
set SRC_PATH=
set DEST_PATH=
echo.

