forked from sgumhold/cgv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine_system_variables.bat
341 lines (326 loc) · 8.58 KB
/
define_system_variables.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
@echo off
setlocal EnableDelayedExpansion
%~d0
cd %~p0
set my_path=%~dp0
set cgvdir=%my_path:~0,-1%
set cgvbuild=%cgvdir%\build
set cgvinstall=%cgvdir%
if [%1] == [] (
set param=""
) else (
set param=%1
)
set param=%param:"=%
if NOT [%1] == [] (
if EXIST "%param%\..\%~n1" (
call set cgvbuild=%param%
call set cgvinstall=%param%
) else (
echo only directories valid as build path argument
echo "%param%\..\%~n1" does not exist
)
)
echo Define System Variables for cgv Framework
echo -------------------------------------------
echo please answer the following question by
echo entering a number in [1,9] or letter in [a-c]
echo pressing return afterwards.
echo -------------------------------------------
echo choose whether to proceed interactively and
echo which compiler to choose:
echo.
echo interactive mode:
echo [0] ... Microsoft Visual Studio 2005
echo [1] ... Microsoft Visual Studio 2008
echo [2] ... Microsoft Visual Studio 2008 Express
echo [3] ... Microsoft Visual Studio 2010
echo [4] ... Microsoft Visual Studio 2012
echo [5] ... Microsoft Visual Studio 2013
echo [6] ... Microsoft Visual Studio 2015
echo [7] ... Microsoft Visual Studio 2017
echo [8] ... Microsoft Visual Studio 2019
echo [9] ... Microsoft Visual Studio 2022
echo.
echo automatic mode:
echo [a] ... Microsoft Visual Studio 2005
echo [b] ... Microsoft Visual Studio 2008
echo [c] ... Microsoft Visual Studio 2008 Express
echo [d] ... Microsoft Visual Studio 2010
echo [e] ... Microsoft Visual Studio 2012
echo [f] ... Microsoft Visual Studio 2013
echo [g] ... Microsoft Visual Studio 2015
echo [h] ... Microsoft Visual Studio 2017
echo [i] ... Microsoft Visual Studio 2019
echo [j] ... Microsoft Visual Studio 2022
echo.
echo [q] ... quit script
echo.
:ask_again
set /P selection=choose 0-9 or a-j or q^>
if [%selection%] == [] (
echo please enter a number in [0-9] or a letter in [a-j] or q for quit
goto:ask_again
)
if "%selection%" == "q" (
echo script canceled
pause
goto:eof
)
set valid_number=true
if "%selection%" == "a" (
call set /A selection=10
) else (
if "%selection%" == "b" (
call set /A selection=11
) else (
if "%selection%" == "c" (
call set /A selection=12
) else (
if "%selection%" == "d" (
call set /A selection=13
) else (
if "%selection%" == "e" (
call set /A selection=14
) else (
if "%selection%" == "f" (
call set /A selection=15
) else (
if "%selection%" == "g" (
call set /A selection=16
) else (
if "%selection%" == "h" (
call set /A selection=17
) else (
if "%selection%" == "i" (
call set /A selection=18
) else (
if "%selection%" == "j" (
call set /A selection=19
) else (
call set /A selection=%selection%
if %selection% LSS 0 (set valid_number=false)
if %selection% GTR 9 (set valid_number=false)
)
)
)
)
)
)
)
)
)
)
if %valid_number% == false (
echo invalid number outside range [0-9,a-j], please try again
goto:ask_again
)
set interactive_mode=true
if %selection% GTR 9 (
set interactive_mode=false
set /A selection=selection-10
)
set cgvcompiler=undefined
call set condition=%selection%==0
if %condition% (set cgvcompiler=vs8)
call set condition=%selection%==1
if %condition% (set cgvcompiler=vs9)
call set condition=%selection%==2
if %condition% (set cgvcompiler=vs9)
call set condition=%selection%==3
if %condition% (set cgvcompiler=vs10)
call set condition=%selection%==4
if %condition% (set cgvcompiler=vs11)
call set condition=%selection%==5
if %condition% (set cgvcompiler=vs12)
call set condition=%selection%==6
if %condition% (set cgvcompiler=vs14)
call set condition=%selection%==7
if %condition% (set cgvcompiler=vs141)
call set condition=%selection%==8
if %condition% (set cgvcompiler=vs142)
call set condition=%selection%==9
if %condition% (set cgvcompiler=vs143)
if %interactive_mode%==true (
echo.
echo selected interactive mode
echo.
)
call :set_variable CGV_DIR "%cgvdir%" %interactive_mode%
call :set_variable CGV_BUILD "%cgvbuild%" %interactive_mode%
call :set_variable CGV_INSTALL "%cgvinstall%" %interactive_mode%
call :set_variable CGV_COMPILER "%cgvcompiler%" %interactive_mode%
rem find out current value of path variable
call :query_user_path old_path
set target_path=%%CGV_INSTALL%%\bin
call :remove_from_list old_path target_path
set old_path_1=%new_path%
set target_path=%%CGV_DIR%%\bin
call :remove_from_list old_path_1 target_path
set old_path_2=%new_path%
set target_path=%%CGV_DIR%%\bin\WIN32
call :remove_from_list old_path_2 target_path
set old_path_3=%new_path%
set target_path=%%CGV_DIR%%\bin\WIN64
call :remove_from_list old_path_3 target_path
if "%new_path%" == "" (
set new_path=%%CGV_DIR%%\bin;%%CGV_INSTALL%%\bin
) else (
set new_path=%%CGV_DIR%%\bin;%%CGV_INSTALL%%\bin;%new_path%
)
set change=false
if "%new_path%" NEQ "%old_path%" (
set change=true
)
if %change%==true (
echo.
echo old Path extension of USER:
echo ---------------------------
call :show_list_expanded old_path
echo.
echo new Path extension of USER:
echo ---------------------------
call :show_list_expanded new_path
)
set allow_change=y
:yes_no_main
if %change%==true (
if %interactive_mode%==true (
echo.
set /p allow_change=allow path change [y/n] ^>
)
)
if "%allow_change%" == "n" (
set change=false
) else (
if %allow_change% NEQ y (
echo.
echo please answer y, n
goto:yes_no
)
)
if %change%==true (
reg ADD HKEY_CURRENT_USER\Environment /v Path /t REG_EXPAND_SZ /d "%new_path%" /f > nul 2> nul
)
bin\setx CGV_DUMMY ""
call reg DELETE HKEY_CURRENT_USER\Environment /v CGV_DUMMY /f >nul 2> nul
pause
goto:eof
:set_variable
SETLOCAL
set var_name=%1
set new_value=%2
set new_value=%new_value:~1,-1%
set interactive_mode=%3
rem echo called set_variable(%var_name%,%new_value%,%interactive_mode%)
if defined %var_name% (
call set old_value=%%%var_name%%%
)
set change=true
if defined %var_name% (
if "%old_value%" NEQ "%new_value%" (
echo %var_name%: %old_value% -^> %new_value%
) else (
echo %var_name%: no change
set change=false
)
) else (
echo %var_name%: set to %new_value%
)
set allow_change=y
:yes_no
if %change%==true (
if %interactive_mode%==true (
echo.
set /p allow_change=allow change [y/n] ^>
)
)
if %allow_change% == n (
set change=false
) else (
if %allow_change% NEQ y (
echo.
echo please answer y or n
goto:yes_no
)
)
if %change%==true (
call reg ADD HKEY_CURRENT_USER\Environment /v %var_name% /t REG_SZ /d "%new_value%" /f > nul 2> nul
endlocal & call set %var_name%=%new_value%
echo ^(USER:%var_name%=%new_value%^)
)
echo.
goto:eof
:show_list_expanded
setlocal
call set list=%%%1%%
if "%list%" == "[]" (
echo empty
goto :eof
)
for %%G in ("%list:;=" "%") do @echo %%G
goto:eof
:remove_from_list
setlocal
call set list=%%%1%%
if "%list%" == "[]" (
goto :eof
)
if "%list%" == "" (
goto :eof
)
call set element=%%%2%%
for %%G in ("%list:;=" "%") do (
set entry=%%G
set entry=!entry:~1,-1!
if !entry! NEQ %element% (
if defined new_list (
set new_list=!new_list!;!entry!
) else (
set new_list=!entry!
)
)
)
endlocal & set new_path=%new_list%
endlocal
goto:eof
:query_user_path
reg QUERY HKEY_CURRENT_USER\Environment /v Path > nul 2> nul
if ERRORLEVEL 1 (
set %1=[]
) else (
call :query_user_path_impl %1
)
goto:eof
:query_user_path_impl
for /f "delims=" %%G IN ('reg QUERY HKEY_CURRENT_USER\Environment /v Path ^|find "Path"') DO (set user_path=%%G)
call :remove_spaces user_path
call :remove_non_spaces user_path
call :remove_spaces user_path
call :remove_non_spaces user_path
call :remove_spaces user_path
set %1=%user_path%
goto :eof
:remove_spaces
call set temp=%%%1%%
:loop_remove_spaces
if "%temp:~0,1%" == " " (
set temp=%temp:~1%
goto :loop_remove_spaces
)
if "%temp:~0,1%" == " " (
set temp=%temp:~1%
goto :loop_remove_spaces
)
set %1=%temp%
goto:eof
:remove_non_spaces
call set temp=%%%1%%
:loop_remove_non_spaces
if "%temp:~0,1%" == " " (goto :end_remove_non_spaces)
if "%temp:~0,1%" == " " (goto :end_remove_non_spaces)
set temp=%temp:~1%
goto :loop_remove_non_spaces
:end_remove_non_spaces
set %1=%temp%
goto:eof