-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageproc.cmd
244 lines (244 loc) · 15.2 KB
/
imageproc.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
::Image Processor (C) Joshua Cline - All rights reserved
@ECHO OFF&&SETLOCAL ENABLEDELAYEDEXPANSION&&CD /D "%~DP0"&&Reg.exe query "HKU\S-1-5-19\Environment">NUL
IF NOT "%ERRORLEVEL%" EQU "0" ECHO Right-Click ^& Run As Administrator&&PAUSE&&EXIT 0
SET "##=[94m"&&SET "#$=[97m"&&SET "#@=[96m"&&FOR /F "TOKENS=*" %%a in ('ECHO %CD%') DO (SET "IMAGE_FOLDER=%%a")
SET "CAPS_SET=IMAGE_FOLDER"&&SET "CAPS_VAR=%IMAGE_FOLDER%"&&CALL:CAPS_SET
SET "CHAR_STR=%IMAGE_FOLDER%"&&SET "CHAR_CHK= "&&CALL:CHAR_CHK
IF DEFINED CHAR_FLG ECHO Remove the space from the path\folder name, then launch again&&PAUSE&&EXIT 0
TITLE Download more scripted utilities from github.com/joshuacline
:IMAGE_PROCESSOR
CLS&&FOR %%a in (PACK_XLVL WIM_XLVL) DO (IF NOT DEFINED %%a SET "%%a=FAST")
FOR %%a in (WIM_XXX PAK_XXX IMAGEPROC_SLOT) DO (IF NOT DEFINED %%a SET "%%a=1")
IF NOT DEFINED VHDX_XLVL SET "VHDX_XLVL=DISABLED"
IF NOT DEFINED SOURCE_TYPE SET "SOURCE_TYPE=WIM"&&SET "TARGET_TYPE=VHDX"
IF NOT DEFINED VHDX_SIZE SET "VHDX_SIZE=25600"
FOR %%a in (WIM_SOURCE VHDX_SOURCE) DO (SET "OBJ_FLD=%IMAGE_FOLDER%"&&CALL SET "OBJ_CHK=%%a"&&CALL:OBJ_CLEAR)
FOR %%a in (WIM_SOURCE VHDX_SOURCE WIM_TARGET VHDX_TARGET) DO (IF NOT DEFINED %%a SET "%%a=SELECT")
IF "%WIM_SOURCE%"=="SELECT" SET "WIM_DESC=NULL"&&SET "WIM_INDEX=1"
CALL:PAD_LINE&&ECHO Image Processing&&CALL:PAD_LINE
ECHO Place WIM/VHDX files in the same folder as this script&&CALL:PAD_LINE
IF "%SOURCE_TYPE%"=="WIM" IF NOT "%WIM_SOURCE%"=="SELECT" CALL:WIM_INDEX_QUERY
IF NOT DEFINED WIM_DESC SET "WIM_DESC=NULL"&&SET "WIM_INDEX=1"
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="VHDX" ECHO WIM (%##%X%#$%) VHDX&&CALL:PAD_LINE
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="WIM" ECHO WIM (%##%X%#$%) WIM&&CALL:PAD_LINE
IF "%SOURCE_TYPE%"=="VHDX" IF "%TARGET_TYPE%"=="WIM" ECHO VHDX (%##%X%#$%) WIM&&CALL:PAD_LINE
IF "%SOURCE_TYPE%"=="VHDX" ECHO AVAILABLE VHDX'S:&&SET "BLIST=VHDX"&&CALL:FILE_LIST&&CALL:PAD_LINE&&ECHO. (%##%S%#$%)ource[%#@%VHDX%#$%] [%#@%%VHDX_SOURCE%%#$%]&&CALL:PAD_LINE
IF "%SOURCE_TYPE%"=="WIM" ECHO AVAILABLE WIM'S:&&SET "BLIST=WIM"&&CALL:FILE_LIST&&CALL:PAD_LINE&&ECHO. (%##%S%#$%)ource[%#@%WIM%#$%] [%#@%%WIM_SOURCE%%#$%] (%##%I%#$%)ndex[%#@%%WIM_INDEX%%#$%] [Edition[%#@%%WIM_DESC%%#$%]&&CALL:PAD_LINE
IF "%TARGET_TYPE%"=="VHDX" ECHO EXISTING VHDX'S:&&SET "BLIST=VHDX"&&CALL:FILE_LIST&&CALL:PAD_LINE&&ECHO. (%##%T%#$%)arget[%#@%VHDX%#$%] [%#@%%VHDX_TARGET%%#$%] (%##%G%#$%)o^^! (%##%V%#$%)Size[%#@%%VHDX_SIZE%MB%#$%] (%##%Z%#$%)[%#@%%VHDX_XLVL%%#$%]&&CALL:PAD_LINE
IF "%TARGET_TYPE%"=="WIM" ECHO EXISTING WIM'S:&&SET "BLIST=WIM"&&CALL:FILE_LIST&&CALL:PAD_LINE&&ECHO. (%##%T%#$%)arget[%#@%WIM%#$%] [%#@%%WIM_TARGET%%#$%] (%##%G%#$%)o^^! (%##%Z%#$%)[X-Lvl[%#@%%WIM_XLVL%%#$%]&&CALL:PAD_LINE
ECHO Press (%##%Q%#$%) to quit&&CALL:MENU_SELECT
IF NOT DEFINED SELECT GOTO:IMAGE_PROCESSOR
IF "%SELECT%"=="Q" EXIT 0
IF "%SELECT%"=="X" CALL:IMAGEPROC_SLOT
IF "%SELECT%"=="T" CALL:IMAGEPROC_PROMPT
IF "%SELECT%"=="Z" CALL:IMAGEPROC_XLVL
IF "%SELECT%"=="S" CALL:IMAGEPROC_PICK&&SET "SELECT="
IF "%SELECT%"=="V" CALL:IMAGEPROC_VSIZE&&SET "SELECT="
IF "%SELECT%"=="I" IF "%SOURCE_TYPE%"=="WIM" IF NOT "%WIM_SOURCE%"=="SELECT" CALL:WIM_INDEX
IF "%SELECT%"=="G" CALL:IMAGEPROC_START&&CALL:PAUSED
GOTO:IMAGE_PROCESSOR
:IMAGEPROC_START
CALL:PAD_LINE&&ECHO Image Processing Start&&CALL:PAD_LINE&&SET "ERR_MSG="&&SET "APPLYDIR_MASTER=V:"&&SET "CAPTUREDIR_MASTER=V:"&&SET "VHDX_MB=%VHDX_SIZE%"
IF "%TARGET_TYPE%"=="VHDX" IF EXIST "%IMAGE_FOLDER%\%VHDX_TARGET%" SET "ERR_MSG=%##%Target %VHDX_TARGET% exists. Try another name or rename the existing file.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%TARGET_TYPE%"=="WIM" IF EXIST "%IMAGE_FOLDER%\%WIM_TARGET%" SET "ERR_MSG=%##%Target %WIM_TARGET% exists. Try another name or rename the existing file.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%SOURCE_TYPE%"=="VHDX" IF "%VHDX_SOURCE%"=="SELECT" SET "ERR_MSG=%##%Source %SOURCE_TYPE% not set.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%TARGET_TYPE%"=="VHDX" IF "%VHDX_TARGET%"=="SELECT" SET "ERR_MSG=%##%Target %TARGET_TYPE% not set.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%SOURCE_TYPE%"=="WIM" IF "%WIM_SOURCE%"=="SELECT" SET "ERR_MSG=%##%Source %SOURCE_TYPE% not set.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%TARGET_TYPE%"=="WIM" IF "%WIM_TARGET%"=="SELECT" SET "ERR_MSG=%##%Target %TARGET_TYPE% not set.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF EXIST "V:\" SET "ERR_MSG=%##%Drive letter V:\ can NOT be in use. Unmount the Vdisk in use.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF NOT DEFINED WIM_INDEX SET "WIM_INDEX=1"
IF NOT DEFINED WIM_XLVL SET "WIM_XLVL=FAST"
IF NOT "%VHDX_XLVL%"=="COMPACT" SET "COMPACTX="
IF "%VHDX_XLVL%"=="COMPACT" SET "COMPACTX= /COMPACT"
CALL:VDISK_DETACH&&IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="WIM" CALL:SCRATCH_CREATE
IF "%SOURCE_TYPE%"=="VHDX" SET "VDISK=%IMAGE_FOLDER%\%VHDX_SOURCE%"
IF "%TARGET_TYPE%"=="VHDX" SET "VDISK=%IMAGE_FOLDER%\%VHDX_TARGET%"
IF "%SOURCE_TYPE%"=="WIM" SET "IMAGE_SRC=%IMAGE_FOLDER%\%WIM_SOURCE%"
IF "%TARGET_TYPE%"=="WIM" SET "IMAGE_TGT=%IMAGE_FOLDER%\%WIM_TARGET%"
IF "%SOURCE_TYPE%"=="VHDX" IF "%TARGET_TYPE%"=="WIM" CALL:VDISK_ATTACH
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="VHDX" CALL:VDISK_CREATE
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="WIM" SET "VDISK=%SCRATCHDIR%\SCRATCH.VHDX"&&SET "VHDX_MB=20000"&&CALL:VDISK_CREATE
IF NOT EXIST "V:\" SET "ERR_MSG=%##%Virtual Disk Error. If VHDX refuses mounting, reboot and try again.%#$%"&&CALL:VDISK_DETACH&&GOTO:IMAGEPROC_CLEANUP
IF NOT DEFINED WIM_DESC SET "WIM_DESC=WINDICK"
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="VHDX" DISM /ENGLISH /APPLY-IMAGE /IMAGEFILE:"%IMAGE_SRC%" /INDEX:%WIM_INDEX% /APPLYDIR:"%APPLYDIR_MASTER%"%COMPACTX%
IF "%SOURCE_TYPE%"=="WIM" IF "%TARGET_TYPE%"=="WIM" DISM /ENGLISH /APPLY-IMAGE /IMAGEFILE:"%IMAGE_SRC%" /INDEX:%WIM_INDEX% /APPLYDIR:"%APPLYDIR_MASTER%"
IF "%TARGET_TYPE%"=="WIM" IF NOT EXIST "%APPLYDIR_MASTER%\*" CALL:VDISK_DETACH&&DEL /F /Q "%IMAGE_FOLDER%\%WIM_TARGET%">NUL 2>&1
IF "%TARGET_TYPE%"=="VHDX" IF NOT EXIST "%APPLYDIR_MASTER%\*" CALL:VDISK_DETACH&&DEL /F /Q "%IMAGE_FOLDER%\%VHDX_TARGET%">NUL 2>&1
IF NOT EXIST "%APPLYDIR_MASTER%\*" CALL:PAD_LINE&&SET "ERR_MSG=%##%Source Extraction Error. If source refuses to extract, reboot and try again.%#$%"&&GOTO:IMAGEPROC_CLEANUP
IF "%TARGET_TYPE%"=="WIM" DISM /ENGLISH /CAPTURE-IMAGE /CAPTUREDIR:"%CAPTUREDIR_MASTER%" /IMAGEFILE:"%IMAGE_TGT%" /COMPRESS:%WIM_XLVL% /NAME:%WIM_DESC%
CALL:VDISK_DETACH>NUL 2>&1
:IMAGEPROC_CLEANUP
IF DEFINED ERR_MSG ECHO.&&ECHO %ERR_MSG%
ECHO.&&CALL:SCRATCH_DELETE&&CALL:PAD_LINE&&ECHO Image Processing Complete&&CALL:PAD_LINE
EXIT /B
:MENU_SELECT
SET "SELECT="&&SET /P "SELECT=$>>"
IF DEFINED SELECT SET "CAPS_SET=SELECT"&&SET "CAPS_VAR=%SELECT%"&&CALL:CAPS_SET
CALL SET "$ELECTMP=%%$ITEM%SELECT%%%"&&IF DEFINED SELECT CALL SET "$ELECT=%SELECT%"
IF DEFINED SELECT IF DEFINED $ELECTMP CALL SET "$ELECT$=%$ELECTMP%"
EXIT /B
:PROMPT_SET
IF NOT DEFINED PROMPT_SET SET "PROMPT_SET=SELECT"
SET "PROMPT_VAR="&&SET /P "PROMPT_VAR=$>>"
SET "CAPS_SET=%PROMPT_SET%"&&SET "CAPS_VAR=%PROMPT_VAR%"
IF DEFINED PROMPT_ANY CALL SET "%CAPS_SET%=%CAPS_VAR%"
IF NOT DEFINED PROMPT_ANY CALL:CAPS_SET
SET "PROMPT_ANY="&&SET "PROMPT_SET="&&SET "PROMPT_VAR="
EXIT /B
:CAPS_SET
FOR %%G 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 (CALL SET "CAPS_VAR=%%CAPS_VAR:%%G=%%G%%")
CALL SET "%CAPS_SET%=%CAPS_VAR%"&&SET "CAPS_SET="&&SET "CAPS_VAR="
EXIT /B
:CHAR_CHK
FOR %%a in (CHAR_STR CHAR_CHK) DO (IF NOT DEFINED %%a EXIT /B)
SET "CHAR_FLG="&&FOR /F "DELIMS=" %%$ in ('CMD.EXE /D /U /C ECHO %CHAR_STR%^| FIND /V ""') do (IF "%%$"=="%CHAR_CHK%" SET "ERROR=1"&&SET "CHAR_FLG=1")
EXIT /B
:CHECK
SET "ERROR="&&IF NOT DEFINED SELECT SET "ERROR=1"
SET "CHAR_CHK= "&&SET "CHAR_STR=%SELECT%"&&CALL:CHAR_CHK
IF "%CHECK%"=="NUM" IF "%SELECT%" LSS "0" SET "ERROR=1"
IF "%CHECK%"=="NUM" IF "%SELECT%" GTR "9999999" SET "ERROR=1"
IF "%CHECK%"=="NUM" SET "CAPS_SET=SELECT"&&SET "CAPS_VAR=%SELECT%"&&CALL:CAPS_SET
IF "%CHECK%"=="NUM" FOR %%G 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 "CHAR_CHK=%%G"&&SET "CHAR_STR=%SELECT%"&&CALL:CHAR_CHK)
SET "CHECK="
EXIT /B
:OBJ_CLEAR
CALL SET "OBJ_CHKX=%%%OBJ_CHK%%%"
IF NOT EXIST "%OBJ_FLD%\%OBJ_CHKX%" CALL SET "%OBJ_CHK%=SELECT"
EXIT /B
:PAD_LINE
ECHO [92m=====================================================================[97m
EXIT /B
:PAD_PREV
ECHO Press (%##%Enter%#$%) to return to previous menu
EXIT /B
:PAUSED
SET /P "PAUSED=. Press (%##%Enter%#$%) to continue..."
EXIT /B
:FILE_PICK
IF NOT DEFINED PICK GOTO:PICK_ERROR
CLS&&CALL:PAD_LINE&&ECHO File Picker&&CALL:PAD_LINE&&ECHO AVAILABLE %PICK%'S:
SET "NLIST=%PICK%"&&CALL:FILE_LIST&&CALL:PAD_LINE&&ECHO Select a (%##%#%#$%)&&CALL:PAD_LINE&&CALL:PAD_PREV
FOR %%a in (ERROR SELECT $PICK $ELECT $ELECT$) DO (SET "%%a=")
SET /P "SELECT=$>>"&&FOR %%G 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 (CALL SET "SELECT=%%SELECT:%%G=%%G%%")
IF "%SELECT%" GTR "9999999" SET "ERROR=1"
IF "%SELECT%" LSS "0" SET "ERROR=1"
IF DEFINED ERROR GOTO:PICK_ERROR
CALL SET "$ELECT=%SELECT%"&&CALL SET "$ELECT$=%%$ITEM%SELECT%%%"
IF NOT DEFINED $ELECT$ SET "ERROR=1"&&GOTO:PICK_ERROR
SET "$FOLD=%IMAGE_FOLDER%"
IF NOT EXIST "%$FOLD%\%$ELECT$%" SET "ERROR=1"&&GOTO:PICK_ERROR
IF EXIST "%$FOLD%\%$ELECT$%" SET "$PICK=%$FOLD%\%$ELECT$%"
:PICK_ERROR
SET "PICK="&&IF DEFINED ERROR SET "$PICK="
EXIT /B
:FILE_LIST
SET "$FOLD="&&FOR %%a in (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) DO (IF DEFINED $ITEM%%a SET "$ITEM%%a=")
IF NOT DEFINED BLIST IF NOT DEFINED NLIST GOTO:FILE_ERROR
IF DEFINED BLIST SET "$MENU=BAS"&&SET "EXT=%BLIST%"
IF DEFINED NLIST SET "$MENU=NUM"&&SET "EXT=%NLIST%"
SET "$FOLD=%IMAGE_FOLDER%\*.%EXT%"&&SET "$LABEL=%IMAGE_FOLDER%"&&ECHO.
IF NOT EXIST "%$FOLD%" ECHO [%#@%EMPTY..%#$%]
IF EXIST "%$FOLD%" SET "$XNT="&&DIR "%$FOLD%" /A: /B /O:GN>$HZ&&FOR /F "TOKENS=*" %%a in ($HZ) DO (IF NOT "%%a"=="$HZ" CALL SET /A "$XNT+=1"&&CALL SET "$CLM$=%%a"&&CALL:FILE_LISTX)
ECHO.&&IF EXIST "$HZ" DEL /F "$HZ">NUL 2>&1
:FILE_ERROR
FOR %%a in (EXT BLIST NLIST CRICKETS NOECHO1 NOECHO2 MENU_INSERTA $MENU $FOLD $LABEL) DO (SET "%%a=")
EXIT /B
:FILE_LISTX
CALL SET "$ITEM%$XNT%=%$CLM$%"
IF "%$MENU%"=="NUM" ECHO [ %##%%$XNT%%#$% ]\[%#@%%$CLM$%%#$%]
IF "%$MENU%"=="BAS" ECHO [%#@%%$LABEL%%#$%]\[%#@%%$CLM$%%#$%]
EXIT /B
:IMAGEPROC_XLVL
IF "%TARGET_TYPE%"=="WIM" CALL:WIM_XLVL
IF "%TARGET_TYPE%"=="VHDX" IF "%VHDX_XLVL%"=="COMPACT" SET "VHDX_XLVL=DISABLED"&&EXIT /B
IF "%TARGET_TYPE%"=="VHDX" IF "%VHDX_XLVL%"=="DISABLED" SET "VHDX_XLVL=COMPACT"&&EXIT /B
EXIT /B
:IMAGEPROC_VSIZE
SET "PROMPT_SET=VHDX_SIZE"&&CALL:PAD_LINE&&ECHO VHDX size?&&CALL:PAD_LINE&&CALL:PAD_PREV&&CALL:PROMPT_SET
SET "SELECT=%VHDX_SIZE%"&&SET "CHECK=NUM"&&CALL:CHECK
IF DEFINED ERROR SET "VHDX_SIZE=25600"
EXIT /B
:IMAGEPROC_PROMPT
IF "%TARGET_TYPE%"=="WIM" CALL:PAD_LINE&&ECHO Name of WIM?&&CALL:PAD_LINE&&CALL:PAD_PREV&&SET "PROMPT_SET=WIM_TARGET"&&SET "PROMPT_ANY=1"&&CALL:PROMPT_SET
IF "%TARGET_TYPE%"=="WIM" IF DEFINED WIM_TARGET SET "WIM_TARGET=%WIM_TARGET%.wim"
IF "%TARGET_TYPE%"=="VHDX" CALL:PAD_LINE&&ECHO Name of VHDX?&&CALL:PAD_LINE&&CALL:PAD_PREV&&SET "PROMPT_SET=VHDX_TARGET"&&SET "PROMPT_ANY=1"&&CALL:PROMPT_SET
IF "%TARGET_TYPE%"=="VHDX" IF DEFINED VHDX_TARGET SET "VHDX_TARGET=%VHDX_TARGET%.vhdx"
EXIT /B
:IMAGEPROC_PICK
IF "%SOURCE_TYPE%"=="WIM" SET "PICK=WIM"&&CALL:FILE_PICK
IF "%SOURCE_TYPE%"=="VHDX" SET "PICK=VHDX"&&CALL:FILE_PICK
CALL SET "%SOURCE_TYPE%_SOURCE=%$ELECT$%"
EXIT /B
:IMAGEPROC_SLOT
SET /A "IMAGEPROC_SLOT+=1"
IF "%IMAGEPROC_SLOT%" GTR "3" SET "IMAGEPROC_SLOT=1"
IF "%IMAGEPROC_SLOT%"=="1" SET "SOURCE_TYPE=WIM"&&SET "TARGET_TYPE=VHDX"
IF "%IMAGEPROC_SLOT%"=="2" SET "SOURCE_TYPE=VHDX"&&SET "TARGET_TYPE=WIM"
IF "%IMAGEPROC_SLOT%"=="3" SET "SOURCE_TYPE=WIM"&&SET "TARGET_TYPE=WIM"
EXIT /B
:WIM_XLVL
SET /A "WIM_XXX+=1"
IF "%WIM_XXX%" GTR "3" SET "WIM_XXX=1"
IF "%WIM_XXX%"=="1" SET "WIM_XLVL=FAST"
IF "%WIM_XXX%"=="2" SET "WIM_XLVL=MAX"
IF "%WIM_XXX%"=="3" SET "WIM_XLVL=NONE"
EXIT /B
:WIM_INDEX
SET /A "WIM_INDEX+=1"
IF "%WIM_INDEX%"=="20" SET "WIM_INDEX=1"
CALL:WIM_INDEX_QUERY
EXIT /B
:WIM_INDEX_QUERY
SET "WIM_DESC="&&DISM /ENGLISH /Get-ImageInfo /ImageFile:"%IMAGE_FOLDER%\%WIM_SOURCE%" /Index:%WIM_INDEX% >"$DISM"
FOR /F "TOKENS=1-5 DELIMS=<> " %%a in ($DISM) DO (IF "%%a"=="Edition" SET "WIM_DESC=%%c")
FOR /F "TOKENS=1-5 DELIMS=<> " %%a in ($DISM) DO (IF "%%a"=="Languages" IF NOT "%%c"=="" SET "WIM_SOURCE=SELECT")
IF NOT DEFINED WIM_DESC SET "WIM_DESC=NULL"&&SET "WIM_INDEX=1"
IF EXIST "$DISM" DEL /Q /F "$DISM">NUL
EXIT /B
:SCRATCH_CREATE
IF NOT DEFINED SCRATCHDIR SET "SCRATCHDIR=%IMAGE_FOLDER%\Scratch"
IF EXIST "%SCRATCHDIR%" SET "SCRATCHDIRX=%SCRATCHDIR%"&&CALL:SCRATCH_DELETE
IF DEFINED SCRATCHDIRX SET "SCRATCHDIR=%SCRATCHDIRX%"
IF NOT EXIST "%SCRATCHDIR%" MD "%SCRATCHDIR%">NUL 2>&1
SET "SCRATCHDIRX="
EXIT /B
:SCRATCH_DELETE
IF NOT DEFINED SCRATCHDIR SET "SCRATCHDIR=%IMAGE_FOLDER%\Scratch"
IF EXIST "%SCRATCHDIR%" DISM /cleanup-MountPoints>NUL 2>&1
IF EXIST "%SCRATCHDIR%" ATTRIB -R -S -H "%SCRATCHDIR%" /S /D /L>NUL 2>&1
IF EXIST "%SCRATCHDIR%" RD /S /Q "%SCRATCHDIR%">NUL 2>&1
SET "SCRATCHDIR="
EXIT /B
:VDISK_CREATE
IF NOT DEFINED VDISK EXIT /B
CALL:VDISK_DETACH>NUL 2>&1
IF NOT DEFINED VHDX_MB SET "VHDX_MB=25600"
IF EXIST "%VDISK%" DEL /Q /F "%VDISK%">NUL 2>&1
(ECHO.create vdisk file="%VDISK%" maximum=%VHDX_MB% type=expandable&&ECHO.Select vdisk file="%VDISK%"&&ECHO.Attach vdisk&&ECHO.create partition primary&&ECHO.select partition 1&&ECHO.format fs=ntfs quick&&ECHO.Assign letter=V noerr&&ECHO.Exit)>"$DSK"&&DISKPART /s "$DSK">NUL 2>&1
SET "VHDX_MB="&&DEL /F "$DSK">NUL 2>&1
EXIT /B
:VDISK_ATTACH
SET "VDISK_SYS="&&CALL:VDISK_DETACH>NUL 2>&1
(ECHO.Select vdisk file="%VDISK%"&&ECHO.Attach vdisk&&ECHO.select partition 1&&ECHO.Assign letter=V noerr&&ECHO.Exit)>"$DSK"&&DISKPART /s "$DSK">NUL 2>&1
IF EXIST "V:\WINDOWS" SET "VDISK_SYS=1"
DEL /F "$DSK">NUL 2>&1
EXIT /B
:VDISK_DETACH
(ECHO.Select vdisk file="%VDISK%"&&ECHO.Detach vdisk&&ECHO.Exit)>"$DSK"&&DISKPART /s "$DSK">NUL 2>&1
IF EXIST "V:\" CALL:VDISK_BRUTE
DEL /F "$DSK">NUL 2>&1
EXIT /B
:VDISK_BRUTE
(ECHO.List Volume&&ECHO.Exit)>"$DSK1"&&DISKPART /s "$DSK1">"$DSK2"
SET "DISK_TMP="&&FOR /F "TOKENS=1-9 DELIMS= " %%a IN ($DSK2) DO (IF "%%c"=="V" CALL SET "DISK_TMP=%%b")
(ECHO.Select Volume %DISK_TMP%&&ECHO.Detail Volume&&ECHO.Exit)>"$DSK1"&&DISKPART /s "$DSK1">"$DSK2"
SET "DISK_TMP="&&FOR /F "TOKENS=1-9 DELIMS= " %%a IN ($DSK2) DO (
IF "%%a"=="Disk" IF NOT "%%b"=="###" SET "DISK_TMP=%%b"
IF "%%a"=="*" IF "%%b"=="Disk" SET "DISK_TMP=%%c")
(ECHO.List Vdisk&&ECHO.Exit)>"$DSK1"&&DISKPART /s "$DSK1">"$DSK2"
SET "VDISK_TMP="&&FOR /F "TOKENS=1-9* DELIMS= " %%a IN ($DSK2) DO (IF "%%a"=="VDisk" IF "%%d"=="%DISK_TMP%" IF EXIST "%%i" SET "VDISK_TMP=%%i")
CALL:PAD_LINE&&CALL ECHO Detaching [%VDISK_TMP%]&&CALL:PAD_LINE
(ECHO.Select vdisk file="%VDISK_TMP%"&&ECHO.Detach vdisk&&ECHO.Exit)>"$DSK1"&&DISKPART /s "$DSK1" >NUL 2>&1
DEL /F "$DSK*">NUL 2>&1
EXIT /B