-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDE_ModCleaner.bat
323 lines (308 loc) · 6.67 KB
/
DE_ModCleaner.bat
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
@ECHO OFF
CLS
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
SET "$SCRIPTVERSION=v1.7"
SET "$TITLEHEADER=DE ModCleaner %$SCRIPTVERSION%-BATCH"
REM | Check for command-line parameters
:CHECK_PARAMS
REM | Check for "help" argument
IF /I "x%~1" EQU "x--help" (
CALL :RUN_HELP
EXIT /B
)
IF /I "x%~1" EQU "x-h" (
CALL :RUN_HELP
EXIT /B
)
IF /I "x%~1" EQU "x-?" (
CALL :RUN_HELP
EXIT /B
)
IF /I "x%~1" EQU "x/?" (
CALL :RUN_HELP
EXIT /B
)
REM | Standard arguments
IF /I "x%~1" EQU "x-q" (
SET "$QUIETMODE=Y"
SHIFT
GOTO CHECK_PARAMS
)
IF /I "x%~1" EQU "x--quiet" (
SET "$QUIETMODE=Y"
SHIFT
GOTO CHECK_PARAMS
)
IF /I "x%~1" EQU "x--dry-run" (
SET "$DRYRUN=Y"
SHIFT
GOTO CHECK_PARAMS
)
REM | Aliases and other variables
SET "$ECHO_Q=IF NOT DEFINED $QUIETMODE ECHO"
SET "$ORIGDIR=%CD%"
REM | Set and create temp dirs/files
:SET_TEMPDIR
SET "$TEMPDIR=%TEMP%\DE_ModCleaner_%RANDOM:~-1%%RANDOM:~-1%%RANDOM:~-1%%RANDOM:~-1%%RANDOM:~-1%"
IF EXIST "%$TEMPDIR%" GOTO SET_TEMPDIR
SET "$LIST=%$TEMPDIR%\temp.txt"
MKDIR "%$TEMPDIR%"
REM | Display script banner
IF NOT DEFINED $QUIETMODE CALL :BANNER
REM | Tool check
%$ECHO_Q% Checking for required tools...
%$ECHO_Q%.
FOR %%A IN (FIND;FINDSTR;POWERSHELL;XCOPY) DO (CALL :CHECK_FOR_TOOL "%%~A" || GOTO END_SCRIPT)
FOR /F "tokens=*" %%A IN ('POWERSHELL -Command "[system.console]::title"') DO SET "$ORIGTITLE=%%~A"
TITLE %$TITLEHEADER%
REM | Generate and parse sorted resource-load list
CALL :GENERATE_ORDERFILE >"%$TEMPDIR%\order.txt"
ECHO. >"%$LIST%"
FOR /F "tokens=*" %%A IN (%$TEMPDIR%\order.txt) DO (
IF "x%%~A" NEQ "x=" (
IF EXIST "%$ORIGDIR%\%%~nA" (
SET "$FOUND=Y"
CD /D "%$ORIGDIR%\%%~nA" >NUL
%$ECHO_Q% == %%~A ==
TITLE %$TITLEHEADER% ^| %%~A ^| Generating file list...
XCOPY /L /S /Y /R ".\*.*" "%$TEMPDIR%" | FIND ".\" >"%$TEMPDIR%\filelist.txt"
FOR /F "tokens=*" %%B IN (%$TEMPDIR%\filelist.txt) DO (
SET "$SKIPCHECK="
FOR %%C IN (json) DO IF /I "x%%~xB" EQU "x.%%~C" SET "$SKIPCHECK=Y"
IF NOT DEFINED $SKIPCHECK (CALL :TEST_FOR_DUPE "%%~B" "%%~A" || GOTO END_SCRIPT)
)
CD /D "%$ORIGDIR%" >NUL
%$ECHO_Q%.
)
) ELSE (
ECHO. >"%$LIST%"
)
)
REM | Clean any empty directories after processing
IF "x%$FOUND%" EQU "xY" (
TITLE %$TITLEHEADER% ^| Cleaning empty directories...
%$ECHO_Q% Cleaning empty directories...
IF NOT DEFINED $DRYRUN FOR /F "tokens=*" %%A IN ('DIR /S /B /AD ^| SORT /R') DO RMDIR /Q "%%~A" 2>NUL
%$ECHO_Q%.
)
TITLE %$TITLEHEADER% ^| Search completed!
%$ECHO_Q% Search completed!
GOTO END_SCRIPT
REM | Check temp.txt for a line containing the given string
:TEST_FOR_DUPE
TITLE %$TITLEHEADER% ^| %~2 ^| %~1
FINDSTR /X /C:"%~1" "%$LIST%" >NUL
IF "x%ERRORLEVEL%" EQU "x0" (
%$ECHO_Q% * Dupe found: %~1
IF NOT DEFINED $DRYRUN (
DEL /Q "%~1"
IF EXIST "%~1" (
ECHO !! CRITICAL: File removal failed!
EXIT /B 1
)
)
) ELSE (
ECHO %~1>>"%$LIST%"
)
EXIT /B 0
REM | Check for given tool; exit if fail
:CHECK_FOR_TOOL
WHERE "%~1" >NUL 2>&1
IF "x%ERRORLEVEL%" EQU "x0" EXIT /B 0
ECHO !! CRITICAL: %~1 not found!
EXIT /B 1
REM | Help prompt
:RUN_HELP
CALL :BANNER
ECHO Usage:
ECHO.
ECHO DE_ModCleaner [--help ^| -h ^| -? ^| /?] [-q ^| --quiet] [--dry-run]
ECHO.
ECHO Options:
ECHO.
ECHO --help ^| -h ^| -? ^| /?
ECHO Runs this help prompt and exits.
ECHO.
ECHO -q ^| --quiet
ECHO Suppresses script output and prompts (not including critical errors).
ECHO.
ECHO --dry-run
ECHO Simulates how the script would run without deleting any files/directories.
EXIT /B
REM | The priority order list; sets are separated with '='
:GENERATE_ORDERFILE
ECHO gameresources_patch3
ECHO gameresources_patch1
ECHO gameresources_patch2
ECHO gameresources
ECHO =
::ECHO meta
::ECHO =
ECHO warehouse_patch1
ECHO warehouse
ECHO =
ECHO hub_patch2
ECHO hub
ECHO hub_patch1
ECHO =
ECHO e1m1_intro_patch3
ECHO e1m1_intro_patch1
ECHO e1m1_intro_patch2
ECHO e1m1_intro
ECHO =
ECHO e1m2_battle_patch3
ECHO e1m2_battle_patch2
ECHO e1m2_battle_patch1
ECHO e1m2_battle
ECHO =
ECHO e1m3_cult_patch3
ECHO e1m3_cult_patch2
ECHO e1m3_cult_patch1
ECHO e1m3_cult
ECHO =
ECHO e1m4_boss_patch2
ECHO e1m4_boss_patch1
ECHO e1m4_boss
ECHO =
ECHO e2m1_nest_patch2
ECHO e2m1_nest_patch1
ECHO e2m1_nest
ECHO =
ECHO e2m2_base_patch3
ECHO e2m2_base_patch1
ECHO e2m2_base_patch2
ECHO e2m2_base
ECHO =
ECHO e2m3_core_patch2
ECHO e2m3_core_patch3
ECHO e2m3_core_patch1
ECHO e2m3_core
ECHO =
ECHO e2m4_boss_patch2
ECHO e2m4_boss_patch1
ECHO e2m4_boss
ECHO =
ECHO e3m1_slayer_patch2
ECHO e3m1_slayer_patch3
ECHO e3m1_slayer_patch1
ECHO e3m1_slayer
ECHO =
ECHO e3m2_hell_patch2
ECHO e3m2_hell_patch1
ECHO e3m2_hell
ECHO =
ECHO e3m2_hell_b_patch2
ECHO e3m2_hell_b_patch1
ECHO e3m2_hell_b
ECHO =
ECHO e3m3_maykr_patch3
ECHO e3m3_maykr_patch1
ECHO e3m3_maykr_patch2
ECHO e3m3_maykr
ECHO =
ECHO e3m4_boss_patch3
ECHO e3m4_boss_patch2
ECHO e3m4_boss_patch1
ECHO e3m4_boss
ECHO =
ECHO dlc_hub_patch1
ECHO dlc_hub
ECHO =
ECHO e4m1_rig_patch2
ECHO e4m1_rig_patch1
ECHO e4m1_rig
ECHO =
ECHO e4m2_swamp_patch2
ECHO e4m2_swamp_patch1
ECHO e4m2_swamp
ECHO =
ECHO e4m3_mcity_patch2
ECHO e4m3_mcity_patch1
ECHO e4m3_mcity
ECHO =
ECHO e5m1_spear_patch1
ECHO e5m1_spear_patch2
ECHO e5m1_spear
ECHO =
ECHO e5m2_earth_patch2
ECHO e5m2_earth_patch1
ECHO e5m2_earth
ECHO =
ECHO e5m3_hell_patch1
ECHO e5m3_hell_patch2
ECHO e5m3_hell
ECHO =
ECHO e5m4_boss_patch1
ECHO e5m4_boss
ECHO =
ECHO e6m1_cult_horde_patch1
ECHO e6m1_cult_horde
ECHO =
ECHO e6m2_earth_horde_patch1
ECHO e6m2_earth_horde
ECHO =
ECHO e6m3_mcity_horde_patch1
ECHO e6m3_mcity_horde
ECHO =
ECHO pvp_bronco_patch1
ECHO pvp_bronco
ECHO =
ECHO pvp_darkmetal_patch1
ECHO pvp_darkmetal
ECHO =
ECHO pvp_deathvalley_patch1
ECHO pvp_deathvalley
ECHO =
ECHO pvp_inferno_patch1
ECHO pvp_inferno
ECHO =
ECHO pvp_laser_patch1
ECHO pvp_laser
ECHO =
ECHO pvp_shrapnel_patch1
ECHO pvp_shrapnel
ECHO =
ECHO pvp_sideswipe_patch1
ECHO pvp_sideswipe
ECHO =
ECHO pvp_thunder_patch1
ECHO pvp_thunder
ECHO =
ECHO pvp_zap_patch1
ECHO pvp_zap
ECHO =
::ECHO tutorial_sp
::ECHO =
::ECHO tutorial_demons
::ECHO =
ECHO tutorial_pvp_laser_patch1
ECHO tutorial_pvp_laser
ECHO =
ECHO shell_patch1
ECHO shell
EXIT /B
REM | Extra comment to fill space because Batch is fucking weird
REM | Da banner
:BANNER
ECHO.
ECHO #############################
ECHO # #
ECHO # DE ModCleaner #
ECHO # %$SCRIPTVERSION% #
ECHO # #
ECHO # by #
ECHO # Wryyyong#2935 #
ECHO # #
ECHO #############################
ECHO.
EXIT /B
REM | Cleanup and exiting
:END_SCRIPT
RMDIR /S /Q "%$TEMPDIR%"
CD /D "%$ORIGDIR%"
IF NOT DEFINED $QUIETMODE (
ECHO.
ECHO Press any key to exit.
PAUSE >NUL
)
IF DEFINED $ORIGTITLE TITLE %$ORIGTITLE%