-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.cmd
67 lines (56 loc) · 1.24 KB
/
Config.cmd
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
@echo off
set Self=%1
rem echo Configure %Self% scrpit
call :InitVars
rem echo %Init%
IF "x%Init%" == "xFalse" (
rem del %Self%.config.new
call :InitConfig
call :InitVars
rem %SrcDir%
)
goto :EOF
:InitVars
set "input="
for /f "delims== tokens=1,2" %%a in (%Self%.config) do (
rem ignore comments that starts with '#'
if Not "%variable:~0,1%"=="#" (
call :SetVar %%a %%b
)
)
goto :EOF
:SetVar
rem echo Setting var %1 %2
set value=%~2
set %1=%value%
goto :EOF
:WriteVar
rem echo Write variable %1="%2"
echo %1="%2">> %Self%.config.new
set %1=%2
goto :EOF
:InitVar
echo ' '
echo ' '
set /p input=Enter value for %1:
rem echo Write variable %1="%input%"
echo %1="%input%">> %Self%.config.new
goto :EOF
:InitConfig
for /f "delims== tokens=1,2" %%a in (%Self%.config) do (
rem replace init flag
if "%%a"=="Init" (
call :WriteVar Init True
) else (
rem copy comments that starts with '#'
if "x%%a:~0,1%"=="x#" (
call :WriteVar %%a %%b
) else (
setlocal enabledelayedexpansion
call :InitVar %%a
)
)
)
move %Self%.config %Self%.config.back
move %Self%.config.new %Self%.config
goto :EOF