@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=v170321"
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") ELSE (SET "wimlib=%~dp0bin\wimlib-imagex.exe")
cd /d "%~dp0"
setlocal EnableExtensions
setlocal EnableDelayedExpansion
color 1f
SET UUP=
SET ERRORTEMP=
SET VOL=0
SET uups_esd_num=0
set uupa=0
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
mkdir temp

if exist "UUPs\*.esd" set UUP=.\UUPs&goto :check

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

:check
del temp\uups_esd.txt 1>nul 2>nul
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 %UUP%\%%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
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=!name%%i!"
goto :MAINMENU

:MULTIMENU
cls
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 %userinp%==alliso set "uupa=1"&set "uupb=iso"&set WIMFILE=install.wim&goto :ALL
if %userinp%==allisz set "uupa=1"&set "uupb=iso"&set WIMFILE=install.esd&goto :ALL
if %userinp%==allwim set "uupa=1"&set "uupb=install"&set WIMFILE=install.wim&goto :ALL
if %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
echo ===============================================================================
echo %txt17%: %nameos%
echo ===============================================================================
echo.
echo.       1 - %txt07%
echo.       2 - %txt08%
echo.       3 - %txt20%
echo.       4 - %txt21%
echo.       5 - %txt06%
echo.
echo ===============================================================================
echo %txt09%
echo ===============================================================================
choice /c 1234590 /n /m "%txt10%: "
if errorlevel 7 GOTO :QUIT
if errorlevel 6 GOTO :MULTIMENU
if errorlevel 5 GOTO :INFO
if errorlevel 4 (set WIMFILE=install.esd&goto :Single)
if errorlevel 3 (set WIMFILE=install.wim&goto :Single)
if errorlevel 2 (set WIMFILE=install.esd&goto :ISO)
if errorlevel 1 (set WIMFILE=install.wim&goto :ISO)
GOTO :MAINMENU

: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!"
if /i %uupb%==iso call :ISO
if /i %uupb%==install call :Single
)
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

:ALLISO
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!"
call :Single
)
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

:ISO
cls
CALL :PREPARE
if exist "%UUP%\*.cab" (
echo.
echo ===============================================================================
echo %txt11% . . .
echo ===============================================================================
echo.
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
)
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 ===============================================================================
echo.
"%wimlib%" export "%MetadataESD%" 2 ISOFOLDER\sources\boot.wim --compress=maximum -boot
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt15%&PAUSE&GOTO :QUIT)
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 %WIMFILE%==install.wim (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 ISOFOLDER\sources\%WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd" --compress=maximum
) else (
"%wimlib%" export "%MetadataESD%" 3 ISOFOLDER\sources\%WIMFILE% --ref="%UUP%\*.esd" --compress=maximum
))
if /i %WIMFILE%==install.esd (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 ISOFOLDER\sources\%WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd"
) else (
"%wimlib%" export "%MetadataESD%" 3 ISOFOLDER\sources\%WIMFILE% --ref="%UUP%\*.esd"
))
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt15%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %txt13% . . .
echo ===============================================================================
echo.
"%wimlib%" update ISOFOLDER\sources\install.wim 1 --command="add 'ISOFOLDER\sources\boot.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
"%wimlib%" info %~dp0ISOFOLDER\sources\boot.wim 1 --image-property FLAGS=9 1>nul 2>nul
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
))
if exist "%UUP%\*.cab" (
echo.
echo ===============================================================================
echo %txt11% . . .
echo ===============================================================================
echo.
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
)
echo.
echo ===============================================================================
echo %txt12% %WIMFILE% . . .
echo ===============================================================================
echo.
if /i %WIMFILE%==install.wim (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 %WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd" --compress=maximum
) else (
"%wimlib%" export "%MetadataESD%" 3 %WIMFILE% --ref="%UUP%\*.esd" --compress=maximum)
)
if /i %WIMFILE%==install.esd (
if exist "temp\*.ESD" (
"%wimlib%" export "%MetadataESD%" 3 %WIMFILE% --ref="%UUP%\*.esd" --ref="temp\*.esd"
) else (
"%wimlib%" export "%MetadataESD%" 3 %WIMFILE% --ref="%UUP%\*.esd")
)
SET ERRORTEMP=%ERRORLEVEL%
IF %ERRORTEMP% NEQ 0 (echo.&echo %txt15%&PAUSE&GOTO :QUIT)
echo.
echo ===============================================================================
echo %txt13% . . .
echo ===============================================================================
echo.
if not exist "temp\winre.wim" "%wimlib%" export "%MetadataESD%" 2 temp\winre.wim --compress=maximum
if /i %uupa%==1 (
for /L %%i in (1, 1, %uups_esd_num%) do "%wimlib%" update %WIMFILE% %%i --command="add 'temp\winre.wim' '\windows\system32\recovery\winre.wim'" 1>nul 2>nul
)
if /i %uupa%==0 (
"%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=.\bin\temp --no-acls >nul 2>&1
type .\bin\temp\ei.cfg 2>nul | find /i "Volume" 1>nul && set VOL=1
"%wimlib%" extract "%MetadataESD%" 1 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)
"%wimlib%" extract "%MetadataESD%" 3 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 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!
)
set _label2=
if /i %branch%==WinBuild (
"%wimlib%" extract "%MetadataESD%" 3 \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!
rd /s /q .\bin\temp

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 %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

: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 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%
set "uups_esd%1=%uups_esd%"
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"
if /i !arch%1!==x86_64 set "arch%1=x64"
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! (!arch%1! / !langid%1!)"
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

: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