!BAT

#%1 has name of Windows folder,  %2 has name of XML file (user choose if blank)
set OS=%1
if "%OS%"=="" echo BAD PARAMETER 1 for %0 && pause && commandline

# load getstr batch file into memory
#load module if not already loaded
debug 0
delmod -l getstr.g4b || insmod /%grub%/getstr.g4b
debug 1


#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

if not "%2"=="" set XML=%2 && goto :skipkey

clear
getstr.g4b $$STRbV01
echo -e %STR%

#echo Select an Unattend.XML file
#echo -e ===========================
set ask=
getstr.g4b $$STRbV02
set ZZ=%STR%
#Use Easy2Boot XML file
/%grub%/PickaFile.g4b %OS% .XML
#if no user xmls then use default
if "%FCOUNT%"=="0" set CHOSEN=0
echo
# check if user aborted
set XML=%OS%/%CHOSEN%
if "%CHOSEN%"=="0" set XML=/_ISO/e2b/FiraDisk/au.xml
if "%CHOSEN%"==""  echo Aborting... && /%grub%/configX.g4b (bd)/%grub%/menuWinInstall.lst

:skipkey

# 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!
#findx /WINHELPER.USB && findX --set-root /WINHELPER.USB &&  ls /AutoUnattend.xml > nul  || echo USB DRIVE HAS WINHELPER.USB file but no AutoUnattend.xml! && pause
set WH=
# don't abort if error accessing other drive
errorcheck off
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
getstr.g4b $$STRbV05
if "%WH%"=="1" if not exist /AutoUnattend.xml echo -e %STR% && 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
getstr.g4b $$STRbV03
if %SG%>=128 if not "%WH%"=="1" echo -e %STR%
#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.
getstr.g4b $$STRbV04
if %SG%>=128 if not "%WH%"=="1" set /p ask=%STR%
#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) > nul
if not exist CD dd if=(rd)+1 of=()/_ISO/e2b/firadisk/ISONAME.CMD > nul

### CHANGED 12-09-2014
if not exist CD write (bd)/_ISO/e2b/firadisk/ISONAME.CMD SET \"MYISO=%OS%\\%ISO%\"\r\n > nul
if not exist CD cat --locate=/ --replace=\\ (bd)/_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

##map --mem (md)0x800+4 (99)
# run the grub4dos map command and specify the iso file we want to load
debug 1
errorcheck on
echo -e \nLoading %OS%/%ISO% - please wait ...
map %OS%/%ISO% (0xff) > nul
if not exist CD map (hd0) (hd1) > nul
if not exist CD map (hd1) (hd0) > nul
map --hook
rootnoverify (hd0,0)
# Specify the same iso file for when firadisk runs in winpe
##write (99) [FiraDisk]\nStartOptions=cdrom,vmem=find:%OS%/%ISO%;\n\0
chainloader (0xff)/BOOTMGR > nul || chainloader (0xff) > nul

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

exit

