@echo off

rem script:	   abbodi1406, @rgadguard
rem wimlib:	   synchronicity
rem Thanks to: @Ratiborus58, @NecrosoftCore, @DiamondMonday, @WzorNET

set "params=%*"
cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )

set "vers=v171020_test"
title Decrypt UUPs -^> ISO - %vers%
echo Preparing...
if not exist "%~dp0bin\wimlib-imagex.exe" goto :eof
IF /I "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (SET "wimlib=%~dp0bin\bin64\wimlib-imagex.exe"&set "dism=%~dp0bin\bin64\dism.exe") ELSE (SET "wimlib=%~dp0bin\wimlib-imagex.exe"&set "dism=%~dp0bin\dism.exe")
cd /d "%~dp0"
setlocal EnableExtensions
setlocal EnableDelayedExpansion
color 1f
set bootedit=temp\boot.txt
SET UUP=
SET ERRORTEMP=
SET VOL=0
SET uups_esd_num=0
set uupa=0
set dual=0
SET "ramdiskoptions={7619dcc8-fafe-11d9-b411-000476eba25f}"
for /f "tokens=3 delims=: " %%b in ('dism /english /online /Get-Intl ^| find /i "System locale"') do set dlang=%%b && call :dlang
rmdir /s /q ISOFOLDER\ >nul 2>nul
rmdir /s /q %~dp0bin\temp\ >nul 2>nul
rmdir /s /q %~dp0temp\ >nul 2>nul
mkdir bin\temp >nul 2>nul
mkdir temp >nul 2>nul

if not [%1]==[] (if exist "%~1\*.esd" set "UUP=%~1"&goto :check)
if exist "%CD%\UUPs\*.esd" set "fold=%CD%\uups"&goto :uup_fold
if exist "%CD%\UUP\*" set "fold=%CD%\uup"&goto :uup_fold

:prompt
cls
set fold=
echo.
echo ===============================================================================
echo %txt01%
echo ===============================================================================
echo.
set /p fold=
if [%fold%]==[] goto :QUIT
goto :uup_fold

:check
set "fold="
call :uup_esd %UUP%
if %uups_esd_num% equ 0 (
echo.
echo ===============================================================================
echo %txt02%
echo ===============================================================================
echo.
echo %exitd%
pause >nul
goto :QUIT
)
if %uups_esd_num% gtr 1 (
for /L %%i in (1, 1, %uups_esd_num%) do call :uups_esd %%i
goto :MULTIMENU
)
call :uups_esd 1
set "MetadataESD=%UUP%\%uups_esd1%"&set "arch=%arch1%"&set "editionid=%edition1%"&set "langid=%langid1%"&set "nameos=!name1!"
goto :MAINMENU

:MULTIMENU
cls
set "fold=0"
set userinp=
echo ===============================================================================
echo %txt03%
echo ===============================================================================
echo.
for /L %%i in (1, 1, %uups_esd_num%) do (
echo %%i. !name%%i!
)
echo.
echo ===============================================================================
echo %txt04%
echo ===============================================================================
set /p userinp= ^> %txt05%: 
set userinp=%userinp:~0,6%
if %userinp%==0 goto :QUIT
if /i %userinp%==alliso set "uupa=1"&set "uupb=iso"&set WIMFILE=install.wim&goto :ALL
if /i %userinp%==allisz set "uupa=1"&set "uupb=iso"&set WIMFILE=install.esd&goto :ALL
if /i %userinp%==aiowim set "uupa=2"&set WIMFILE=install.wim&goto :AIO
if /i %userinp%==aioesd set "uupa=2"&set WIMFILE=install.esd&goto :AIO
if /i %userinp%==allwim set "uupa=1"&set "uupb=install"&set WIMFILE=install.wim&goto :ALL
if /i %userinp%==allesd set "uupa=1"&set "uupb=install"&set WIMFILE=install.esd&goto :ALL
for /L %%i in (1, 1, %uups_esd_num%) do (
if %userinp%==%%i set "MetadataESD=%UUP%\!uups_esd%%i!"&set "arch=!arch%%i!"&set "editionid=!edition%%i!"&set "langid=!langid%%i!"&set "nameos=!name%%i!"&goto :MAINMENU
)
goto :MULTIMENU

:MAINMENU
cls
set userinr=
echo ===============================================================================
echo %txt17%: %nameos%
echo ===============================================================================
echo.
echo.       1 - %txt07%
echo.       2 - %txt08%
echo.       3 - %txt20%
echo.       4 - %txt21%
echo.       5 - %txt06%
echo.
echo ===============================================================================
if [%fold%]==[] (echo %txt04%) else (echo %txt09%)
echo ===============================================================================
set /p userinr= ^> %txt10%: 
set userinr=%userinr:~0,1%
if %userinr%==0 GOTO :QUIT
if not [%fold%]==[] (if %userinr%==9 if [%fold%]==[0] (GOTO :MULTIMENU) else (GOTO :uup_fold))
if %userinr%==5 GOTO :INFO
if %userinr%==4 (set WIMFILE=install.esd&goto :Single)
if %userinr%==3 (set WIMFILE=install.wim&goto :Single)
if %userinr%==2 (set WIMFILE=install.esd&goto :ISO)
if %userinr%==1 (set WIMFILE=install.wim&goto :ISO)
GOTO :MAINMENU

