@echo off
cls
TITLE %~n0
:: set cmd shell window size
mode con: cols=120 lines=60
echo.
color 1f
echo %~n0 (using RoboCopy)
echo.
echo.
echo Action: Updates files on an existing Easy2Boot USB drive.
echo.
echo Source: %~dp0
echo.
echo         Old E2B v1.5x files will be replaced.
echo         Your own files will not be deleted.
echo.
echo.
echo Note: To make a new E2B drive, please use the \Make_E2B_USB_DRIVE (run as admin).cmd file.
echo.
echo.
echo.

set str=%~dp0
set str=%STR:~-2,2%
if "%str%"==":\" echo ERROR: Source is a drive! Please run %~nx0 from the download folder & color 4f & pause & goto :EOF
set str=

pushd %~dp0

echo.%~pn0 | find /I "Desktop\Update_e2b">nul && (set ERR=0) || (set ERR=1)
if "%ERR%"=="0" echo ERROR: Please extract the Easy2Boot files to an EMPTY FOLDER - not the Desktop! & color 4f & pause & goto :EOF
set ERR=

wmic logicaldisk get caption,volumename,description,Size | find "Disk" | sort /+1
echo.
echo.

set ask=%1
if "%ask%"=="" set /P ask=E2B USB Drive Letter to update? (e.g. E) : 
if "%ask%"=="" goto :EOF
set USB=%ask:~0,1%

if exist "%USB%:\_ISO\e2b\grub\menu.lst" goto :cc1
echo.
echo WARNING: Drive %USB%: does not already contain E2B!
echo.
set /P cont=Continue to update? ([N]/Y) : 
if /i not "%cont%"=="Y" goto :eof


:cc1
set DF=ZZA_FASTLOAD_ON_OFF.mnu
call :delzz
set DF=ZZSubMenuAntiVirus.mnu
call :delzz
set DF=ZZSubMenuAuto.mnu
call :delzz
set DF=ZZSubMenuBackup.mnu
call :delzz
set DF=ZZSubMenuDos.mnu
call :delzz
set DF=ZZSubMenuLinux.mnu
call :delzz
set DF=ZZSubMenuUtilities.mnu
call :delzz
set DF=ZZSubMenuWin.mnu
call :delzz
set DF=ZZSubMenuWinPE.mnu
call :delzz
set DF=ZZWindowsInstall.mnu
call :delzz
set DF=ZZZF1SubMenuHelp.mnu
call :delzz
set DF=ZZZF7BootHdd.mnu
call :delzz
set DF=ZZZF8$_SHOW_FASTLOAD.mnu
call :delzz
set DF=ZZZF8ReloadMenu.mnu
call :delzz
set DF="Place *"
call :delzz
set DF="\MNU\Read Me*"
call :delzz
set DF="\MNU\Note Any*.*"
call :delzz
if exist %USB%:\_ISO\FASTLOAD.YES del %USB%:\_ISO\FASTLOAD.YES
if exist %USB%:\_ISO\FASTLOAD_Read_Me.txt del %USB%:\_ISO\FASTLOAD_Read_Me.txt

::tidy up old files
if exist "%USB%:\_ISO\docs\Sample mnu Files\*.mnu" del "%USB%:\_ISO\docs\Sample mnu Files\*.mnu"
if exist "%USB%:\_ISO\docs\Sample mnu Files\Win7*.ini" del "%USB%:\_ISO\docs\Sample mnu Files\Win7*.ini"
if exist "%USB%:\_ISO\docs\Sample mnu Files\POS*.txt" del "%USB%:\_ISO\docs\Sample mnu Files\POS*.txt" 
if exist "%USB%:\_ISO\docs\Sample mnu Files\kali*.txt" del "%USB%:\_ISO\docs\Sample mnu Files\kali*.txt"
if exist "%USB%:\_ISO\docs\Sample mnu Files\crunch*.txt" del "%USB%:\_ISO\docs\Sample mnu Files\crunch*.txt"
if exist "%USB%:\_ISO\docs\Sample mnu Files\E2B Menus\PTN2_Menu.mnu" del "%USB%:\_ISO\docs\Sample mnu Files\E2B Menus\PTN2_Menu.mnu"
if exist "%USB%:\_ISO\docs\Sample mnu Files\E2B Menus\PTN_Log1_Menu.mnu" del "%USB%:\_ISO\docs\Sample mnu Files\E2B Menus\PTN_Log1_Menu.mnu"

