@echo off

rem script:     abbodi1406, adguard
rem esddecrypt: qad, @tfwboredom
rem wimlib:     synchronicity
rem cryptokey:  MrMagic, Chris123NT, mohitbajaj143, Superwzt, timster

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=v171005"
title ESD ^> 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") ELSE (SET "wimlib=%~dp0bin\wimlib-imagex.exe")
cd /d "%~dp0"
setlocal EnableDelayedExpansion
color 1f
SET Backup=OFF
set savess=0
SET ENCRYPTEDESD=
SET ERRORTEMP=
SET ENCRYPTED=0
SET MULTI=0
SET PREPARED=0
set VOL=0
SET "ramdiskoptions={7619dcc8-fafe-11d9-b411-000476eba25f}"
set newkeys=0
for /f "tokens=3 delims=: " %%b in ('dism /english /online /Get-Intl ^| find /i "System locale"') do set dlang=%%b && call :dlang

if not [%1]==[] (set "ENCRYPTEDESD=%~1"&set "ENCRYPTEDESDN=%~nx1"&goto :check)
set _esd=0
if exist "*.esd" (for /f "delims=" %%i in ('dir /b "*.esd"') do (call set /a _esd+=1))
if !_esd! equ 2 goto :dCheck
if !_esd! equ 0 goto :prompt1
if !_esd! gtr 1 goto :prompt2
for /f "delims=" %%i in ('dir /b "*.esd"') do (set "ENCRYPTEDESD=%%i"&set "ENCRYPTEDESDN=%%i"&goto :check)
 =
:prompt1
cls
echo.
echo ===============================================================================
echo %prompt1%
echo ===============================================================================
echo.
set /p ENCRYPTEDESD=
if [%ENCRYPTEDESD%]==[] goto :QUIT
call :setvar "%ENCRYPTEDESD%"
goto :check

:setvar
SET ENCRYPTEDESDN=%~nx1
goto :eof

:prompt2
cls
echo.
echo ===============================================================================
echo %prompt2%
echo ===============================================================================
echo.
set /p ENCRYPTEDESD=
if [%ENCRYPTEDESD%]==[] goto :QUIT
SET ENCRYPTEDESDN=%ENCRYPTEDESD%
goto :check

:check
SET ENCRYPTED=0
if /i %ENCRYPTEDESDN%==install.esd (ren %ENCRYPTEDESD% %ENCRYPTEDESDN%.orig&set ENCRYPTEDESD=%ENCRYPTEDESD%.orig)
CALL :MULTI
IF NOT %MULTI%==0 GOTO :MAINMENU
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 1>nul 2>nul
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1&GOTO :MAINMENU
IF %ERRORLEVEL% EQU 18 (
cls
echo.
echo ===============================================================================
echo %check%
echo ===============================================================================
echo.
echo %presskey%
pause >nul
goto :eof
)
IF %ERRORLEVEL% NEQ 0 (
cls
echo.
echo ===============================================================================
echo %check2%
echo ===============================================================================
echo.
echo %presskey%
pause >nul
goto :eof
)

:MAINMENU
attrib -r -s -a -h "%ENCRYPTEDESD%"
if /i %Backup%==OFF (set Backup2=ON) else (set Backup2=OFF)
cls
set userinp=
echo ===============================================================================
echo %menust1%
echo %menust2%
echo %menust3%
echo %menust4%
IF %ENCRYPTED%==1 (
echo %menust5%
echo %menust6%
echo %menust7%
echo ____________________________________________________________
echo %createsd1% %Backup%. %createsd2% %Backup2%
) else (
echo %menust51%
echo ____________________________________________________________
echo %cryptesd%
)
echo ===============================================================================
echo.
set /p userinp= ^> %choice% 
set userinp=%userinp:~0,1%
if %userinp%==0 GOTO :QUIT
if %userinp%==4 (set WIMFILE=install.esd&goto :Single)
if %userinp%==3 (set WIMFILE=install.wim&goto :Single)
if %userinp%==2 (set WIMFILE=install.esd&goto :ISO)
if %userinp%==1 (set WIMFILE=install.wim&goto :ISO)
if %ENCRYPTED%==1 (
if %userinp%==9 (if /i %Backup%==OFF (set Backup=ON) else (set Backup=OFF))&goto :MAINMENU
if %userinp%==7 (GOTO :update)
if %userinp%==6 (GOTO :keynew)
if %userinp%==5 (GOTO :DDECRYPT))
if %ENCRYPTED%==0 (
if %userinp%==5 (GOTO :INFO))
GOTO :MAINMENU

