@echo off
rem ----------------------------------------
rem 
rem Updates the MS-DOS 6.x binary specified 
rem by F_NAME to MS-DOS 6.22. Also copies 
rem full binaries to target directory.
rem 
rem ----------------------------------------

rem ++++++ File Name Variables +++++++++++++
set F_NAME=EMM386
set F_EXT=EXE
goto chkpath

rem Use previously set F_NAME to change F_NAME
:EMM386
rem set F_NAME=MSD
rem set F_EXT=EXE
rem goto chkpath

rem :MSD
goto end
rem ++++++ End File Name Vars ++++++++++++++

:chkpath
if "%1"=="" goto noargs

echo A path of %1 was given...
if not exist %1\%F_NAME%.%F_EXT% goto help
set F_TARGET=%1\%F_NAME%.%F_EXT%
rem ** Special COM file handling **
if exist %1\%F_NAME%.COM set COM_TARG=%1\%F_NAME%.COM
rem ** End special handling **
goto preupdate

:noargs
if not exist C:\DOS\%F_NAME%.%F_EXT% goto noargs2
echo Found C:\DOS\%F_NAME%.%F_EXT%
set F_TARGET=C:\DOS\%F_NAME%.%F_EXT%
rem ** Special COM file handling **
if exist C:\DOS\%F_NAME%.COM set COM_TARG=C:\DOS\%F_NAME%.COM
rem ** End special handling **
goto preupdate

:noargs2
if not exist C:\MSDOS\%F_NAME%.%F_EXT% goto help
echo Found C:\MSDOS\%F_NAME%.%F_EXT%
set F_TARGET=C:\MSDOS\%F_NAME%.%F_EXT%
rem ** Special COM file handling **
if exist C:\MSDOS\%F_NAME%.COM set COM_TARG=C:\MSDOS\%F_NAME%.COM
rem ** End special handling **

:preupdate
if not exist %F_NAME%.%F_EXT% goto prepatch
copy %F_NAME%.%F_EXT% %F_TARGET%
rem ** Special handling for COM file of same name **
if "%F_EXT%"=="COM" goto %F_NAME%
if "%F_EXT%"=="com" goto %F_NAME%
if exist %COM_TARG% rename %COM_TARG% OLD%F_NAME%.COM
rem ** End special handling **
goto %F_NAME%

:prepatch
if not exist .\MSUPDATE.EXE goto no_patcher
cls
echo.
echo %0 uses the MSUPDATE.EXE program to update your copy of 
echo the %F_NAME%.%F_EXT% file to MS-DOS 6.22.
echo.
echo NOTICE: By installing and using the SOFTWARE you are agreeing to be 
echo         bound by the terms of this Agreement. If you do not agree 
echo         to the terms of this Agreement, promptly delete the SOFTWARE 
echo         from your computer.
echo.
echo This Agreement permits you to make and use copies of the MSUPDATE 
echo software program (the "SOFTWARE") provided that each such copy 
echo is used only on a single computer which contains a licensed copy 
echo of the Microsoft(R) MS-DOS(R) 6.0 or higher operating system which 
echo has been validly licensed by you. You must maintain all copyright 
echo notices on all copies of the SOFTWARE. You may not rent or lease 
echo the SOFTWARE, but you may transfer the SOFTWARE on a permanent basis 
echo provided you retain no copies, include the most recent update and all 
echo prior versions of the SOFTWARE, and the recipient agrees to the terms of 
echo this Agreement. You may not reverse engineer, decompile, or disassemble 
echo the SOFTWARE. 
echo.
pause
echo.
echo.
echo.
echo THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. 
echo MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, 
echo INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY 
echo AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT OR 
echo ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT 
echo LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, 
echo LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING OUT 
echo OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF MICROSOFT HAS 
echo BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME STATES 
echo DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL 
echo OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAY NOT APPLY TO YOU. 
echo The SOFTWARE is provided with RESTRICTED RIGHTS. Use, duplication, 
echo or disclosure by the Government is subject to restrictions as set 
echo forth in subparagraph (c)(1)(ii) of The Rights in Technical Data and 
echo Computer Software clause at DFARS 252.227-7013 or subparagraphs (c)(1) 
echo and (2) of the Commercial Computer Software-Restricted Rights 
echo at 48 CFR 52.227-19, as applicable.  Manufacturer is Microsoft 
echo Corporation/One Microsoft Way/Redmond, WA  98052-6399. This 
echo Agreement is governed by the laws of the State of Washington.
echo.
echo.
CHOICE "Do you agree to abide by the terms of this agreement "
if errorlevel 2 goto end
if errorlevel 1 goto patch
echo Do you agree to abide by the terms of this agreement?
echo.
echo If not, press Ctrl+C to quit. Otherwise,
pause

:patch
CLS
MSUPDATE %F_TARGET%
set F_TARGET=
goto %F_NAME%

:help
echo.
echo %0 needs the location of %F_NAME%.%F_EXT%.
echo Restart %0 with path to %F_NAME%.%F_EXT%.
echo Example:
echo    %0 C:\DOSFILES
echo.
goto end

:no_patcher
echo.
echo In order to update %F_NAME%.%EXT%, you must
echo start %0 from the drive and directory that 
echo contains the MSUPDATE.EXE program.
echo.
goto end

:end
set F_NAME=
set F_EXT=