:uup_fold
set userinp=
set "b=0"
set "c=0"
set "d=0"
for %%A in ("%fold%") do set fold=%%~fA
set "UUP=%fold%"
call :uup_esd %fold%
dir /b /a:d /o:d /t:c "%fold%">>temp\uups_fol.txt 2>nul
for /f "tokens=3 delims=: " %%i in ('find /v /n /c "" temp\uups_fol.txt') do set uups_fol_num=%%i
cls
if %uups_fol_num% neq 0 (
set /a c+=%uups_fol_num%
echo.
echo ===============================================================================
echo %txt22% %fold%
echo ===============================================================================
echo.
for /f "tokens=* delims=" %%a in ('dir /b /a:d /o:d /t:c "%fold%"') do (
	if /i amd64==%%a set /a d+=1
	if /i x86==%%a set /a d+=1
	set /a b+=1
	echo   f!b!. %%a
))
if %uups_esd_num% neq 0 (
set /a c+=%uups_esd_num%
echo.
echo ===============================================================================
echo %txt23% %fold%
echo ===============================================================================
echo.
for /L %%i in (1, 1, %uups_esd_num%) do (
call :uups_esd %%i
echo   e%%i. !name%%i!
))
if /i %c%==0 (
echo.
echo ===============================================================================
echo %txt24% %fold%
echo ===============================================================================
)
echo.
echo ===============================================================================
echo %txt25%
echo %txt26%
if %d%==2 (echo %txt27%)
echo ===============================================================================
set /p userinp= ^> %txt10%: 
set userinp=%userinp:~0,6%
if %uups_fol_num% neq 0 (
set "f=0"
for /f "tokens=* delims=" %%a in ('dir /b /a:d /o:d /t:c "%fold%"') do (
set /a f+=1
if /i %userinp%==f!f! set "fold=%fold%\%%a"&goto :uup_fold
))
if %d%==2 (if /i %userinp%==d goto :dCheck)
if %uups_esd_num% neq 0 (
for /L %%i in (1, 1, %uups_esd_num%) do (
if /i %userinp%==e%%i (
call :uups_esd %%i
set "MetadataESD=!UUP!\!uups_esd%%i!"&set "arch=!arch%%i!"&set "editionid=!edition%%i!"&set "langid=!langid%%i!"&set "nameos=!name%%i!"
goto :MAINMENU
))
if /i %userinp%==alliso set "uupa=1"&set "uupb=iso"&set WIMFILE=install.wim&goto :ALL
if /i %userinp%==allisz set "uupa=1"&set "uupb=iso"&set WIMFILE=install.esd&goto :ALL
if /i %userinp%==aiowim set "uupa=2"&set WIMFILE=install.wim&goto :AIO
if /i %userinp%==aioesd set "uupa=2"&set WIMFILE=install.esd&goto :AIO
if /i %userinp%==allwim set "uupa=1"&set "uupb=install"&set WIMFILE=install.wim&goto :ALL
if /i %userinp%==allesd set "uupa=1"&set "uupb=install"&set WIMFILE=install.esd&goto :ALL
)
if /i %userinp%==b set "fold=%fold%\.."&goto :uup_fold
if /i %userinp%==q goto :QUIT
if %userinp%==0 goto :prompt
GOTO :uup_fold

:uup_esd
if exist "temp\*.txt" del /f /q "temp\*.txt" >nul 2>&1
for /d %%A in (Starter,StarterN,Cloud,CloudN,CoreCountrySpecific,CoreSingleLanguage,Core,CoreN,ProfessionalCountrySpecific,ProfessionalSingleLanguage,Professional,ProfessionalN,ProfessionalEducation,ProfessionalWorkstation,Education,EducationN,Enterprise,EnterpriseN,EnterpriseEval,EnterpriseNEval,EnterpriseS,EnterpriseSN,EnterpriseSEval,EnterpriseSNEval,EnterpriseG,EnterpriseGN,PPIPro) do (
dir /b %1\%%A_*.esd>>temp\uups_esd.txt 2>nul
)
for /f "tokens=3 delims=: " %%i in ('find /v /n /c "" temp\uups_esd.txt') do set uups_esd_num=%%i
exit /b

:ALL
for /L %%i in (1, 1, %uups_esd_num%) do (
set "MetadataESD=%UUP%\!uups_esd%%i!"&set "arch=!arch%%i!"&set "editionid=!edition%%i!"&set "langid=!langid%%i!"&set "numin=%%i"
if /i %uupb%==iso call :ISO
if /i %uupb%==install call :Single
)
if /i %uupb%==install ("%wimlib%" optimize %WIMFILE%)
rmdir /s /q ISOFOLDER\ 1>nul 2>nul
rmdir /s /q bin\temp\ 1>nul 2>nul
rmdir /s /q temp\ 1>nul 2>nul
echo.
echo %exitd%
pause >nul
GOTO :QUIT

:AIO
set "MetadataESD=%UUP%\%uups_esd1%"&set "arch=%arch1%"&set "editionid=%edition1%"&set "langid=%langid1%"

:ISO
if %dual%==0 (
cls
set "ISOFOLDER=ISOFOLDER"
call :PREPARE
)
if %dual%==1 (
echo.
echo ===============================================================================
echo %txt28% ^(%arch%^)
echo ===============================================================================
)
call :convert
echo.
echo ===============================================================================
echo %txt12% Setup Media Layout . . .
echo ===============================================================================
IF EXIST %ISOFOLDER% rmdir /s /q %ISOFOLDER%\
mkdir %ISOFOLDER%
echo.
"%wimlib%" apply "%MetadataESD%" 1 %ISOFOLDER%\ >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt14%&PAUSE&GOTO :QUIT)
del %ISOFOLDER%\MediaMeta.xml >nul 2>&1
echo %done%
echo.
echo ===============================================================================
echo %txt12% boot.wim . . .
echo ===============================================================================
%dism% /export-image /SourceImageFile:%MetadataESD% /SourceIndex:2 /DestinationImageFile:%~dp0%ISOFOLDER%\sources\boot.wim /compress:max /bootable
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo Errors were reported during export.&echo.&echo Press any key to exit.&pause >nul&GOTO :QUIT)
copy /y %ISOFOLDER%\sources\boot.wim temp\winre.wim >nul
"%wimlib%" info %ISOFOLDER%\sources\boot.wim 1 --image-property FLAGS=9 1>nul 2>nul
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
if %winbuild% GEQ 7601 (call :Boot) else (copy /y .\bin\reagent.xml .\%ISOFOLDER%\sources >nul 2>&1)
echo.
echo ===============================================================================
echo %txt12% %WIMFILE% . . .
echo ===============================================================================
echo.
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| find /i "Last Modification Time"') do (set mmm=%%G&set "isotime=%%H/%%L,%%I:%%J:%%K")
call :setdate %mmm%
if /i %uupa%==2 (for /L %%i in (1, 1, %uups_esd_num%) do (
set "MetadataESD=%UUP%\!uups_esd%%i!" && call :install %ISOFOLDER%^\sources^\
)) else call :install %ISOFOLDER%^\sources^\
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt15%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %txt13% %WIMFILE% . . .
echo ===============================================================================
echo.
if /i %uupa%==2 (
for /L %%i in (1, 1, %uups_esd_num%) do "%wimlib%" update %ISOFOLDER%\sources\%WIMFILE% %%i --command="add 'temp\winre.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
"%wimlib%" optimize %ISOFOLDER%\sources\%WIMFILE%
) else "%wimlib%" update %ISOFOLDER%\sources\%WIMFILE% 1 --command="add 'temp\winre.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
if %dual%==1 (
del /f /q "temp\*" >nul 2>&1
exit /b
)
echo.
echo ===============================================================================
echo %txt12% ISO . . .
echo ===============================================================================
bin\cdimage -bootdata:2#p0,e,b"ISOFOLDER\boot\etfsboot.com"#pEF,e,b"ISOFOLDER\efi\Microsoft\boot\efisys.bin" -o -m -u2 -udfver102 -t%isotime% -g -l%DVDLABEL% ISOFOLDER %DVDISO%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (
echo.
echo %txt16%
echo.
echo %exitd%
pause >nul
exit
)
if /i %uupa%==1 goto :eof
rmdir /s /q ISOFOLDER\ 1>nul 2>nul
rmdir /s /q bin\temp\ 1>nul 2>nul
rmdir /s /q temp\ 1>nul 2>nul
echo.
echo %exitd%
pause >nul
GOTO :QUIT