:keynew
cls
echo.
echo ===========================================================
echo %addkey%
echo ===========================================================
echo.
set /p keynew=
echo set "newkey=%keynew%">newkey.cmd
echo.
echo %done%
echo.
echo %presscont%
pause >nul
GOTO :MAINMENU

:update
cls
echo.
echo ===============================================================================
echo %updkey%
echo ===============================================================================
echo.
IF EXIST "%CD%\update_keys.cmd" (
call update_keys.cmd
GOTO :MAINMENU
)
echo %upderr%
echo.
echo %presskey%
pause >nul
GOTO :MAINMENU

:ISO
cls
IF %ENCRYPTED%==1 CALL :DECRYPT
IF %PREPARED%==0 CALL :PREPARE
echo.
echo ===============================================================================
echo %creat% Setup Media Layout...
echo ===============================================================================
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
mkdir ISOFOLDER
echo.
"%wimlib%" apply "%ENCRYPTEDESD%" 1 ISOFOLDER\ >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind1e%&PAUSE&GOTO :QUIT)
del ISOFOLDER\MediaMeta.xml >nul 2>&1
echo.
echo ===============================================================================
echo %creat% boot.wim...
echo ===============================================================================
echo.
"%wimlib%" export "%ENCRYPTEDESD%" 2 ISOFOLDER\sources\boot.wim --compress=maximum
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
echo.
"%wimlib%" export "%ENCRYPTEDESD%" 3 ISOFOLDER\sources\boot.wim --boot
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
"%wimlib%" extract ISOFOLDER\sources\boot.wim 2 sources\dism.exe --dest-dir=.\bin\temp --no-acls >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (
"%wimlib%" update ISOFOLDER\sources\boot.wim 2 <bin\wim-update.txt 1>nul 2>nul
)
rd /s /q .\bin\temp
echo.
echo ===============================================================================
echo %creat% %WIMFILE%...
echo ===============================================================================
echo.
IF %MULTI%==0 (set sourcetime=4) else (set sourcetime=%MULTI%)
for /f "tokens=5,6,7,8,9,10 delims=: " %%G in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" %sourcetime% ^| find /i "Last Modification Time"') do (set mmm=%%G&set "isotime=%%H/%%L,%%I:%%J:%%K")
call :setdate %mmm%
if /i %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\sources\%WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\sources\%WIMFILE% --compress=maximum
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
IF NOT %MULTI%==0 (
if %savess%==yes ("%wimlib%" extract "%ENCRYPTEDESD%" 4 windows\system32\recovery\winre.wim --dest-dir=.\bin\temp --no-acls >nul 2>&1
"%wimlib%" update ISOFOLDER\sources\%WIMFILE% 1 --command="delete '\Windows\WinSxS\ManifestCache\0570bdaf5aeb6357_blobs.bin'" >nul 2>&1)
set testind=%MULTI%
FOR /L %%j IN (5,1,%MULTI%) DO (call :testind %%j "ISOFOLDER\sources\%WIMFILE%")
rd /s /q .\bin\temp
echo.
"%wimlib%" optimize ISOFOLDER\sources\%WIMFILE%
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %creat% 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 %ind3e%
echo.
echo %presskey%
pause >nul
IF EXIST "%ENCRYPTEDESD%.bak" (
del /f /q "%ENCRYPTEDESD%" >nul 2>&1
ren "%ENCRYPTEDESD%.bak" %ENCRYPTEDESDN%
)
exit
)
rmdir /s /q ISOFOLDER\
echo.
echo %presskey%
pause >nul
GOTO :QUIT