if exist "%USB%:\_ISO\docs\E2B Utilities\Make SubMenu.cmd" del "%USB%:\_ISO\docs\E2B Utilities\Make SubMenu.cmd"
REM ZGRUB_USB_046.mnu has moved
if exist %USB%:\_ISO\MAINMENU\ZGRUB_USB_046.mnu del %USB%:\_ISO\MAINMENU\ZGRUB_USB_046.mnu

echo.
REM exclude .zip files and this file (must add \ at end if enclosing in quotes)
echo RoboCopy...
REM robocopy "%~dp0\" %USB%:\\ /E /NFL /NDL /NJH /r:2 /w:3 /MT:1 /XF *.7z *.zip %~nx0 "MAKE_E2B_USB_DRIVE (run as admin).cmd" E2B_ReadMe.txt
robocopy "%~dp0\" %USB%:\\ /E /NFL /NDL /NJH /r:2 /w:3 /MT:1 /XF %~nx0 "MAKE_E2B_USB_DRIVE (run as admin).cmd" E2B_ReadMe.txt

echo ------------------------------------------------------------------------------
    if %ERRORLEVEL% EQU 16 echo ***FATAL ERROR*** & goto end1
    if %ERRORLEVEL% EQU 15 echo COPIED + FAIL + MISMATCHES + EXTRA  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 14 echo FAIL + MISMATCHES + EXTRA FILES  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 13 echo COPIED + FAIL + MISMATCHES  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 12 echo FAILED + MISMATCHES  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 11 echo COPY + FAIL + EXTRA (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 10 echo FAILED + EXTRA  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 9 echo COPY OK + FAIL  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 8 echo FAILED  (some files not copied!) & goto end1
    if %ERRORLEVEL% EQU 7 echo COPIED OK, SOME MISMATCHES + EXTRA FILES  - POSSIBLE ERRORS? & goto end1
    if %ERRORLEVEL% EQU 6 echo MISMATCH, EXTRA FILES COPIED  - POSSIBLE ERRORS? & goto end1
    if %ERRORLEVEL% EQU 5 echo MISMATCH, COPIED OK  - POSSIBLE ERRORS? & goto end1
    if %ERRORLEVEL% EQU 4 echo MISMATCH - POSSIBLE ERRORS? & goto end1
    if %ERRORLEVEL% EQU 3 echo UPDATED OK & goto end1
    if %ERRORLEVEL% EQU 2 echo ALREADY UP TO DATE (NO CHANGES MADE) & goto end1
    if %ERRORLEVEL% EQU 1 echo FILES UPDATED OK & goto end1
REM    if %ERRORLEVEL% EQU 0 echo ALREADY UP TO DATE (NO CHANGES MADE) & goto end1
:end1

REM Robocopy gives errorlevel 0 if access denied!!!

REM if error or no changes, don't make MyE2B.cfg
if %ERRORLEVEL%==0 goto skipcfg
if %ERRORLEVEL%==2 goto skipcfg
if %ERRORLEVEL% GTR 9000 echo NO ROBOCOPY! Using XCOPY /d to update - please wait... & echo. & xcopy /cherkyd "%~dp0*.*" %USB%:\ > nul
if %ERRORLEVEL% GTR 7 goto skipcfg
echo.


REM Make new MyE2B.cfg file
if not exist %USB%:\_ISO\MyE2B.cfg if exist .\_ISO\docs\Make_E2B_USB_Drive\Make_MyE2B.cfg.cmd call .\_ISO\docs\Make_E2B_USB_Drive\Make_MyE2B.cfg.cmd %USB%:


:skipcfg

if exist "%USB%:\MAKE_E2B_USB_DRIVE (run as admin).cmd" del "%USB%:\MAKE_E2B_USB_DRIVE (run as admin).cmd"
if exist %USB%:\E2B_ReadMe.txt del %USB%:\E2B_ReadMe.txt
if exist %USB%:\%~nx0 del %USB%:\%~nx0
:: copy bootmgr for NTBOOT if present
if not exist %USB%:\_ISO\e2b\grub\DPMS\NTBOOT.MOD\bootmgr if exist C:\bootmgr xcopy /h c:\bootmgr %USB%:\_ISO\e2b\grub\DPMS\NTBOOT.MOD > nul
if not exist %USB%:\_ISO\e2b\grub\DPMS\NTBOOT.MOD\bootmgr if exist "%SystemRoot%\Boot\PCAT\bootmgr" xcopy /h "%SystemRoot%\Boot\PCAT\bootmgr" %USB%:\_ISO\e2b\grub\DPMS\NTBOOT.MOD > nul

echo.
REM echo Finished!
pause
goto :EOF

:delzz
if exist %USB%:\_ISO\MAINMENU\%DF% del %USB%:\_ISO\MAINMENU\%DF%
goto :eof