:Single
cls
if /i %uupa%==0 (
IF EXIST "%CD%\%WIMFILE%" (
echo.
echo ===============================================================================
echo %txt18%
echo ===============================================================================
echo.
echo %exitd%
pause >nul
GOTO :QUIT
))
call :convert
echo.
echo ===============================================================================
echo %txt12% %WIMFILE% . . .
echo ===============================================================================
echo.
call :install
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt15%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %txt13% %WIMFILE% . . .
echo ===============================================================================
if not exist "temp\winre.wim" %dism% /export-image /SourceImageFile:%MetadataESD% /SourceIndex:2 /DestinationImageFile:%~dp0temp\winre.wim /compress:max /bootable
if /i %uupa%==1 (
"%wimlib%" update %WIMFILE% %numin% --command="add 'temp\winre.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
) else "%wimlib%" update %WIMFILE% 1 --command="add 'temp\winre.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
echo.
echo %done%
echo.
if /i %uupa%==1 goto :eof
echo %exitd%
pause >nul
GOTO :QUIT

:INFO
CALL :PREPARE
cls
echo ===============================================================================
echo                     %txt06%
echo ===============================================================================
echo.
echo        OS: %_os%
echo      Arch: %arch%
echo  Language: %langid%
echo   Version: %_ver1%.%_ver2%.%build%.%svcbuild%
echo    Branch: %branch%
echo.
echo %exitc% . . .
pause >nul
GOTO :MAINMENU

:PREPARE
"%wimlib%" info "%MetadataESD%" 3 | find /i "Display Name" 1>nul && (
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| find /i "Display Name"') do set "_os=%%j"
) || (
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| findstr /b "Name"') do set "_os=%%j"
)
for /f "tokens=4 delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| find /i "Service Pack Build"') do set svcbuild=%%i
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| findstr /b "Build"') do set build=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| find /i "Major"') do set _ver1=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex info "%MetadataESD%" 3 ^| find /i "Minor"') do set _ver2=%%i
"%wimlib%" extract "%MetadataESD%" 1 sources\ei.cfg --dest-dir=.\temp --no-acls >nul 2>&1
type .\temp\ei.cfg 2>nul | find /i "Volume" 1>nul && set VOL=1
"%wimlib%" extract "%MetadataESD%" 1 sources\SetupPlatform.dll --dest-dir=.\temp --no-acls >nul 2>&1
bin\7z.exe l .\temp\SetupPlatform.dll >.\temp\version.txt 2>&1
for /f "tokens=4,5 delims=. " %%i in ('"findstr /B "FileVersion" .\temp\version.txt" 2^>nul') do set version=%%i.%%j
for /f "tokens=7 delims=.) " %%i in ('"findstr /B "FileVersion" .\temp\version.txt" 2^>nul') do set datetime=%%i
for /f "tokens=6 delims=.( " %%i in ('"findstr /B "FileVersion" .\temp\version.txt" 2^>nul') do set branch=%%i
if /i %arch%==x86 (set _ss=x86) else (set _ss=amd64)
if /i %arch%==arm64 (set _ss=arm64)
"%wimlib%" extract "%MetadataESD%" 3 Windows\WinSxS\Manifests\%_ss%_microsoft-windows-coreos-revision* --dest-dir=.\temp --no-acls >nul 2>&1
for /f "tokens=6,7 delims=_." %%i in ('dir /b .\temp\*.manifest') do set revision=%%i.%%j
if not %version%==%revision% (
set version=%revision%
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info "%MetadataESD%" 3 ^| find /i "Last Modification Time"') do (set mmm=%%G&set yyy=%%L&set ddd=%%H-%%I%%J)
call :setmmm !mmm!
)
call bin\revision.cmd
set _label2=
if /i %branch%==WinBuild (
"%wimlib%" extract "%MetadataESD%" 3 \Windows\System32\config\SOFTWARE --dest-dir=.\temp --no-acls >nul
reg load HKLM\TEMP .\temp\SOFTWARE >nul
for /f "skip=2 tokens=3,4,5,6,7 delims=. " %%i in ('"reg query "HKLM\TEMP\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx" 2^>nul') do if not errorlevel 1 set _label2=%%i.%%j.%%m.%%l_CLIENT
for /f "skip=2 tokens=3 delims= " %%i in ('reg query "HKLM\TEMP\Microsoft\Windows NT\CurrentVersion" /v BuildBranch') do set branch=%%i
reg unload HKLM\TEMP >nul
)
if defined _label2 (set _label=%_label2%) else (set _label=%version%.%datetime%.%branch%_CLIENT)
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set _label=!_label:%%b=%%b!

