# Use for installing Win Vista, 2K8R2 or Win7 from a menu (no user choices)
# see also $$AddWin2Main.mnu  for a more compact menu

title Install Windows 7 ISO \n Install Windows 7
# run win ISO - ISO MUST BE IN \_ISO\WINDOWS\xxx folder
debug 1

set ISO=Win7_32_SP1.iso
set OS=WIN7
set XML=/_ISO/e2b/FiraDisk/au.xml



#get size of boot device in GB in SG (allow for 2TB drives - max grub4dos +ve number is 0x7FFFFFFFFFFFFFFF 1TB)
geometry (bd) > (md)0x333+1
cat --locate=/512 --replace=\x00 (md)0x333+1 > nul
cat --locate=nt/Size= (md)0x333+1 > nul
set /A a=%?%+8 > nul
cat --skip=%a% (md)0x333+1 | set a=
set /a a=%a%>>2 > nul
set /a a=%a%/2048 > nul
set /a SG=%a%/1024 > nul
set /a SG=%SG%<<2 > nul
if "%SG%"=="0" set SG=1


# fill (rd) with 0's , 0x82d0 is rd-base mem address, Fn24 is memset - fill memory  <addr> <string> <size>
map (md)0x300+200 (rd) > nul ;; read 0x82d0 > nul ;; call Fn.24  %@retval% 0x20  102400 > nul  

echo -e Using %ISO% with %XML%
#echo Booting...
if not exist CD dd if=(rd)+1 of=()/AutoUnattend.xml > nul
if not exist CD dd if=(bd)%XML% of=()/AutoUnattend.xml > nul
# if extra USB Flash drive use Autounattend.xml on it - must have WINHELPER.USB file on it!

set WH=
if exist (hd1,0)/WINHELPER.USB root (hd1,0) > nul && set WH=1
if "%WH%"=="" if exist (hd0,0)/WINHELPER.USB root (hd0,0) > nul && set WH=1
if "%WH%"=="" if exist (hd2,0)/WINHELPER.USB root (hd2,0) > nul && set WH=1
if "%WH%"=="" if exist (hd3,0)/WINHELPER.USB root (hd3,0) > nul && set WH=1
if "%WH%"=="" if exist (hd4,0)/WINHELPER.USB root (hd4,0) > nul && set WH=1
if "%WH%"=="" if exist (hd5,0)/WINHELPER.USB root (hd5,0) > nul && set WH=1
if "%WH%"=="" if exist (hd6,0)/WINHELPER.USB root (hd6,0) > nul && set WH=1
if "%WH%"=="" if exist (hd7,0)/WINHELPER.USB root (hd7,0) > nul && set WH=1
if "%WH%"=="" if exist (hd8,0)/WINHELPER.USB root (hd8,0) > nul && set WH=1
if "%WH%"=="" if exist (hd9,0)/WINHELPER.USB root (hd9,0) > nul && set WH=1

if "%WH%"=="1" if not exist /AutoUnattend.xml echo -e $$STRbV05 && pause
#USB DRIVE HAS WINHELPER.USB file but no AutoUnattend.xml! 

#check if running from HDD with no HELPER USB drive
if %SG%>=128 if not "%WH%"=="1" echo

if %SG%>=128 if not "%WH%"=="1" echo -e $$STRbV03
#if %SG%>=128 if not "%WH%"=="1" echo $[0104]WARNING: To install Windows from a USB Hard disk you also need an E2B HELPER USB Flash drive. 
#if %SG%>=128 if not "%WH%"=="1" echo $[0104]If you do not have one you will get a 'DVD drive device driver is missing' message.
#if %SG%>=128 if not "%WH%"=="1" echo $[0104]Please read the Easy2Boot Tutorial for more details.

if %SG%>=128 if not "%WH%"=="1" set /p ask=$$STRbV04
#Press C to continue or press [Enter] to return : 
if %SG%>=128 if not "%WH%"=="1" if not /i "%ask%"=="C" echo -e \nAborting... && /%grub%/configX.g4b (bd)/%grub%/menuWinInstall.lst
if %SG%>=128 if not "%WH%"=="1" echo

if "%WH%"=="1" dd if=(rd)+1 of=()/AutoUnattend.xml > nul
if "%WH%"=="1" dd if=(bd)%XML% of=()/AutoUnattend.xml > nul
set WH=
root (bd)
if not exist CD dd if=(rd)+1 of=()/_ISO/e2b/firadisk/ISONAME.CMD > nul
if not exist CD write (bd)/_ISO/e2b/firadisk/ISONAME.CMD SET \"MYISO=\\_ISO\\WINDOWS\\%OS%\\%ISO%\"\r\n > nul

# run the grub4dos map command and specify the iso file we want to load
debug 1
errorcheck on
echo -e \nLoading /_ISO/Windows/%OS%/%ISO% - please wait ...
map /_ISO/Windows/%OS%/%ISO% (0xff)
if not exist CD map (hd0) (hd1)
if not exist CD map (hd1) (hd0)
map --hook
# Specify the same iso file for when firadisk runs in winpe
chainloader (0xff)/BOOTMGR || chainloader (0xff)

#get rid of 'press any key' prompt
cat --locate=BOOTFIX.BIN --number=1 --replace=XXX (0xff)+0x1000

boot