:Single
cls
if %WIMFILE%==install.wim IF EXIST "%CD%\install.wim" (
echo.
echo ===============================================================================
echo %singlee%
echo ===============================================================================
echo.
echo %presskey%
pause >nul
GOTO :QUIT
)
IF %ENCRYPTED%==1 CALL :DECRYPT
CALL :MULTI
echo ===============================================================================
echo %creat% %WIMFILE% %filei%...
echo ===============================================================================
echo.
if /i %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 %WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 %WIMFILE% --compress=maximum
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
IF NOT %MULTI%==0 (
if %savess%==yes ("%wimlib%" extract "%ENCRYPTEDESD%" 4 windows\system32\recovery\winre.wim --dest-dir=.\bin\temp --no-acls >nul 2>&1
"%wimlib%" update %WIMFILE% 1 --command="delete '\Windows\WinSxS\ManifestCache\0570bdaf5aeb6357_blobs.bin'" >nul 2>&1)
FOR /L %%j IN (5,1,%MULTI%) DO (call :testind %%j "%WIMFILE%")
rd /s /q .\bin\temp
echo.
"%wimlib%" optimize %WIMFILE%
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
echo.
echo %done%
echo.
echo %presskey%
pause >nul
GOTO :QUIT

:testind
set /a testind=%1-3
echo.
"%wimlib%" export "%ENCRYPTEDESD%" %1 %2
if %savess%==yes ("%wimlib%" update %2 %testind% --command="add 'bin\temp\winre.wim' '\windows\system32\recovery\winre.wim'" >nul 2>&1
"%wimlib%" update %2 %testind% --command="delete '\Windows\WinSxS\ManifestCache\0570bdaf5aeb6357_blobs.bin'" >nul 2>&1)
exit /b

:INFO
IF %PREPARED%==0 CALL :PREPARE
cls
echo ===============================================================================
echo %infoesd%
echo ===============================================================================
echo.
IF %MULTI%==0 echo %ios%: %_os%
IF NOT %MULTI%==0 (
echo %ios% 1: %_os%
FOR /L %%j IN (5,1,%MULTI%) DO (
call set /a osnum=%%j-3
echo %ios% !osnum!: !_os%%j!
)
)
echo %iarch% %arch%
echo %ilanguage% %langid%
echo %iversion% %_ver%.%svcbuild%
if defined branch echo %ibranch% %branch%
echo.
echo %presscont%
pause >nul
GOTO :MAINMENU

:PREPARE
SET PREPARED=1
set editionids=0
set editionidc=0
set display=0
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" | find /i "CoreSingleLanguage" 1>nul && set editionids=1
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" | find /i "CoreCountrySpecific" 1>nul && set editionidc=1
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 | find /i "Display Name" 1>nul && set display=1
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| findstr /b "Build"') do set build=%%i
if %build% LEQ 9600 GOTO :E_W81
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Major"') do set _ver1=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Minor"') do set _ver2=%%i
set _ver=%_ver1%.%_ver2%.%build%
if %display%==1 (
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Display Name"') do set "_os=%%j"
) else (
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| findstr /b "Name"') do set "_os=%%j"
)
CALL :MULTI
IF NOT %MULTI%==0 FOR /L %%g IN (5,1,%MULTI%) DO (
if !display!==1 (
for /f "tokens=1* delims=: " %%i in ('bin\wimlib-imagex.exe info "!ENCRYPTEDESD!" %%g ^| findstr /b "Name"') do set "_os%%g=%%j"
) else (
for /f "tokens=2* delims=: " %%i in ('bin\wimlib-imagex.exe info "!ENCRYPTEDESD!" %%g ^| find /i "Display Name"') do set "_os%%g=%%j"
)
)
for /f "tokens=2 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Architecture"') do set arch=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Edition"') do set editionid=%%i
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Default"') do set langid=%%i
for /f "tokens=4 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 4 ^| find /i "Service Pack Build"') do set svcbuild=%%i
"%wimlib%" extract "%ENCRYPTEDESD%" 1 sources\ei.cfg --dest-dir=.\bin\temp --no-acls >nul 2>&1
type .\bin\temp\ei.cfg 2>nul | find /i "Volume" 1>nul && set VOL=1
"%wimlib%" extract "%ENCRYPTEDESD%" 3 sources\SetupPlatform.dll --dest-dir=.\bin\temp --no-acls >nul 2>&1
bin\7z.exe l .\bin\temp\SetupPlatform.dll >.\bin\temp\version.txt 2>&1
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
if /i %arch%==x86 (set _ss=x86) else (set _ss=amd64)
if /i %arch%==arm64 (set _ss=arm64)
"%wimlib%" extract "%ENCRYPTEDESD%" 4 Windows\WinSxS\Manifests\%_ss%_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 "%ENCRYPTEDESD%" 4 ^| find /i "Last Modification Time"') do (set mmm=%%G&set yyy=%%L&set ddd=%%H-%%I%%J)
call :setmmm !mmm!
)
if %revision%==10240.16487 (set version=10240.16393&set datetime=150909-1450&set branch=th1_refresh&set savess=no)
if %revision%==10586.104 (set version=10586.0&set datetime=160212-2000&set branch=th2_refresh&set savess=no)
if %revision%==10586.164 (set version=10586.0&set datetime=160426-1409&set branch=th2_refresh&set savess=no)
if %revision%==14393.447 (set version=14393.0&set datetime=161119-1705&set branch=rs1_refresh&set savess=no)
if %revision%==15063.413 (set version=15063.0&set datetime=170607-1447&set branch=rs2_release_svc_refresh&set savess=no)
if %revision%==15063.483 (set version=15063.0&set datetime=170710-1358&set branch=rs2_release_svc_refresh&set savess=no)
set _label2=
if /i %branch%==WinBuild (
"%wimlib%" extract "%ENCRYPTEDESD%" 4 \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!
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!
rd /s /q .\bin\temp

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

if %savess%==no (
call :savess
)

IF %MULTI%==5 (
if /i %editionid%==Professional set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRO-CORE_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==ProfessionalN set DVDLABEL=J_CCSNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%PRON-COREN_OEMRET_%archl%FRE_%langid%.ISO
if defined branch exit /b
)
IF %MULTI% GEQ 6 (
if /i %editionid%==Professional set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COMBINED_OEMRET_%archl%FRE_%langid%.ISO
if /i %editionid%==ProfessionalN set DVDLABEL=J_CCSNA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COMBINEDN_OEMRET_%archl%FRE_%langid%.ISO
if %editionids%==1 set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COMBINEDSL_OEMRET_%archl%FRE_%langid%.ISO
if %editionidc%==1 set DVDLABEL=J_CCCHA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%COMBINEDCHINA_OEMRET_%archl%FRE_%langid%.ISO
IF %MULTI% GEQ 7 (if %revision%==16299.15 (set DVDLABEL=J_CCCHA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CONSUMER_OEMRET_%archl%FRE_%langid%.ISO))
if defined branch 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_CCLA_%archl%FRE_%langid%_DV5&set DVDISO=%_label%CLOUD_OEM_%archl%FRE_%langid%.ISO
if /i %editionid%==CloudN set DVDLABEL=J_CCLNA_%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

:savess
set saves=0
echo.
echo ===============================================================================
echo %savesize%
echo ===============================================================================
echo.
set /p saves= ^> %choices% 
set saves=%saves:~0,1%
if /i %saves%==1 set "savess=yes"
exit /b

: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

:MULTI
bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" 1>nul 2>nul
IF %ERRORLEVEL% EQU 74 exit /b
for /f "tokens=3 delims=: " %%i in ('bin\wimlib-imagex.exe info "%ENCRYPTEDESD%" ^| findstr /c:"Image Count"') do set images=%%i
if %images%==4 exit /b
set MULTI=%images%
exit /b

:DDECRYPT
cls
echo.
CALL :DECRYPT
ren "%ENCRYPTEDESD%" Decrypted-%ENCRYPTEDESDN%
echo.
echo %presskey%
pause >nul
GOTO :QUIT

:DECRYPT
if /i %Backup%==ON (
echo.
echo ===============================================================================
echo %ibackup%
echo ===============================================================================
copy /y "%ENCRYPTEDESD%" "%ENCRYPTEDESD%.bak" >nul
)
echo.
echo ===============================================================================
echo %idecr%
echo ===============================================================================
echo.
for /f "tokens=3 delims=: " %%i in ('find /v /n /c "" bin\key.cmd') do set newkeys=%%i
call bin\key.cmd
IF NOT %newkeys%==0 FOR /L %%c IN (1,1,%newkeys%) DO (
bin\esddecrypt.exe "%ENCRYPTEDESD%" !newkey%%c! 2>nul&& (echo %done%&exit /b)
)
bin\esddecrypt.exe "%ENCRYPTEDESD%" >nul && (echo %done%&exit /b)
call newkey.cmd
bin\esddecrypt.exe "%ENCRYPTEDESD%" %newkey% >nul && (echo %done%&exit /b)
echo.
echo %idecre%
echo.
echo %presskey%
pause >nul
GOTO :QUIT

:E_W81
cls
echo.
echo ===============================================================================
echo   %iwin8%
echo ===============================================================================
echo.
echo %presskey%
pause >nul
goto :QUIT

:dCheck
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 combine=0
SET count=0
SET ESDmulti1=0
SET ESDmulti2=0
SET ESDenc1=0
SET ESDenc2=0
set ESDvol1=0
set ESDvol2=0
set ESDarch1=0
set ESDarch2=0
set ESDver1=0
set ESDver2=0
set ESDlang1=0
set ESDlang2=0
for /f "delims=" %%i in ('dir /b "*.esd"') do call :dCount %%i
CALL :dInfo 1
CALL :dInfo 2
if /i %ESDarch1% equ %ESDarch2% goto :prompt2
if /i %ESDver1% neq %ESDver2% goto :prompt2
if /i %ESDlang1% neq %ESDlang2% goto :prompt2
bin\wimlib-imagex.exe info "%ESDfile1%" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1
bin\wimlib-imagex.exe info "%ESDfile2%" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ENCRYPTED=1

:DUALMENU
attrib -r -s -a -h "%ESDfile1%"
attrib -r -s -a -h "%ESDfile2%"
if /i %Backup%==OFF (set Backup2=ON) else (set Backup2=OFF)
set userint=
cls
echo.
echo %finddu%
echo ____________________________________________________________________________
echo.
echo %youcreatdu%
echo.
echo %menudu1%
echo %menudu2%
echo %menudu3%
echo.
echo %menudu4%
IF %ENCRYPTED%==1 (
echo ____________________________________________________________________________
echo %createsd1% %Backup%. %createsd2% %Backup2%
)
echo.
set /p userint= ^> %denter% 
set userint=%userint:~0,1%
if %userint%==9 (if /i %Backup%==OFF (set Backup=ON) else (set Backup=OFF))&goto :DUALMENU
if %userint%==4 goto :prompt2
if %userint%==3 (set WIMFILE=install.wim&set combine=1&goto :Dual)
if %userint%==2 (set WIMFILE=install.wim&goto :Dual)
if %userint%==1 (set WIMFILE=install.esd&goto :Dual)
GOTO :DUALMENU

:dCount
set /a count+=1
set "ESDfile%count%=%1
goto :eof

:dInfo
set ESDedition2%1=0
dism /english /get-wiminfo /wimfile:"!ESDfile%1!" | find /i "China" 1>nul && set ESDedition2%1=1
for /f "skip=1 tokens=2 delims=: " %%i in ('dism /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Version"') do set ESDver%1=%%i
for /f "tokens=2 delims=: " %%i in ('dism /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Edition"') do set ESDedition%1=%%i
for /f "tokens=2 delims=: " %%i in ('dism /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Architecture"') do set ESDarch%1=%%i
for /f "tokens=1" %%i in ('dism /english /get-wiminfo /wimfile:"!ESDfile%1!" /index:4 ^| find /i "Default"') do set ESDlang%1=%%i
for /f "tokens=2 delims=: " %%i in ('dism /english /Get-WimInfo /WimFile:"!ESDfile%1!" ^| findstr /b "Index"') do set images=%%i
IF %images% GEQ 5 SET ESDmulti%1=%images%
bin\wimlib-imagex.exe info "!ESDfile%1!" 4 >nul 2>&1
IF %ERRORLEVEL% EQU 74 SET ESDenc%1=1
goto :eof

:Dual
cls
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
mkdir ISOFOLDER
CALL :dISO 1
CALL :dISO 2
bin\7z.exe l .\ISOFOLDER\x64\sources\SetupPlatform.dll >.\bin\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\version.txt" 2^>nul') do set version=%%i.%%j
for /f "tokens=7 delims=.) " %%i in ('"findstr /B "FileVersion" .\bin\version.txt" 2^>nul') do set datetime=%%i
for /f "tokens=6 delims=.( " %%i in ('"findstr /B "FileVersion" .\bin\version.txt" 2^>nul') do set branch=%%i
del /f /q .\bin\version.txt
set _label2=
if /i %branch%==WinBuild (
"%wimlib%" extract "%ESDfile1%" 4 \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)
if %version%==10240.16487 (set version=10240.16393&set datetime=150909-1450&set branch=th1_refresh)
if %version%==10586.103 (set version=10586.0&set datetime=160212-2000&set branch=th2_refresh)
if %version%==10586.162 (set version=10586.0&set datetime=160426-1409&set branch=th2_refresh)
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!
set langid=%ESDlang1%
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 %ESDarch1%==x86 (set ESDarch1=X86) else (set ESDarch1=X64)
if /i %ESDarch2%==x86 (set ESDarch2=X86) else (set ESDarch2=X64)
if /i %DVDLABEL1% equ %DVDLABEL2% (
set DVDLABEL=%DVDLABEL1%_%archl%FRE_%langid%_DV5
set DVDISO=%_label%%DVDISO1%_%archl%FRE_%langid%.ISO
) else (
set DVDLABEL=J_CCSA_%archl%FRE_%langid%_DV5
set DVDISO=%_label%%DVDISO1%_%ESDarch1%FRE-%DVDISO2%_%ESDarch2%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
copy /y ISOFOLDER\x86\efi\boot\bootia32.efi ISOFOLDER\efi\boot\bootia32.efi >nul 2>&1
for /d %%G in (bootmgr,bootmgr.efi,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
for /f "tokens=2 delims={}" %%A in ('bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /copy {default} /d "Windows 10 Setup (32-bit)"') do set guid={%%A}
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set %guid% device ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
bcdedit /store ISOFOLDER\efi\microsoft\boot\bcd /set %guid% osdevice ramdisk=[boot]\x86\sources\boot.wim,%ramdiskoptions% >nul 2>&1
echo.
echo ===============================================================================
echo %creat% ISO...
echo ===============================================================================
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 "isotime=%%H/%%L,%%I:%%J:%%K")
call :setdate %mmm%
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 %ind3e%
echo.
echo %presskey%
pause >nul
exit
)
rmdir /s /q ISOFOLDER\
echo.
echo %presskey%
pause >nul
GOTO :QUIT

:dISO
echo.
SET ENCRYPTEDESD=!ESDfile%1!
IF !ESDenc%1!==1 CALL :DECRYPT
"%wimlib%" extract "%ENCRYPTEDESD%" 1 sources\ei.cfg --dest-dir=.\bin --no-acls >nul 2>&1
type .\bin\ei.cfg 2>nul | find /i "Volume" 1>nul && set ESDvol%1=1
del bin\ei.cfg >nul 2>&1
CALL :dPREPARE %1
echo.
echo ===============================================================================
echo %creat% Setup Media Layout ^(!ESDarch%1!^)...
echo ===============================================================================
echo.
"%wimlib%" apply "%ENCRYPTEDESD%" 1 ISOFOLDER\!ESDarch%1!\ >nul 2>&1
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind1e%&PAUSE&GOTO :QUIT)
del ISOFOLDER\!ESDarch%1!\MediaMeta.xml >nul 2>&1
echo.
echo ===============================================================================
echo %creat% boot.wim ^(!ESDarch%1!^)...
echo ===============================================================================
echo.
"%wimlib%" export "%ENCRYPTEDESD%" 2 ISOFOLDER\!ESDarch%1!\sources\boot.wim --compress=maximum
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
echo.
"%wimlib%" export "%ENCRYPTEDESD%" 3 ISOFOLDER\!ESDarch%1!\sources\boot.wim --boot
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %creat% %WIMFILE% ^(!ESDarch%1!^)...
echo ===============================================================================
echo.
if /i %WIMFILE%==install.esd (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\!ESDarch%1!\sources\%WIMFILE%
) else (
"%wimlib%" export "%ENCRYPTEDESD%" 4 ISOFOLDER\!ESDarch%1!\sources\%WIMFILE% --compress=maximum
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
IF NOT !ESDmulti%1!==0 FOR /L %%j IN (5,1,!ESDmulti%1!) DO (
echo.
"%wimlib%" export "%ENCRYPTEDESD%" %%j ISOFOLDER\!ESDarch%1!\sources\%WIMFILE%
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %ind2e%&PAUSE&GOTO :QUIT)
exit /b

:dPREPARE
IF !ESDmulti%1!==5 (
if /i !ESDedition%1!==Professional set DVDLABEL%1=J_CCSA&set DVDISO%1=PRO-CORE_OEMRET
if /i !ESDedition%1!==ProfessionalN set DVDLABEL%1=J_CCSNA&set DVDISO%1=PRON-COREN_OEMRET
exit /b
)
IF !ESDmulti%1! GEQ 6 (
if /i !ESDedition%1!==Professional set DVDLABEL%1=J_CCSA&set DVDISO%1=COMBINEDMULTI_OEMRET
if /i !ESDedition%1!==ProfessionalN set DVDLABEL%1=J_CCSNA&set DVDISO%1=COMBINEDMULTIN_OEMRET
if !ESDedition2%1!==1 set DVDLABEL%1=J_CCSNA&set DVDISO%1=COMBINEDMULTICHINA_OEMRET
exit /b
)
if /i !ESDedition%1!==Core set DVDLABEL%1=J_CCRA&set DVDISO%1=CORE_OEMRET
if /i !ESDedition%1!==CoreN set DVDLABEL%1=J_CCRNA&set DVDISO%1=COREN_OEMRET
if /i !ESDedition%1!==CoreSingleLanguage set DVDLABEL%1=J_CSLA&set DVDISO%1=SINGLELANGUAGE_OEM
if /i !ESDedition%1!==CoreCountrySpecific set DVDLABEL%1=J_CCHA&set DVDISO%1=CHINA_OEM
if /i !ESDedition%1!==Professional (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRA&set DVDISO%1=PROFESSIONALVL_VOL) else (set DVDLABEL%1=J_CPRA&set DVDISO%1=PRO_OEMRET))
if /i !ESDedition%1!==ProfessionalN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRNA&set DVDISO%1=PROFESSIONALNVL_VOL) else (set DVDLABEL%1=J_CPRNA&set DVDISO%1=PRON_OEMRET))
if /i !ESDedition%1!==Education (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CEDA&set DVDISO%1=EDUCATION_VOL) else (set DVDLABEL%1=J_CEDA&set DVDISO%1=EDUCATION_RET))
if /i !ESDedition%1!==EducationN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CEDNA&set DVDISO%1=EDUCATIONN_VOL) else (set DVDLABEL%1=J_CEDNA&set DVDISO%1=EDUCATIONN_RET))
if /i !ESDedition%1!==Enterprise set DVDLABEL%1=J_CENA&set DVDISO%1=ENTERPRISE_VOL
if /i !ESDedition%1!==EnterpriseN set DVDLABEL%1=J_CENNA&set DVDISO%1=ENTERPRISEN_VOL
if /i !ESDedition%1!==EnterpriseS set DVDLABEL%1=J_CES&set DVDISO%1=ENTERPRISES_VOL
if /i !ESDedition%1!==EnterpriseSN set DVDLABEL%1=J_CESN&set DVDISO%1=ENTERPRISESN_VOL
if /i !ESDedition%1!==PPIPro set DVDLABEL%1=J_CPPIA&set DVDISO%1=PPIPRO_OEM
if /i !ESDedition%1!==ProfessionalSingleLanguage set DVDLABEL%1=J_CPRSLA_&set DVDISO%1=PROSINGLELANGUAGE_OEM
if /i !ESDedition%1!==ProfessionalCountrySpecific set DVDLABEL%1=J_CPRCHA&set DVDISO%1=PROCHINA_OEM
if /i !ESDedition%1!==ProfessionalEducation (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPREA&set DVDISO%1=PROFESSIONALEDUCATION_VOL) else (set DVDLABEL%1=J_CPREA&set DVDISO%1=PROEDUCATION_OEMRET))
if /i !ESDedition%1!==ProfessionalEducationN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRENA&set DVDISO%1=PROFESSIONALEDUCATIONN_VOL) else (set DVDLABEL%1=J_CPRENA&set DVDISO%1=PROEDUCATIONN_OEMRET))
if /i !ESDedition%1!==ProfessionalWorkstation (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRWA&set DVDISO%1=PROFESSIONALWORKSTATION_VOL) else (set DVDLABEL%1=J_CPRWA&set DVDISO%1=PROWORKSTATION_OEMRET))
if /i !ESDedition%1!==ProfessionalWorkstationN (IF !ESDvol%1!==1 (set DVDLABEL%1=J_CPRWNA&set DVDISO%1=PROFESSIONALWORKSTATIONN_VOL) else (set DVDLABEL%1=J_CPRWNA&set DVDISO%1=PROWORKSTATIONN_OEMRET))
if /i !ESDedition%1!==EnterpriseSubscription set DVDLABEL%1=J_CESA_&set DVDISO%1=ENTERPRISESUBSCRIPTION_VOL
if /i !ESDedition%1!==EnterpriseSubscriptionN set DVDLABEL%1=J_CESNA&set DVDISO%1=ENTERPRISESUBSCRIPTIONN_VOL
exit /b

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

:QUIT
IF EXIST ISOFOLDER\ rmdir /s /q ISOFOLDER\
IF EXIST "%ENCRYPTEDESD%.bak" (
del /f /q "%ENCRYPTEDESD%" >nul 2>&1
ren "%ENCRYPTEDESD%.bak" %ENCRYPTEDESDN%
)
exit