@echo off

rem ********************************************************************************
rem *
rem * Modify-ADS-Updates.BAT
rem *
rem * This file calls the Microsoft ADS floppy disk creation program to send the virtual
rem * floppy disk image for BIOS updates to the floppy drive so that it can be modified.
rem *
rem ********************************************************************************
title Modifying ADS BIOS updates virtual floppy disk

rem ********************************************************************************
rem * Call the msiadspt.bat file to set the ADS_PATH variable is set.
rem ********************************************************************************
call msiadspt.bat

rem ********************************************************************************
rem * Restore backup file if it exists. This scenario means that the write 
rem *  procedure was probably canceled by hitting the window's 'X', and the 
rem *  backup was not restored properly.
rem ********************************************************************************
if not exist "%ADS_PATH%\tftproot\tk_updt.$fd" goto BEGIN
echo tk_updt.vfd was corrupted during last modification, restoring last backup...
copy "%ADS_PATH%\tftproot\tk_updt.$fd" "%ADS_PATH%\tftproot\tk_updt.vfd" /Y
del "%ADS_PATH%\tftproot\tk_updt.$fd"
echo.

:BEGIN
rem ********************************************************************************
rem * Write the Virtual Disk Image To The Floppy Disk.
rem ********************************************************************************
echo Copying virtual floppy disk image to diskette for modification:
call "%ADS_PATH%\bin\dskimage.exe" "%ADS_PATH%\tftproot\tk_updt.vfd" A:
echo.

if not ERRORLEVEL 0 goto ERROR1


rem ********************************************************************************
rem * Open the netvars.bat file for editing.
rem ********************************************************************************
echo You may now edit NETVARS.BAT, the virtual disk modification process will 
echo  continue when you exit notepad...
echo.
call notepad.exe A:\netvars.bat

rem ********************************************************************************
rem * Open the usrvars.bat file for editing.
rem ********************************************************************************
echo You may now edit USRVARS.BAT, the virtual disk modifications will be
echo  written when you exit notepad...
echo.
call notepad.exe A:\usrvars.bat

rem ********************************************************************************
rem * Update the network variables that were changed in netvars.bat
rem ********************************************************************************
echo Updating network files on the diskette. This may take up to a minute...
call ..\boot\Update-Network-Files.bat
echo.

rem ********************************************************************************
rem * Create a backup copy of the virtual floppy in case an error occurs
rem ********************************************************************************
echo Creating a backup of the virtual floppy...
copy "%ADS_PATH%\tftproot\tk_updt.vfd" "%ADS_PATH%\tftproot\tk_updt.$fd" /Y
echo.

rem ********************************************************************************
rem * Write the floppy disk back to the virtual floppy disk.
rem ********************************************************************************
echo Modifying virtual floppy disk image:

call "%ADS_PATH%\bin\dskimage.exe" A: "%ADS_PATH%\tftproot\tk_updt.vfd"

if not ERRORLEVEL 0 goto ERROR2
goto SUCCESS

:ERROR1
echo.
echo An error occurred when writing the virtual disk image to the floppy disk. 
echo  Make sure that the disk is in the drive and it is not write protected. 
echo  Also check that the path to the virtual floppy disk is correct:
echo.
echo %ADS_PATH%\tftproot\

goto END


:ERROR2
rem ********************************************************************************
rem * Error occured while writing the disk which also corrupts the original image.
rem *   Echo error message and restore a good copy of the virtual floppy.
rem ********************************************************************************
echo.
echo.
echo An error occurred when writing the virtual disk image to the ADS server.
echo  Make sure that the disk is in the drive and that you have permissions to 
echo  write to the location of the ADS virtual floppy disks:
echo.
echo %ADS_PATH%\tftproot\
echo.
echo.

echo Restoring the tk_updt.vfd from the backup copy...
copy "%ADS_PATH%\tftproot\tk_updt.$fd" "%ADS_PATH%\tftproot\tk_updt.vfd" /Y

goto END


:SUCCESS
echo.
echo Virtual disk modifications complete.

:END
rem ********************************************************************************
rem * Clean up temporary files and exit
rem ********************************************************************************
if exist "%ADS_PATH%\tftproot\tk_updt.$fd" del "%ADS_PATH%\tftproot\tk_updt.$fd"
echo.
pause