for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set langid=!langid:%%b=%%b!

if /i %arch%==x86 set archl=X86
if /i %arch%==x64 set archl=X64
if /i %arch%==arm64 set archl=ARM64

if /i %uupa%==2 set DVDLABEL=CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COMBINED_UUP_%archl%FRE_%langid%.ISO&exit /b

if /i %editionid%==Starter set DVDLABEL=J_CSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%STARTER_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==StarterN set DVDLABEL=J_CSNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%STARTERN_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==Cloud set DVDLABEL=J_CWCA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CLOUD_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==CloudN set DVDLABEL=J_CWCNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CLOUDN_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreCountrySpecific set DVDLABEL=J_CCHA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CHINA_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreSingleLanguage set DVDLABEL=J_CSLA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%SINGLELANGUAGE_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==Core set DVDLABEL=J_CCRA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CORE_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==CoreN set DVDLABEL=J_CCRNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COREN_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==ProfessionalSingleLanguage set DVDLABEL=J_CPRSLA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROSINGLELANGUAGE_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==ProfessionalCountrySpecific set DVDLABEL=J_CPRCHA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROCHINA_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==Professional (IF %VOL%==1 (set DVDLABEL=J_CPRA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALVL_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRO_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalN (IF %VOL%==1 (set DVDLABEL=J_CPRNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALNVL_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRON_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalEducation (IF %VOL%==1 (set DVDLABEL=J_CPREA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALEDUCATION_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPREA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROEDUCATION_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalEducationN (IF %VOL%==1 (set DVDLABEL=J_CPRENA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALEDUCATIONN_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRENA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROEDUCATIONN_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalWorkstation (IF %VOL%==1 (set DVDLABEL=J_CPRWA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALWORKSTATION_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRWA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROWORKSTATION_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==ProfessionalWorkstationN (IF %VOL%==1 (set DVDLABEL=J_CPRWNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%PROFESSIONALWORKSTATIONN_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CPRWNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PROWORKSTATIONN_OEMRET_%archl%FRE_%langid%.ISO))
if /i %editionid%==Education (IF %VOL%==1 (set DVDLABEL=J_CEDA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%EDUCATION_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CEDA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%EDUCATION_RET_%archl%FRE_%langid%.ISO))
if /i %editionid%==EducationN (IF %VOL%==1 (set DVDLABEL=J_CEDNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%EDUCATIONN_VOL_%archl%FRE_%langid%.ISO) else (set DVDLABEL=J_CEDNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%EDUCATIONN_RET_%archl%FRE_%langid%.ISO))
if /i %editionid%==Enterprise set DVDLABEL=J_CENA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISE_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseN set DVDLABEL=J_CENNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISEN_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseG set DVDLABEL=J_CEGA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISEG_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseGN set DVDLABEL=J_CEGNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISEGN_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseEval set DVDLABEL=J_CEEA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISEEVAL_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseNEval set DVDLABEL=J_CEENA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISENEVAL_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseS set DVDLABEL=J_CESA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISES_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSN set DVDLABEL=J_CESNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESN_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSubscription set DVDLABEL=J_CESA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESUBSCRIPTION_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSubscriptionN set DVDLABEL=J_CESNA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESUBSCRIPTIONN_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSEval set DVDLABEL=J_CESEA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESEVAL_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==EnterpriseSNEval set DVDLABEL=J_CESNEA_%archl%FREV_%langid%_DV5&set DVDISO=%_label%ENTERPRISESNEVAL_VOL_%archl%FRE_%langid%.ISO
if /i %editionid%==PPIPro set DVDLABEL=J_CPPIA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PPIPRO_OEM_%archl%FRE_%langid%.ISO
if defined branch exit /b

:Boot
"%wimlib%" info %ISOFOLDER%\sources\boot.wim 1 "Microsoft Windows PE (%arch%)" "Microsoft Windows PE (%arch%)" 1>nul 2>nul
"%wimlib%" update %ISOFOLDER%\sources\boot.wim 1 --command="delete '\Windows\system32\winpeshl.ini'" 1>nul 2>nul
md .\temp\mount
%dism% /Quiet /Mount-Wim /Wimfile:%ISOFOLDER%\sources\boot.wim /Index:1 /MountDir:"%~dp0temp\mount"
%dism% /Quiet /Image:"%~dp0temp\mount" /Set-TargetPath:X:\$windows.~bt\
%dism% /Quiet /Unmount-Wim /MountDir:"%~dp0temp\mount" /Commit
rmdir /s /q .\temp\mount
"%wimlib%" extract %ISOFOLDER%\sources\install.wim 1 Windows\system32\xmllite.dll --dest-dir=%ISOFOLDER%\sources --no-acls >nul 2>&1
echo delete '^\Windows^\system32^\winpeshl.ini'>%bootedit%
echo add '%ISOFOLDER%^\setup.exe' '^\setup.exe'>>%bootedit%
echo add '%ISOFOLDER%^\sources^\inf^\setup.cfg' '^\sources^\inf^\setup.cfg'>>%bootedit%
echo add '%ISOFOLDER%^\sources^\background_cli.bmp' '^\sources^\background.bmp'>>%bootedit%
for %%A in (
alert.gif
api-ms-win-core-apiquery-l1-1-0.dll
api-ms-win-downlevel-advapi32-l1-1-0.dll
api-ms-win-downlevel-advapi32-l1-1-1.dll
api-ms-win-downlevel-advapi32-l2-1-0.dll
api-ms-win-downlevel-advapi32-l2-1-1.dll
api-ms-win-downlevel-advapi32-l3-1-0.dll
api-ms-win-downlevel-advapi32-l4-1-0.dll
api-ms-win-downlevel-kernel32-l1-1-0.dll
api-ms-win-downlevel-kernel32-l2-1-0.dll
api-ms-win-downlevel-ole32-l1-1-0.dll
api-ms-win-downlevel-ole32-l1-1-1.dll
api-ms-win-downlevel-shlwapi-l1-1-0.dll
api-ms-win-downlevel-shlwapi-l1-1-1.dll
api-ms-win-downlevel-user32-l1-1-0.dll
api-ms-win-downlevel-user32-l1-1-1.dll
api-ms-win-downlevel-version-l1-1-0.dll
appcompat.xsl
appcompat_bidi.xsl
appcompat_detailed_bidi_txt.xsl
appcompat_detailed_txt.xsl
appraiser.dll
ARUNIMG.dll
arunres.dll
autorun.dll
cmisetup.dll
compatctrl.dll
compatprovider.dll
cryptosetup.dll
diager.dll
diagnostic.dll
diagtrack.dll
diagtrackrunner.exe
dism.exe
dismapi.dll
dismcore.dll
dismcoreps.dll
dismprov.dll
ext-ms-win-advapi32-encryptedfile-l1-1-0.dll
folderprovider.dll
hwcompat.dll
hwcompat.txt
hwexclude.txt
idwbinfo.txt
imagingprovider.dll
input.dll
lang.ini
locale.nls
logprovider.dll
MediaSetupUIMgr.dll
ndiscompl.dll
nlsbres.dll
ntdsupg.dll
offline.xml
pnpibs.dll
reagent.admx
reagent.dll
reagent.xml
rollback.exe
schema.dat
segoeui.ttf
setup.exe
setupcompat.dll
SetupCore.dll
SetupHost.exe
SetupMgr.dll
SetupPlatform.cfg
SetupPlatform.dll
SetupPlatform.exe
SetupPrep.exe
SmiEngine.dll
spflvrnt.dll
spprgrss.dll
spwizeng.dll
spwizimg.dll
spwizres.dll
sqmapi.dll
testplugin.dll
unattend.dll
unbcl.dll
upgloader.dll
upgrade_frmwrk.xml
uxlib.dll
uxlibres.dll
vhdprovider.dll
w32uiimg.dll
w32uires.dll
warning.gif
wdsclient.dll
wdsclientapi.dll
wdscore.dll
wdscsl.dll
wdsimage.dll
wdstptc.dll
wdsutil.dll
wimprovider.dll
win32ui.dll
WinDlp.dll
winsetup.dll
wpx.dll
xmllite.dll
) do (
if exist "%ISOFOLDER%\sources\%%A" echo add '%ISOFOLDER%^\sources^\%%A' '^\sources^\%%A'>>%bootedit%
)
for %%A in (
appraiser.dll.mui
arunres.dll.mui
cmisetup.dll.mui
compatctrl.dll.mui
compatprovider.dll.mui
dism.exe.mui
dismapi.dll.mui
dismcore.dll.mui
dismprov.dll.mui
folderprovider.dll.mui
imagingprovider.dll.mui
input.dll.mui
logprovider.dll.mui
MediaSetupUIMgr.dll.mui
nlsbres.dll.mui
pnpibs.dll.mui
reagent.adml
reagent.dll.mui
rollback.exe.mui
setup.exe.mui
setup_help_upgrade_or_custom.rtf
setupcompat.dll.mui
SetupCore.dll.mui
setupplatform.exe.mui
SetupPrep.exe.mui
smiengine.dll.mui
spwizres.dll.mui
upgloader.dll.mui
uxlibres.dll.mui
vhdprovider.dll.mui
vofflps.rtf
w32uires.dll.mui
wdsclient.dll.mui
wdsimage.dll.mui
wimprovider.dll.mui
WinDlp.dll.mui
winsetup.dll.mui
) do (
if exist "%ISOFOLDER%\sources\%langid%\%%A" echo add '%ISOFOLDER%^\sources^\%langid%^\%%A' '^\sources^\%langid%^\%%A'>>%bootedit%
)
"%wimlib%" export "%MetadataESD%" 2 %ISOFOLDER%\sources\boot.wim "Microsoft Windows Setup (%arch%)" "Microsoft Windows Setup (%arch%)" --boot
"%wimlib%" update %ISOFOLDER%\sources\boot.wim 2 < %bootedit% 1>nul 2>nul
"%wimlib%" info %ISOFOLDER%\sources\boot.wim 2 --image-property FLAGS=2 1>nul 2>nul
"%wimlib%" optimize %ISOFOLDER%\sources\boot.wim
del %bootedit% >nul 2>&1
del %ISOFOLDER%\sources\xmllite.dll >nul 2>&1
goto :eof

:convert
if exist "%UUP%\*.cab" (
echo.
echo ===============================================================================
echo %txt11% . . .
echo ===============================================================================
echo.
if exist "%UUP%\*.xml.cab" if exist "%UUP%\Metadata\*" move /y "%UUP%\*.xml.cab" "%UUP%\Metadata\" 1>nul 2>nul
for /f "delims=" %%i in ('dir /b "%UUP%\*.cab"') do call :uups_cab %%i
for /f "delims=" %%i in ('dir /AD /b "%UUP%\"') do call :uups_fol %%i
if exist "%UUP%\Metadata\*.xml.cab" copy /y "%UUP%\Metadata\*.xml.cab" "%UUP%\" 1>nul 2>nul
)
goto :eof

:install
if /i %WIMFILE%==install.wim (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 %1%WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd" --compress=maximum
) else (
"%wimlib%" export "%MetadataESD%" 3 %1%WIMFILE% --ref="%UUP%\*.esd" --compress=maximum
))
if /i %WIMFILE%==install.esd (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 %1%WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd"
) else (
"%wimlib%" export "%MetadataESD%" 3 %1%WIMFILE% --ref="%UUP%\*.esd"
))
goto :eof

:uups_cab
set pack=%~n1
if exist "%CD%\temp\%pack%.ESD" goto :eof
md temp\%pack%
echo CAB ^> DIR ^> ESD ^(%pack%.cab^)
expand.exe "%UUP%\%pack%.cab" -f:* temp\%pack%\ >nul
"%wimlib%" capture "temp\%pack%" "temp\%pack%.ESD" --compress=LZX:15 --check --no-acls --norpfix "%pack%" "%pack%" >nul
rd /s /q temp\%pack%
)
goto :eof

:uups_fol
set pack=%1
if /i [%1]==[Metadata] goto :eof
if exist "%CD%\temp\%pack%.ESD" goto :eof
echo DIR ^> ESD ^(%pack%^)
"%wimlib%" capture "%UUP%\%pack%" "temp\%pack%.ESD" --compress=LZX:15 --check --no-acls --norpfix "%pack%" "%pack%" >nul
)
goto :eof

:uups_esd
for /f "usebackq  delims=" %%b in (`find /n /v "" temp\uups_esd.txt ^| find "[%1]"`) do set uups_esd=%%b
if %1 GEQ 1 set uups_esd=%uups_esd:~3%
if %1 GEQ 10 set uups_esd=%uups_esd:~1%
if %1 GEQ 100 set uups_esd=%uups_esd:~1%
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| findstr /b "Edition"') do set "edition%1=%%i"
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| find /i "Default"') do set "langid%1=%%i"
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| find /i "Architecture"') do set "arch%1=%%i"
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| findstr /b "Build"') do set build%1=%%i
for /f "tokens=4 delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| find /i "Service Pack Build"') do set svcbuild%1=%%i
if /i !arch%1!==x86_64 set "arch%1=x64"
if /i !arch%1!==ARM64 set "arch%1=arm64"
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex info "%UUP%\%uups_esd%" 3 ^| findstr /b "Name"') do set "name=%%j"
set "name%1=!name! - !build%1!.!svcbuild%1! / !arch%1! / !langid%1!"
set "uups_esd%1=%uups_esd%"
goto :eof

:setdate
if /i %1==Jan set "isotime=01/%isotime%"
if /i %1==Feb set "isotime=02/%isotime%"
if /i %1==Mar set "isotime=03/%isotime%"
if /i %1==Apr set "isotime=04/%isotime%"
if /i %1==May set "isotime=05/%isotime%"
if /i %1==Jun set "isotime=06/%isotime%"
if /i %1==Jul set "isotime=07/%isotime%"
if /i %1==Aug set "isotime=08/%isotime%"
if /i %1==Sep set "isotime=09/%isotime%"
if /i %1==Oct set "isotime=10/%isotime%"
if /i %1==Nov set "isotime=11/%isotime%"
if /i %1==Dec set "isotime=12/%isotime%"
exit /b

:setmmm
if /i %1==Jan set "datetime=%yyy:~2%01%ddd%"
if /i %1==Feb set "datetime=%yyy:~2%02%ddd%"
if /i %1==Mar set "datetime=%yyy:~2%03%ddd%"
if /i %1==Apr set "datetime=%yyy:~2%04%ddd%"
if /i %1==May set "datetime=%yyy:~2%05%ddd%"
if /i %1==Jun set "datetime=%yyy:~2%06%ddd%"
if /i %1==Jul set "datetime=%yyy:~2%07%ddd%"
if /i %1==Aug set "datetime=%yyy:~2%08%ddd%"
if /i %1==Sep set "datetime=%yyy:~2%09%ddd%"
if /i %1==Oct set "datetime=%yyy:~2%10%ddd%"
if /i %1==Nov set "datetime=%yyy:~2%11%ddd%"
if /i %1==Dec set "datetime=%yyy:~2%12%ddd%"
exit /b

:dlang
if /i %dlang%==ru-RU call bin\uups-lang.cmd -ru && exit /b
call bin\uups-lang.cmd -en
exit /b

:dCheck
set combine=0
call :uup_esd %fold%\amd64
set _amd64=%uups_esd_num%
call :uup_esd %fold%\x86
set _x86=%uups_esd_num%
if /i %_amd64% neq 0 (if /i %_x86% neq 0 (goto :DUALMENU))
cls
color 4f
echo 
echo Мы обнаружели одну не точность в создании Dual.
echo Нажмите любуж кнопку, чтобы вернуть к выборе папок.
echo 
pause>nul
goto :uup_fold

:DUALMENU
set userint=
cls
echo.
echo ===============================================================================
echo   %youcreatdu%
echo ===============================================================================
echo.
echo  %menudu1%
echo  %menudu2%
echo  %menudu3%
echo.
echo  %menudu4%
echo.
echo ===============================================================================
echo.
set /p userint= ^> %denter% 
set userint=%userint:~0,1%
if %userint%==4 goto :uup_fold
if %userint%==3 (set WIMFILE=install.wim&set combine=1&goto :dGo)
if %userint%==2 (set WIMFILE=install.wim&goto :dGo)
if %userint%==1 (set WIMFILE=install.esd&goto :dGo)
GOTO :DUALMENU

:dGo
cls
call :dPREPARE 1 amd64 x64
call :dPREPARE 2 x86 x86

IF NOT EXIST bin\temp\ mkdir bin\temp
bin\7z.exe l .\ISOFOLDER\x64\sources\SetupPlatform.dll >.\bin\temp\version.txt 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo.
echo ===============================================================================
echo %errsetup%
echo ===============================================================================
echo.
echo %presskey%
pause >nul
exit
)
for /f "tokens=4,5 delims=. " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set version=%%i.%%j
for /f "tokens=7 delims=.) " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set datetime=%%i
for /f "tokens=6 delims=.( " %%i in ('"findstr /B "FileVersion" .\bin\temp\version.txt" 2^>nul') do set branch=%%i
"%wimlib%" extract "ISOFOLDER\x64\sources\%WIMFILE%" 1 Windows\WinSxS\Manifests\*_microsoft-windows-coreos-revision* --dest-dir=.\bin\temp --no-acls >nul 2>&1
for /f "tokens=6,7 delims=_." %%i in ('dir /b bin\temp\*.manifest') do set revision=%%i.%%j
if %version% neq %revision% (
set version=%revision%
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info "ISOFOLDER\x64\sources\%WIMFILE%" 1 ^| find /i "Last Modification Time"') do (set mmm=%%G&set yyy=%%L&set ddd=%%H-%%I%%J)
call :setmmm !mmm!
)
call bin\revision.cmd
set _label2=
if /i %branch%==WinBuild (
"%wimlib%" extract "ISOFOLDER\x64\sources\%WIMFILE%" 1 \Windows\System32\config\SOFTWARE --dest-dir=.\bin\temp --no-acls >nul
reg load HKLM\TEMP .\bin\temp\SOFTWARE >nul
for /f "skip=2 tokens=3,4,5,6,7 delims=. " %%i in ('"reg query "HKLM\TEMP\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx" 2^>nul') do if not errorlevel 1 set _label2=%%i.%%j.%%m.%%l_CLIENT
for /f "skip=2 tokens=3 delims= " %%i in ('reg query "HKLM\TEMP\Microsoft\Windows NT\CurrentVersion" /v BuildBranch') do set branch=%%i
reg unload HKLM\TEMP >nul
)
if defined _label2 (set _label=%_label2%) else (set _label=%version%.%datetime%.%branch%_CLIENT)
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set _label=!_label:%%b=%%b!

if /i %UUPlang1%==%UUPlang2% (set langid=%UUPlang1%) else (set langid=%UUPlang1:~0,2%-%UUPlang2:~0,2%)
for %%b in (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do set langid=!langid:%%b=%%b!

set archl=X86-X64

if /i %DVDLABEL1% equ %DVDLABEL2% (
set DVDLABEL=%DVDLABEL1%_%archl%FRE_%langid%_DV9
set DVDISO=%_label%%DVDISO1%_%archl%FRE_%langid%.ISO
) else (
set DVDLABEL=CCSA_%archl%FRE_%langid%_DV9
set DVDISO=%_label%%DVDISO1%_%UUParch1%FRE-%DVDISO2%_%UUParch2%FRE_%langid%.ISO

)

if %combine%==0 goto :BCD
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim ^| findstr /c:"Image Count"') do set imagesi=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim ^| findstr /c:"Image Count"') do set imagesx=%%i
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim 1 ^| findstr /b "Name"') do set "_osi=%%j x86"
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim 1 ^| findstr /b "Name"') do set "_osx=%%j x64"
IF NOT %imagesi%==1 FOR /L %%g IN (2,1,%imagesi%) DO (
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x86\sources\install.wim %%g ^| findstr /b "Name"') do set "_osi%%g=%%j x86"
)
IF NOT %imagesx%==1 FOR /L %%g IN (2,1,%imagesx%) DO (
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info ISOFOLDER\x64\sources\install.wim %%g ^| findstr /b "Name"') do set "_osx%%g=%%j x64"
)
echo.
echo ===============================================================================
echo %iunif% install.wim...
echo ===============================================================================
echo.
echo %ix86d%
"%wimlib%" info ISOFOLDER\x86\sources\install.wim 1 "%_osi%" "%_osi%"
IF NOT %imagesi%==1 FOR /L %%g IN (2,1,%imagesi%) DO (
"%wimlib%" info ISOFOLDER\x86\sources\install.wim %%g "!_osi%%g!" "!_osi%%g!"
)
echo.
echo %ix64d%
"%wimlib%" export ISOFOLDER\x64\sources\install.wim 1 ISOFOLDER\x86\sources\install.wim "%_osx%" "%_osx%"
IF NOT %imagesx%==1 FOR /L %%g IN (2,1,%imagesx%) DO (
"%wimlib%" export ISOFOLDER\x64\sources\install.wim %%g ISOFOLDER\x86\sources\install.wim "!_osx%%g!" "!_osi%%g!"
)
echo.
echo Replacing \x86\sources\install.wim -^> \x64\sources\install.wim
del ISOFOLDER\x64\sources\install.wim >nul 2>&1
copy /y ISOFOLDER\x86\sources\install.wim ISOFOLDER\x64\sources\install.wim

:BCD
echo.
echo ===============================================================================
echo %ibcd%...
echo ===============================================================================
echo.
xcopy ISOFOLDER\x64\boot\* ISOFOLDER\boot\ /cheriky >nul 2>&1
xcopy ISOFOLDER\x64\efi\* ISOFOLDER\efi\ /cheriky >nul 2>&1
xcopy bin\efi\* ISOFOLDER\efi\ /cheriky >nul 2>&1
for /d %%G in (bootmgr,setup.exe) do (copy /y ISOFOLDER\x64\%%G ISOFOLDER\%%G >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 {default} description "Windows 10 Setup (64-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set {default} bootmenupolicy Legacy >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 {default} description "Windows 10 Setup (32-bit)" >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\b32 /set {default} bootmenupolicy Legacy >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
echo.
rd /s /q .\bin\temp >nul 2>&1
echo ===============================================================================
echo %txt12% ISO...
echo ===============================================================================
bin\cdimage.exe -bootdata:2#p0,e,b"ISOFOLDER\boot\etfsboot.com"#pEF,e,b"ISOFOLDER\efi\Microsoft\boot\efisys.bin" -o -m -u2 -udfver102 -t%isotime% -g -l%DVDLABEL% ISOFOLDER %DVDISO%
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (
echo.
echo %txt16%
echo.
echo %exitd%
pause >nul
exit
)
rmdir /s /q ISOFOLDER\ 1>nul 2>nul
rmdir /s /q bin\temp\ 1>nul 2>nul
rmdir /s /q temp\ 1>nul 2>nul
echo.
echo %exitd%
pause >nul
GOTO :QUIT

:dPREPARE
set "UUP=%fold%\%2"
call :uup_esd %UUP%
for /L %%i in (1, 1, %uups_esd_num%) do (
call :uups_esd %%i
)
set "uupa=2"&set "ISOFOLDER=ISOFOLDER\%3"&set dual=1&call :AIO
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "ISOFOLDER\%3\sources\%WIMFILE%" ^| findstr /c:"Image Count"') do set UUPmulti%1=%%i
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex.exe info "ISOFOLDER\%3\sources\%WIMFILE%" 1 ^| find /i "Architecture"') do set "UUParch%1=%%i"
for /f "tokens=3 delims=<>" %%i in ('bin\imagex.exe /info "ISOFOLDER\%3\sources\%WIMFILE%" 1 ^| find /i "<DEFAULT>"') do set UUPlang%1=%%i
if /i !UUParch%1!==x86_64 (set "UUParch%1=X64") else (set "UUParch%1=X86")

IF !UUPmulti%1! GEQ 2 (
bin\wimlib-imagex.exe info "ISOFOLDER\%3\sources\%WIMFILE%" | findstr /b "Edition" | find "N" 1>nul && set UUPeditionn%1=1
bin\wimlib-imagex.exe info "ISOFOLDER\%3\sources\%WIMFILE%" | findstr /b "Edition" | find "o" 1>nul && set UUPeditiona%1=1
bin\wimlib-imagex.exe info "ISOFOLDER\%3\sources\%WIMFILE%" | findstr /b "Edition" | find "e" 1>nul && set UUPeditiona%1=1
if !UUPeditionn%1!==1 set DVDLABEL%1=CCSNA&set DVDISO%1=COMBINEDN_UUP_OEMRET
if !UUPeditiona%1!==1 set DVDLABEL%1=CCSA&set DVDISO%1=COMBINED_UUP_OEMRET
if !UUPeditiona%1!==1 (if !UUPeditionn%1!==1 (set DVDLABEL%1=CCSNA&set DVDISO%1=COMBINED_N_UUP_OEMRET))
exit /b
)

for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex info "ISOFOLDER\%3\sources\%WIMFILE%" 1 ^| findstr /b "Edition"') do set "UUPedition%1=%%i"
if /i !UUPedition%1!==Core set DVDLABEL%1=CCRA&set DVDISO%1=CORE_OEMRET
if /i !UUPedition%1!==CoreN set DVDLABEL%1=CCRNA&set DVDISO%1=COREN_OEMRET
if /i !UUPedition%1!==CoreSingleLanguage set DVDLABEL%1=CSLA&set DVDISO%1=SINGLELANGUAGE_OEM
if /i !UUPedition%1!==CoreCountrySpecific set DVDLABEL%1=CCHA&set DVDISO%1=CHINA_OEM
if /i !UUPedition%1!==Professional (IF !ESDvol%1!==1 (set DVDLABEL%1=CPRA&set DVDISO%1=PROFESSIONALVL_VOL) else (set DVDLABEL%1=CPRA&set DVDISO%1=PRO_OEMRET))
if /i !UUPedition%1!==ProfessionalN (IF !ESDvol%1!==1 (set DVDLABEL%1=CPRNA&set DVDISO%1=PROFESSIONALNVL_VOL) else (set DVDLABEL%1=CPRNA&set DVDISO%1=PRON_OEMRET))
if /i !UUPedition%1!==Education (IF !ESDvol%1!==1 (set DVDLABEL%1=CEDA&set DVDISO%1=EDUCATION_VOL) else (set DVDLABEL%1=CEDA&set DVDISO%1=EDUCATION_RET))
if /i !UUPedition%1!==EducationN (IF !ESDvol%1!==1 (set DVDLABEL%1=CEDNA&set DVDISO%1=EDUCATIONN_VOL) else (set DVDLABEL%1=CEDNA&set DVDISO%1=EDUCATIONN_RET))
if /i !UUPedition%1!==Enterprise set DVDLABEL%1=CENA&set DVDISO%1=ENTERPRISE_VOL
if /i !UUPedition%1!==EnterpriseN set DVDLABEL%1=CENNA&set DVDISO%1=ENTERPRISEN_VOL
if /i !UUPedition%1!==PPIPro set DVDLABEL%1=CPPIA&set DVDISO%1=PPIPRO_OEM
if /i !UUPedition%1!==Cloud set DVDLABEL%1=CWCA&set DVDISO%1=CLOUD_OEM
if /i !UUPedition%1!==CloudN set DVDLABEL%1=CWCNA&set DVDISO%1=CLOUDN_OEM
if /i !UUPedition%1!==EnterpriseG set DVDLABEL%1=CEGA&set DVDISO%1=ENTERPRISEG_VOL
if /i !UUPedition%1!==EnterpriseGN set DVDLABEL%1=CEGNA&set DVDISO%1=ENTERPRISEGN_VOL
if /i !UUPedition%1!==EnterpriseS set DVDLABEL%1=CES&set DVDISO%1=ENTERPRISES_VOL
if /i !UUPedition%1!==EnterpriseSN set DVDLABEL%1=CESNN&set DVDISO%1=ENTERPRISESN_VOL
if /i !UUPedition%1!==ProfessionalEducation (IF %VOL%==1 (set DVDLABEL%1=CPREA&set DVDISO%1=PROFESSIONALEDUCATION_VOL) else (set DVDLABEL%1=CPREA&set DVDISO%1=PROEDUCATION_OEMRET))
if /i !UUPedition%1!==ProfessionalEducationN (IF %VOL%==1 (set DVDLABEL%1=CPRENA&set DVDISO%1=PROFESSIONALEDUCATIONN_VOL) else (set DVDLABEL%1=CPRENA&set DVDISO%1=PROEDUCATIONN_OEMRET))
if /i !UUPedition%1!==ProfessionalWorkstation (IF %VOL%==1 (set DVDLABEL%1=CPRWA&set DVDISO%1=PROFESSIONALWORKSTATION_VOL) else (set DVDLABEL%1=CPRWA&set DVDISO%1=PROWORKSTATION_OEMRET))
if /i !UUPedition%1!==ProfessionalWorkstationN (IF %VOL%==1 (set DVDLABEL%1=CPRWNA&set DVDISO%1=PROFESSIONALWORKSTATIONN_VOL) else (set DVDLABEL%1=CPRWNA&set DVDISO%1=PROWORKSTATIONN_OEMRET))
if /i !UUPedition%1!==ProfessionalSingleLanguage set DVDLABEL%1=CPRSLA&set DVDISO%1=PROSINGLELANGUAGE_OEM
if /i !UUPedition%1!==ProfessionalCountrySpecific set DVDLABEL%1=CPRCHA&set DVDISO%1=PROCHINA_OEM
exit /b

:QUIT
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
IF EXIST bin\temp\ rmdir /s /q bin\temp\
IF EXIST temp\ rmdir /s /q temp\
exit