-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanupMess.bat
435 lines (395 loc) · 13 KB
/
CleanupMess.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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
@echo off
setlocal EnableDelayedExpansion
if "%1" EQU "/?" call :PrintHelp & exit /b 0
call :InitGlobals
call :ParseArgs %*
if errorlevel 1 exit /b 0
call :AdminCheck
:: Cleanup operations
if not defined skipnvidia (
echo Clearing nVidia installer stuff...
call :DelDir C:\NVIDIA
call :DelDirs C:\Program Files\NVIDIA Corporation\Installer2\*
call :DelFiles C:\ProgramData\NVIDIA Corporation\NetService\*.exe
)
if not defined skipmsi (
echo Clearing MSI installer temporary files...
call :DelDir C:\MSI\TestDownload
)
for /d %%U in ("C:\Users\*") do (
echo Clearing %%~nU's user directory:
set appdata=%%U\AppData\Roaming
set localappdata=%%U\AppData\Local
set locallowappdata=%%U\AppData\LocalLow
if not defined skipopera (
echo Clearing Opera caches...
for /d %%D in ("!localappdata!\Opera Software\*") do (
call :DelDir %%~fD\Cache
)
for /d %%D in ("!appdata!\Opera Software\*") do (
call :DelDir %%~fD\Code Cache
call :DelDir %%~fD\Crash Reports\reports
call :DelDir %%~fD\GPUCache
call :DelDir %%~fD\GrShaderCache
call :DelDir %%~fD\IndexedDB
call :DelDir %%~fD\Local Storage
call :DelDir %%~fD\Service Worker\CacheStorage
call :DelDir %%~fD\Service Worker\ScriptCache
)
)
if not defined skipchrome (
echo Clearing Chrome caches...
call :DelDir !localappdata!\Google\Chrome\User Data\Default\Cache
call :DelDir !localappdata!\Google\Chrome\User Data\Default\Code Cache
call :DelDir !localappdata!\Google\Chrome\User Data\Default\GPUCache
call :DelDir !localappdata!\Google\Chrome\User Data\GrShaderCache
)
if not defined skipinetexpl (
echo Clearing Internet Explorer caches...
call :DelContents !localappdata!\Microsoft\Windows\Temporary Internet Files
call :DelContents !localappdata!\Microsoft\Windows\INetCache
)
if not defined skipthunderbird (
echo Clearing Thunderbird cache...
for /d %%D in ("!localappdata!\Thunderbird\Profiles\*.default") do (
call :DelDir %%~fD\Cache
)
)
if not defined skipdiscord (
echo Clearing Discord's caches...
call :DelDir !appdata!\discord\Cache
call :DelDir !appdata!\discord\Code Cache
call :DelFiles !appdata!\discord\*.tmp
call :DelFiles !appdata!\discord\*.log
)
if not defined skipaiomessenger (
echo Clearing All-in-One Messenger caches...
for /d %%D in ("!appdata!\All-in-One Messenger\Partitions\*") do (
call :DelDir %%~fD\Cache
call :DelDir %%~fD\Code Cache
call :DelDir %%~fD\GPUCache
call :DelDir %%~fD\Service Worker\CacheStorage
call :DelDir %%~fD\Service Worker\ScriptCache
)
)
if not defined skipsteam (
echo Clearing Steam HTML cache...
call :DelDir !localappdata!\Steam\htmlcache
)
if not defined skipgdrive (
echo Clearing Google Drive FS Logs...
call :DelDir !localappdata!\Google\DriveFS\Logs
)
if not defined skipgearth (
echo Clearing Google Earth cache...
call :DelDir !locallowappdata!\Google\GoogleEarth\Cache\unified_cache_leveldb_leveldb2
)
if not defined skippsp (
echo Clearing Paint Shop Pro caches...
call :DelDir !appdata!\Corel\Messages
call :DelDir !appdata!\Corel\PaintShop Photo Pro\Cache
if defined pspThumbs (
call :DelDir !localappdata!\Corel PaintShop Pro\2021\Thumbs
)
)
if not defined skipvscode (
echo Clearing Visual Studio Code's caches...
call :DelDir !appdata!\Code\Cache
call :DelDir !appdata!\Code\CachedData
call :DelDir !appdata!\Code\Service Worker\CacheStorage
call :DelDir !appdata!\Code\Service Worker\ScriptCache
)
if not defined skipas (
echo Clearing Android Studio crash logs
call :DelFiles %%~fU\java_error_in_studio64.hprof
if not defined androidUser (
echo Clearing Android Studio Logs and Cache...
call :DelDir %%~fU\.android\breakpad
call :DelDir %%~fU\.android\cache
)
if not defined androidGradle (
echo Clearing Android Studio Gradle Cache and Temp...
call :DelDir %%~fU\.gradle\.tmp
call :DelDir %%~fU\.gradle\caches
)
)
if not defined skipqbittorrent (
echo Clearing qBittorrent Logs...
call :DelDir !localappdata!\qBittorrent\logs
)
if not defined skiptrakts if exist "!appdata!\trakt-scrobbler\trakt_scrobbler.log" (
echo Clearing Trakt Scrobbler Logs...
for /f "tokens=*" %%T in ('where trakts 2^>NUL') do set "traktsdir=%%~dpT\"
if not exist "!traktsdir!trakts.exe" if defined PIPX_BIN_DIR set "traktsdir=%PIPX_BIN_DIR%\"
if exist "!traktsdir!trakts.exe" (
if not defined mock ( "!traktsdir!trakts.exe" stop >NUL 2>NUL )
if defined outfile ( echo "!traktsdir!trakts.exe" stop ^>NUL 2^>NUL 1>>"%outfile%" )
)
call :DelFiles !appdata!\trakt-scrobbler\trakt_scrobbler.log*
if exist "!traktsdir!trakts.exe" (
if not defined mock (
pushd "!traktsdir!"
"!traktsdir!trakts.exe" start >NUL 2>NUL
popd
)
if defined outfile (
echo pushd "!traktsdir!" 1>>"%outfile%"
echo "!traktsdir!trakts.exe" start ^>NUL 2^>NUL 1>>"%outfile%"
echo popd
)
)
)
if not defined skiptemp (
echo Clearing the temp folder...
call :DelContents %%~fU\AppData\Local\Temp
)
)
if not defined skipas (
if defined androidUser (
echo Clearing Android Studio Logs and Cache...
call :DelDir !androidUser!\breakpad
call :DelDir !androidUser!\cache
)
if defined androidGradle (
echo Clearing Android Studio Gradle Cache and Temp...
call :DelDir !androidGradle!\.tmp
call :DelDir !androidGradle!\caches
)
)
if not defined displayfusion (
echo Clearing the DisplayFusion setup cache...
call :DelFiles C:\ProgramData\Binary Fortress Software\DisplayFusion\*Setup*
)
if not defined skiptemp (
echo Clearing global temp folders...
call :DelContents C:\Windows\Temp
)
if not defined skipwinupd (
echo Clearing the Windows Update download cache...
call :DelContents C:\Windows\SoftwareDistribution\Download
echo Clearing the previous version of Windows...
for /d %%D in ("C:\Windows.old*") do (
if not defined mock (
takeown /F "%%~fD" /R /A /D Y >NUL 2>NUL
icacls "%%~fD" /grant:r *S-1-5-32-544:F /T /L /Q >NUL 2>NUL
)
if defined outfile (
echo takeown /F "%%~fD" /R /A /D Y ^>NUL 2^>NUL 1>>"%outfile%"
echo icacls "%%~fD" /grant:r *S-1-5-32-544:F /T /L /Q ^>NUL 2^>NUL 1>>"%outfile%"
)
call :DelDir %%~fD
)
)
if not defined perflogs (
echo Clearing Windows performance logs...
call :DelDir C:\PerfLogs
)
if not defined skipprefetch (
echo Clearing the Windows Prefetch
call :DelFiles C:\Windows\Prefetch\*
)
if not defined skiprecyclebin (
:: Recycle bin cleanup
set/p= Emptying the recycle bin: <NUL
for %%C in (%allLetters%) do (
set recyclebin=%%C:\$RECYCLE.BIN
if exist !recyclebin! (
set/p= %%C: <NUL
call :DelDir !recyclebin!
)
)
echo.
)
if not defined skipcleanmgr (
:: Cleanup manager autoclean
set/p= Running the cleanup manager: <NUL
for %%C in (%allLetters%) do (
if exist %%C:\ (
set/p= %%C: <NUL
if not defined mock (
cleanmgr /d %%C /autoclean
)
if defined outfile (
echo cleanmgr /d %%C /autoclean 1>>"%outfile%"
)
)
)
echo.
)
if not defined skipdism (
echo Start running the Windows Component Cleanup task...
if not defined mock (
Dism.exe /online /Cleanup-Image /StartComponentCleanup %dismSwitch%
)
if defined outfile (
echo Dism.exe /online /Cleanup-Image /StartComponentCleanup %dismSwitch% 1>>"%outfile%"
)
)
exit /b 0
:: End of cleanup code; cleanup code follows
:: New cleanup addition workflow reminder:
:: - Add documentation to :PrintHelp
:: - Add new skip name to :InitGlobals
:: - Add new command line arguments to :ParseArgs if any
:PrintHelp
:: Option, starting with / or -
echo This is the software mess cleaner script for Windows.
echo Usage: CleanupMess ["options"] outfile
echo Options (separated by space):
echo /h: Displays this message.
echo /m: Doesn't do anything, just prints commands to stderr.
echo "CleanupMess /m 2>commands.bat" writes the commands to commands.bat.
echo /s stepnames: Skips cleaning the listed steps.
echo Stepnames is a colon (:) separated list, e.g. recyclebin:dism
echo For skippable cleanup operation names, see the below list.
echo.
echo /ag "dir": The gradle directory (default: %userprofile%\.gradle)
echo /au "dir": The android user directory (default: %userprofile%\.android)
echo /d: Strong Windows component cleanup, uninstallation won't be available.
echo /pspt: Cleans up Paint Shop Pro thumbnails. These get auto-regenerated.
echo.
echo Positional arguments:
echo outfile: Writes all commands to the given file. See also: /m.
echo.
echo Supported cleanup operations (skip if unwanted steps with /s):
echo - All-in-one messenger chat app (/s aiomessenger)
echo - Android Studio integrated developer environment (/s as)
echo - Chrome web browser caches (/s chrome)
echo - Discord chat app (/s discord)
echo - DisplayFusion Windows customization app (/s displayfusion)
echo - Google Drive Desktop client (/s gdrive)
echo - Google Earth client (/s gearth)
echo - Internet Explore and Edge web browser caches (/s inetexpl)
echo - MSI temporary files (/s msi)
echo - nVidia video driver installation temporaries (/s nvidia)
echo - Opera web browser caches (/s opera)
echo - Paint Shop Pro graphics editor (/s psp)
echo - QBittorrent peer-to-peer file sharing client (/s qbittorrent)
echo - Recycle bin (/s recyclebin)
echo - Steam game client (/s steam)
echo - Temporary files (/s temp)
echo - Thunderbird e-mail client (/s thunderbird)
echo - Trakt Scrobbler (/s trakts)
echo - Visual Studio Code (/s vscode)
echo - Windows cleanup manager's autoclean (/s cleanmgr)
echo - Windows component (app installation cache) (/s dism)
echo - Windows performance logs (/s perflogs)
echo - Windows prefetch (app preloads) (/s prefetch)
echo - Windows Update backups and download cache (/s winupd)
exit /b 0
:InitGlobals
:: Skippable cleanups
set skippables=nvidia:msi:opera:chrome:inetexpl:thunderbird:discord:aiomessenger:steam:gdrive:gearth:as:psp:vscode:qbittorrent:trakts:temp:winupd:perflogs:prefetch:recyclebin:cleanmgr:dism:displayfusion
:: Helper data to enumerate drives
set allLetters=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
:: DISM switch to clean up thoroughly; prevents component uninstallation
set dismresetarg=/ResetBase
exit /b 0
:ParseArgs
:: Command line argument handling
for %%A in (%*) do (
set arg=%%~A
if defined switchArg (
:: Option's arguments
if !switchArg! EQU skips (
for %%S in ("!arg::=" "!") do (
set "supportedOpt="
for %%T in ("%skippables::=" "%") do (
if /i %%T EQU %%S ( set supportedOpt=y )
)
if not defined supportedOpt (
echo Unsupported /s option: %%~S >&2
exit /b 4
)
set skip%%~S=y
)
) else if !switchArg! EQU androidUser (
set androidUser=!arg!
) else if !switchArg! EQU androidGradle (
set androidGradle=!arg!
)
set "switchArg="
) else (
set arg1=!arg:~0,1!
set optChars=/-
for /f %%B in ("!arg1!") do if "!optChars:%%B=!" NEQ "!optChars!" (
:: Option switches
if /i "!arg:~1!" EQU "h" (
call :PrintHelp
exit /b 1
) else if /i "!arg:~1!" EQU "m" (
set mock=y
) else if /i "!arg:~1!" EQU "d" (
set "dismSwitch=!dismSwitch! %dismresetarg%"
) else if /i "!arg:~1!" EQU "pspt" (
set pspThumbs=y
) else if /i "!arg:~1!" EQU "s" (
set switchArg=skips
) else if /i "!arg:~1!" EQU "au" (
set switchArg=androidUser
) else if /i "!arg:~1!" EQU "ag" (
set switchArg=androidGradle
) else (
echo Unknown switch: !arg!. >&2
echo To display the help, run CleanupMess /h >&2
exit /b 2
)
) else (
:: Positional arguments
if not defined outfile (
set outfile=!arg!
del /q "!outfile!" 2>NUL
) else (
echo Too many positional arguments: !arg! >&2
exit /b 3
)
)
)
)
:: Default values
if defined mock if not defined outfile (
set "outfile=&2"
)
exit /b 0
:AdminCheck
cacls.exe "%SYSTEMROOT%\System32\config\system" 1>NUL 2>NUL
if errorlevel 1 (
echo WARNING: Missing administrator privileges, some cleanups won't work.
echo Run this script as administrator to be able to do everything.
echo.
pause
)
exit /b 0
:DelFiles
if not defined mock (
del /f /s /q "%*" 1>NUL 2>NUL
del /f /s /q /a:h "%*" 1>NUL 2>NUL
)
if defined outfile (
echo del /f /s /q "%*" 1^>NUL 2^>NUL 1>>"%outfile%"
echo del /f /s /q /a:h "%*" 1^>NUL 2^>NUL 1>>"%outfile%"
)
exit /b 0
:DelDir
if not defined mock (
rmdir /s /q "%*" 2>NUL
)
if defined outfile (
echo rmdir /s /q "%*" 2^>NUL 1>>"%outfile%"
)
exit /b 0
:DelDirs
call :GetFileDir "%*"
:: Finds hidden directories as well
for /f "tokens=* delims=" %%D in ('dir /b /ad "%*" 2^>NUL') do (
call :DelDir %dir%%%D
)
exit /b 0
:DelContents
call :DelFiles %*\*
call :DelDirs %*\*
exit /b 0
:: Trims the "file" off the path into %dir%
:GetFileDir
set dir=%~dp1
exit /b 0