/
WimBuilder.cmd
197 lines (164 loc) · 4.82 KB
/
WimBuilder.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@echo off
cd /d "%~dp0"
title %~n0(%cd%)
set "APP_NAME=%~n0"
set APP_OPT_HELP=
call :PARSE_OPTIONS %*
rem set APP_OPT_
if /i "x%APP_OPT_HELP%"=="x1" goto :SHOW_HELP
set "APP_ROOT=%cd%"
if "x%APP_ROOT:~-1%"=="x\" set APP_ROOT=%APP_ROOT:~0,-1%
set "PATH_ORG=%PATH%"
rem ======set bin PATH======
set "PATH=%APP_ROOT%\bin;%PATH%"
set PROCESSOR_ARCHITECTURE=AMD64
if /i %PROCESSOR_IDENTIFIER:~0,3%==x86 (
set PROCESSOR_ARCHITECTURE=x86
)
set APP_ARCH=x86
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set APP_ARCH=x64
set "PATH=%APP_ROOT%\bin\x64;%APP_ROOT%\bin\x86;%PATH%"
) else (
set "PATH=%APP_ROOT%\bin\x86;%PATH%"
)
rem ========================
call EnvCheck.bat
rem run with Administrators right
IsAdmin.exe
if not ERRORLEVEL 1 (
if not "x%~1"=="xrunas" (
set ElevateMe=1
set "PATH=%PATH_ORG%"
bin\ElevateMe.vbs "%~0" "runas" %*
)
goto :EOF
)
if "x%~1"=="xrunas" (SHIFT)
call DisAutoRun
set APP_HOST_WIN=UNKNOWN
if exist "%windir%\SystemResources\" set APP_HOST_WIN=10
rem init i18n file
set "I18N_SCRIPT=%~dp0lib\i18n\i18n_.wsf"
set findcmd=findstr
if not exist "%windir%\System32\findstr.exe" set findcmd=find
for /f "tokens=1,2 delims==';[] " %%i in ('%findcmd% "$lang" config.js') do (
set LocaleID[%%i]=%%j
)
set LocaleID=%LocaleID[$lang]%
for /f "delims=" %%i in ('cscript.exe //nologo "%I18N_SCRIPT%" GetLocaleName') do set APP_HOST_LANG=%%i
if "x%APP_HOST_LANG%"=="x" set APP_HOST_LANG=en-US
if not "x%LocaleID%"=="x" goto :SKIP_AUTO_LANG
set LocaleID=%APP_HOST_LANG%
:SKIP_AUTO_LANG
set I18N_LCID=%LocaleID%
set APP_UI_LANG=%LocaleID%
if not exist lib\i18n\%LocaleID%.vbs (
set I18N_LCID=0
goto :MAIN_ENTRY
)
set "I18N_SCRIPT=%~dp0lib\i18n\i18n.wsf"
if not exist lib\i18n\0.vbs goto :UPDATE_I18NRES
fc /b lib\i18n\%LocaleID%.vbs lib\i18n\0.vbs>nul
if not ERRORLEVEL 1 goto :MAIN_ENTRY
:UPDATE_I18NRES
copy /y lib\i18n\%LocaleID%.vbs lib\i18n\0.vbs
:MAIN_ENTRY
call :APP_ENV
rem ======set macros PATH======
set "PATH=%APP_ROOT%\lib\macros;%PATH%"
rem ========================
start %APP_START_OPT% mshta "%~dp0assets\%APP_NAME%.hta" %*
goto :EOF
:SHOW_HELP
echo Usage: %~nx0 [-h^|--help] [^<Options^>...]
echo.
echo ^<Options^>
echo --verbose
echo --build^|--build-with-log
echo --source-folder FOLDER^|DRIVE
echo --source-wim SOURCE_WIM_FILE
echo --source-index INDEX
echo --base-wim BASE_WIM_FILE
echo --base-index INDEX
echo --project PROJECT
echo --preset PRESET
echo --make-iso
echo --close-ui (the option will append --wait option by default)
echo --wait
echo --nowait
echo.
echo Examples:
echo.
echo %~nx0 --build --make-iso --close-ui
echo %~nx0 --source-folder I: --source-index 1 --build --preset full --make-iso --close-ui
echo %~nx0 --source-wim "D:\win10v1903\sources\install.wim" --source-index 4 --build --preset full --make-iso --close-ui
echo %~nx0 --source-folder H: --source-index 1 --base-wim "D:\BOOTPE\boot.wim" --preset lite --build-with-log --make-iso
goto :EOF
:PARSE_OPTIONS
if /i "x%1"=="x" goto :EOF
if /i "x%1"=="x-h" (
set APP_OPT_HELP=1
goto :EOF
) else if /i "x%1"=="x--help" (
set APP_OPT_HELP=1
goto :EOF
) else if /i "x%1"=="x--build" (
set WB_OPT_BUILD=CMD
) else if /i "x%1"=="x--build-with-log" (
set WB_OPT_BUILD=LOG
) else if /i "x%1"=="x--verbose" (
set WB_OPT_VERBOSE=1
) else if /i "x%1"=="x--source-driver" (
set "WB_SRC_FOLDER=%~2"
SHIFT
) else if /i "x%1"=="x--source-folder" (
set "WB_SRC_FOLDER=%~2"
SHIFT
) else if /i "x%1"=="x--source-wim" (
set "WB_SRC_WIM=%~2"
SHIFT
) else if /i "x%1"=="x--source-index" (
set WB_SRC_INDEX=%2
SHIFT
) else if /i "x%1"=="x--base-wim" (
set "WB_BASE_WIM=%~2"
SHIFT
) else if /i "x%1"=="x--base-index" (
set WB_BASE_INDEX=%2
SHIFT
) else if /i "x%1"=="x--project" (
set WB_OPT_PROJECT=%2
SHIFT
) else if /i "x%1"=="x--preset" (
set WB_OPT_PRESET=%2
SHIFT
) else if /i "x%1"=="x--make-iso" (
set WB_OPT_MAKE_ISO=1
) else if /i "x%1"=="x--close-ui" (
set WB_OPT_CLOSE_UI=1
set APP_START_OPT=/wait
) else if /i "x%1"=="x--wait" (
set APP_START_OPT=/wait
) else if /i "x%1"=="x--nowait" (
set APP_START_OPT=
)
SHIFT
goto :PARSE_OPTIONS
goto :EOF
:APP_ENV
set "APPDATA_DIR=AppData"
set "Factory=_Factory_"
set "ISO_DIR=_ISO_"
set "V_APP=%APP_ROOT%\vendor"
set "V_USER=%APP_ROOT%\%APPDATA_DIR%\vendor"
set "V=%V_APP%"
rem mount winre.wim/boot.wim with wimlib, otherwise dism
set USE_WIMLIB=0
if exist UserConfig.cmd call UserConfig.cmd
set "V_USER=%APP_ROOT%\%APPDATA_DIR%\vendor"
set "FACTORY_PATH=%APP_ROOT%\%Factory%"
set "ISO_PATH=%APP_ROOT%\%ISO_DIR%"
if "[%Factory:~1,1%]"=="[:]" set "FACTORY_PATH=%Factory%"
if "[%ISO_DIR:~1,1%]"=="[:]" set "ISO_PATH=%ISO_DIR%"
goto :EOF