-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesktopLayoutManager-en.bat
346 lines (288 loc) · 8.92 KB
/
DesktopLayoutManager-en.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
@echo off
@rem Save or restore the layout of the desktop icons
:::::::::::::::::::::::::::::::::::::::::::::::::
:: Main processing from here ::
:::::::::::::::::::::::::::::::::::::::::::::::::
@rem Reopen with administrative privileges
openfiles > nul 2>&1
if not %ERRORLEVEL%==0 (
powershell start-process \"%~f0\" -verb runas > nul
exit /b
)
:::::::::::::::::::::::::::::::::::::::::::::::::
:: [START] Initialization process ::
:::::::::::::::::::::::::::::::::::::::::::::::::
@rem Window Title
title DesktopLayoutManager Version 1.0
@rem Whether to display the startup screen
set showWelcomeScreen=1
@rem Whether to display ASCII art in Explorer
set showExplorerAsciiArt=1
@rem Name of the folder where Desktop Layout is saved
set savedDirName=SavedDesktopLayout
if not %showWelcomeScreen%==0 (
call :welcomeScreen
)
cd %~dp0
@rem temporary file path
set tmpFilePath=%TMP%\DesktopLayoutManagerTmp
if not exist %tmpFilePath% echo: > %tmpFilePath%
:::::::::::::::::::::::::::::::::::::::::::::::::
:: [END] Initialization process ::
:::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
echo Please select an item and enter it.
echo 1: Save 2: Restore
set /P num=""
if [%num%]==[] (
cls
echo Invalid input.
echo Press Enter to exit.
pause > nul
exit /b 1
)
@rem Save data to a file with current time
if %num%==1 (
@rem Create a folder if there is no folder
If not exist %savedDirName% mkdir %savedDirName%
cd %savedDirName%
@rem Current date and time
set year=%date:~0,4%
set month=%date:~5,2%
set day=%date:~8,2%
set time2=%time::=%
set time2=!time2:.=!
set time2=!time2: =0!
set time2=!time2:~-0,-2!
set time2=!time2:~0!
set date2=!year!!month!!day!!time2!
cls
echo Save desktop layouts...
reg save HKCU\SOFTWARE\Microsoft\Windows\Shell\Bags DesktopLayout!date2!.reg
echo Press Enter to exit.
) else if %num%==2 (
call :restore
) else (
cls
echo Invalid input.
echo Press Enter to exit.
)
endlocal
:::::::::::::::::::::::::::::::::::::::::::::::::
:: [START] Termination processes ::
:::::::::::::::::::::::::::::::::::::::::::::::::
@rem Delete temporary file
del %tmpFilePath%
pause > nul
exit /b
:::::::::::::::::::::::::::::::::::::::::::::::::
:: [END] Termination processes ::
:::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::
:: [START] Subroutines ::
:::::::::::::::::::::::::::::::::::::::::::::::::
:restore
@rem If there is a backup folder, select from it; if not, have the user enter it directly.
If exist %savedDirName% (
cd %savedDirName%
call :selectSavedFile
) else (
call :inputFilePath
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Select a saved file
:selectSavedFile
call :showSavedFiles
set /P selectFile=""
if [%selectFile%]==[] (
cls
echo Invalid input.
echo Press Enter to exit.
exit /b 1
)
@rem Stores data for the entered number
for /f "usebackq delims=" %%i in (`findstr "." %tmpFilePath% ^| findstr "^%selectFile%:"`) do set result=%%i
if [%result%]==[] (
cls
echo Invalid input.
echo Press Enter to exit.
exit /b 1
)
call :correctInput %result:~-31%
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Show saved files
:showSavedFiles
cls
@rem Save list of backup files to temporary file
dir /b /o-d | findstr "^.*DesktopLayout[0-9]*\.reg" | findstr /N "." > %tmpFilePath%
echo Select the files you wish to restore. (in order of newest to oldest)
@rem Load list
@rem Cut out string and display date
setlocal enabledelayedexpansion
for /f %%i in (%tmpFilePath%) do (
set i=%%i
echo %%i ^(!i:~-18,4!^/!i:~-14,2!^/!i:~-12,2! !i:~-10,2!^:!i:~-8,2!^:!i:~-6,2!^)
)
endlocal
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::
:inputFilePath
cls
echo The %savedDirName% folder is missing.
echo Please enter the backup file.
set /P file=""
if [%file%]==[] (
cls
echo Invalid input.
echo Press Enter to exit.
exit /b 1
) else (
call :correctInput %file%
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Check if the file exists
:correctInput
if exist "%~1" (
call :fileCheck "%~1"
) else (
cls
echo The entered file does not exist.
echo Press Enter to exit.
exit /b 1
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Check for correct file
:fileCheck
echo %~1 | findstr "^.*DesktopLayout[0-9]*\.reg" > nul
if %ERRORLEVEL%==0 (
call :allCorrect "%~1"
) else (
cls
echo The entered file is incorrect.
echo Press Enter to exit.
exit /b 1
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Passed all file checks
:allCorrect
cls
if not %showExplorerAsciiArt%==0 (
call :explorerAsciiArt
)
echo Explorer needs to be restarted.
echo This may result in loss of data, etc. during the move/copy.
echo Do you want to continue? [Y/n]
set yesOrNo=
set /P yesOrNo=""
if [%yesOrNo%]==[] (
call :runRestore "%~1"
) else (
call :checkYesOrNo "%~1"
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Check non-null variable YesOrNo
:checkYesOrNo
if %yesOrNo:y=y%==y (
set isYes=1
) else if %yesOrNo:yes=y%==y (
set isYes=1
) else if %yesOrNo:n=n%==n (
set isYes=0
) else if %yesOrNo:no=n%==n (
set isYes=0
) else (
goto :allCorrect "%~1"
)
if %isYes%==1 (
call :runRestore "%~1"
) else (
cls
echo Restore has been canceled.
echo Press Enter to exit.
exit /b 1
)
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
@rem Run restore
:runRestore
cls
echo Restoring desktop layout...
taskkill /F /IM explorer.exe > nul
reg restore HKCU\SOFTWARE\Microsoft\Windows\Shell\Bags "%~1"
start explorer.exe > nul
echo Press Enter to exit.
exit /b 0
::::::::::::::::::::::::::::::::::::::::::::::::::
:welcomeScreen
cls
echo [1m
echo DesktopLayoutManager is running...
echo:
echo -+********************************************+-
echo %%%%:............................................:%%%%
echo @+ #@########################################%%%% =@
echo @+ ## *%% =@
echo @+ ## *%% =@
echo @+ ## [31m ooooooooo [33mooooo [32moooo oooo [0m[1m *%% =@
echo @+ ## [31m 888 88o[33m 888 [32m 8888o 888 [0m[1m *%% =@
echo @+ ## [31m 888 888[33m 888 [32m 88 888o8 88 [0m[1m *%% =@
echo @+ ## [31m 888 888[33m 888 o [32m 88 888 88 [0m[1m *%% =@
echo @+ ## [31m o888ooo88 [33mo888ooooo88 [32mo88o 8 o88o [0m[1m *%% =@
echo @+ ## [31m esktop[33m ayout [32m anager[0m[1m *%% =@
echo @+ ## *%% =@
echo @+ ## *%% =@
echo @+ #%%----------------------------------------*%% =@
echo @+ -==========================================- =@
echo @+ :##: =@
echo @* .##: +@
echo +@+============================================+@+
echo :-------------------@*--+@=------------------:
echo .@+ =@:
echo :******************:
echo [0m
echo:
@rem Disable cursor blinking
set /P tmpVar=[?25l<nul
@rem Screen feed
for /L %%z in (1,1,28) do (
ping -n 1 localhost>nul
echo:
)
@rem Move cursor up
set /P tmpVar=[2;0f<nul
@rem Enable blinking cursor
set /P tmpVar=[?25h<nul
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::
:explorerAsciiArt
echo [1m
echo [33m -+++++++++++++++=:
echo [33m*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#-
echo [33m#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#-::::::::::::::::::::.
echo [33m#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#=::::::::::::::::::::::::
echo [93m:-----------------::::::::::::::::::::::::::
echo [93m::::::::::::::::::::::::::::::::::::::::::::
echo [93m::::::::::::::::::::::::::::::::::::::::::::
echo [93m::::::::::::::::::::::::::::::::::::::::::::
echo [93m:::::::::--=======================-:::::::::
echo [93m:::::::[36m-+##########################*-[93m:::::::
echo [93m:::::::[36m+############################+[93m:::::::
echo [93m:::::::[36m+############################*[93m:::::::
echo [93m:::::::[36m+######*[93m==============[36m*######*-[93m::::::
echo [93m::::::[36m-+######*[93m-::::::::::::-[36m+######*-[93m::::::
echo [93m::::::[36m-*######*[93m-::::::::::::-[36m*######*-[93m::::::
echo [93m .::::[36m-*######*[93m-::::::::::::-[36m*######*-[93m::::.
echo [93m :======- :======-
echo [0m
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::
:colorEcho
echo [36m%~1%[0m
exit /b
::::::::::::::::::::::::::::::::::::::::::::::::::