@echo off

xcopy ISOFOLDER\x64\boot\* ISOFOLDER\boot\ /cheriky >nul 2>&1
xcopy ISOFOLDER\x64\efi\* ISOFOLDER\efi\ /cheriky >nul 2>&1
for /d %%G in (bootmgr,bootmgr.efi,setup.exe) do (copy /y ISOFOLDER\x64\%%G ISOFOLDER\%%G >nul 2>&1)
copy /y ISOFOLDER\x86\efi\microsoft\boot\memtest.efi ISOFOLDER\efi\microsoft\boot\mtest32.efi >nul 2>&1
copy /y bin\efi\bootia32.efi ISOFOLDER\efi\boot\bootia32.efi >nul 2>&1
copy /y ISOFOLDER\x86\bootmgr.efi ISOFOLDER\bootmgfw.efi >nul 2>&1
(echo [AutoRun.Amd64]
echo open=x64\setup.exe
echo icon=x64\setup.exe,0
echo.
echo [AutoRun]
echo open=x86\setup.exe
echo icon=x86\setup.exe,0
echo.)>ISOFOLDER\autorun.inf
bcdedit /store ISOFOLDER\boot\bcd /set {default} description "Windows 10 Setup (64-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} bootmenupolicy Legacy >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} device ramdisk=[boot]\x64\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set {default} osdevice ramdisk=[boot]\x64\sources\boot.wim,%ramdiskoptions% >nul 2>&1
for /f "tokens=2 delims={}" %%A in ('bcdedit /store ISOFOLDER\boot\bcd /copy {default} /d "Windows 10 Setup (32-bit)"') do set guid={%%A}
bcdedit /store ISOFOLDER\boot\bcd /set %guid% device ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\boot\bcd /set %guid% osdevice ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {bootmgr} NoIntegrityChecks 1 >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /deletevalue {bootmgr} flightsigning >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} description "Windows 10 Setup (64-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} device ramdisk=[boot]\x64\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} osdevice ramdisk=[boot]\x64\sources\boot.wim,%ramdiskoptions% >nul 2>&1
copy /y ISOFOLDER\efi\microsoft\boot\bcd ISOFOLDER\efi\microsoft\boot\b32 >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {globalsettings} NoIntegrityChecks 1 >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {globalsettings} Testsigning 1 >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} description "Windows 10 Setup (32-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} device ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} osdevice ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} loadoptions DISABLE_INTEGRITY_CHECKS >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} inherit {globalsettings} >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {memdiag} path \efi\microsoft\boot\mtest32.efi >nul 2>&1
rd /s /q .\bin\temp >nul 2>&1

exit /b
