forked from rmkit-dev/rmkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.cpy
73 lines (56 loc) · 1.73 KB
/
config.cpy
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
// reading remux.conf file
class RemuxConfig:
public:
vector<pair<string, string>> values
RemuxConfig():
pass
vector<string> get_array(string key):
vector<string> ret
for auto p : values:
if p.first == key:
ret.push_back(p.second)
return ret
string get_value(string key, default_value=""):
val := default_value
for auto p : values:
if p.first == key:
val = p.second
return val
bool get_bool(string key, bool default_value=false):
val := default_value
for auto p : values:
if p.first == key:
if p.second == "yes" or p.second == "true" or p.second == "1":
val = true
else if p.second == "no" or p.second == "false" or p.second == "" or p.second == "0":
val = false
else:
debug "* KEY", key, "HAS UNRECOGNIZED BOOLEAN VALUE:", p.second, "MUST BE 'yes' or 'no'"
debug " DEFAULTING TO", default_value
return val
bool has_key(string key):
for auto p : values:
if p.first == key:
return true
return false
void set(string key, value):
self.values.push_back({key, value})
int size():
return self.values.size()
def read_remux_config():
string line
_ := system("mkdir -p /home/root/.config/remux/ 2> /dev/null")
config_file := "/home/root/.config/remux/remux.conf"
debug "READING CONFIG FROM", config_file
ifstream f(config_file)
config := RemuxConfig()
while getline(f, line):
tokens := str_utils::split(line, '=')
while tokens.size() > 2:
tokens[tokens.size()-2] += "=" + tokens[tokens.size()-1]
tokens.pop_back()
if tokens.size() == 2:
config.set(tokens[0], tokens[1])
else:
config.set(tokens[0], "")
return config