forked from sgumhold/cgv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
define_options.bat
138 lines (135 loc) · 4.4 KB
/
define_options.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
@echo off
setlocal EnableDelayedExpansion
%~d0
cd %~p0
:menu
echo Define cgv options
echo -------------------------------------------
echo CGV_OPTIONS=%CGV_OPTIONS%
echo -------------------------------------------
echo [1] ... toggle NO_OPENVR (allows to avoid the start of openvr during development)
echo [2] ... toggle SHADER_DEVELOPER (make shader_test throw errors that make the build process fail)
echo [3] ... toggle ENCODE_SHADER_BASE64 (encode shader codes in base64 before embedding)
echo [4] ... toggle BUILD_WITH_AUDIO (requires checking out the git submodules when building from the repository)
echo [5] ... toggle custom option
echo [6] ... clear all options
echo.
echo [q] ... quit script
echo.
:ask_again
set /P selection=choose 1-5 or q^>
if [%selection%] == [] (
echo please enter a number between 1 and 5 or q for quit
goto:ask_again
)
if "%selection%" == "q" (
goto:eof
)
if "%selection%" == "1" (
call :toggle_in_list CGV_OPTIONS NO_OPENVR
goto :publish_options
)
if "%selection%" == "2" (
call :toggle_in_list CGV_OPTIONS SHADER_DEVELOPER
goto :publish_options
)
if "%selection%" == "3" (
call :toggle_in_list CGV_OPTIONS ENCODE_SHADER_BASE64
goto :publish_options
)
if "%selection%" == "4" (
call :toggle_in_list CGV_OPTIONS BUILD_WITH_AUDIO
goto :publish_options
)
if "%selection%" == "5" (
set /P custom_option=enter curstom option:^>
call :toggle_in_list CGV_OPTIONS !custom_option!
goto :publish_options
)
rem clear all options by removal of registry key and using setx to communicate change to all processes
call reg DELETE HKEY_CURRENT_USER\Environment /v CGV_OPTIONS /f >nul 2> nul
bin\setx CGV_DUMMY ""
call reg DELETE HKEY_CURRENT_USER\Environment /v CGV_DUMMY /f >nul 2> nul
set CGV_OPTIONS=
goto :menu
:publish_options
call reg ADD HKEY_CURRENT_USER\Environment /v CGV_OPTIONS /t REG_SZ /d "%CGV_OPTIONS%" /f > nul 2> nul
bin\setx CGV_DUMMY ""
call reg DELETE HKEY_CURRENT_USER\Environment /v CGV_DUMMY /f >nul 2> nul
goto :menu
rem call with two arguments: variable name and to be toggled element
rem the variable is assumed to contain a semicolon separated list of
rem elements. If the passed element is in the list, it is removed and
rem the variable will contain the truncated list afterwards. If the
rem element is not in the list, it is appended to the list.
rem The list is allowed to be empty and optionally can be enclosed in
rem in double quotes. The quoting property is preserved by the function.
rem To handle quotes it is assumed that the # character is not used inside
rem of elements.
:toggle_in_list
setlocal EnableDelayedExpansion
rem extract parameters
set varname=%1
set element=%2
rem extract list into local variable
call set list=%%%1%%
rem replace potential double quotes with the #
if defined list (
set list=!list:"=#!
)
rem in case of empty list, result is just the element with quoting property of previously empty list
if "!list!" == "" (
endlocal & set %1=%element%
goto :eof
) else (
rem this would yield an error if we did not replace double quotes with # before
if "!list!" == "##" (
endlocal & set %1="%element%"
goto :eof
)
)
rem determine quoting proterty into local variable
if "!list:~0,1!" == "#" (
set has_quotes=true
)
rem remove quotes, such that we can assume that the list is unquoted
set list=!list:#=!
rem split list into quoted elements
set list="%list:;=" "%"
rem flag to let us know whether we are at first element and do not need to add a semicolon
set is_first=1
rem remember whether we removed to element during iteration of the list to know whether we need to append it
set removed=0
rem iterate all list elements
for %%G in (%list%) do (
rem check for to be toggled element and do not append it to new list, but set removed status
if %%G == "%element%" (
set removed=1
) else (
rem otherwise prepend a semicolon starting with the second element
set temp=%%G
if !is_first! == 1 (
set is_first=0
) else (
set new_list=!new_list!;
)
rem and the append the current element to the new list
set new_list=!new_list!!temp:~1,-1!
)
)
rem if to be toggled element is not found, append it to new list
if %removed% == 0 (
if !is_first! == 1 (
set is_first=0
) else (
set new_list=!new_list!;
)
set new_list=!new_list!!element!
)
rem preserve original quoting property
if "%has_quotes%" == "true" (
set new_list="!new_list!"
)
rem pass the new list to the variable of the calling shell instance
endlocal & set %varname%=%new_list%
goto:eof