-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
165 lines (158 loc) · 5.98 KB
/
config.py
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
import json
import os
def merge_dicts(dict1, dict2):
""" Recursively merges dict2 into dict1 """
if not isinstance(dict1, dict) or not isinstance(dict2, dict):
return dict2
for k in dict2:
if k in dict1:
dict1[k] = merge_dicts(dict1[k], dict2[k])
else:
dict1[k] = dict2[k]
return dict1
class Config:
def __init__(self):
appdata_path = os.environ.get('LOCALAPPDATA')
microsip_binary = os.path.join(appdata_path, "MicroSIP\\microsip.exe")
self.APP_NAME = 'VRChatVRPhone'
self.default_config = {
"version": 1,
"server_port": 9001,
"microsip_binary": microsip_binary,
"interaction_timeout": 2,
"log_verbose": False,
"phonebook": [
["Entry1", "5229"],
["Entry2", "5230"],
["Entry3", "2275"],
["Conference", "1111"]
],
"phonemenu": {
"init_screen": "main",
"transition_popup": 1,
"dialogs": {
"call_incoming":{
"dialog": 1,
"window": 2,
"popup": 0,
"numbers": {
"row1": "callerid",
"row2": None
},
"choices": {
"yes_button": ["call_accept", None],
"no_button": ["call_hangup", None]
}
},
"call_outgoing":{
"dialog": 2,
"window": 2,
"popup": 0,
"numbers": {
"row1": "callerid",
"row2": None
},
"choices": {
"no_button": ["call_hangup", None]
}
},
"call_confirm":{
"dialog": 3,
"window": 2,
"popup": 0,
"numbers": {
"row1": "phonebook",
"row2": None
},
"choices": {
"yes_button": ["phonebook_call_active_entry", None],
"no_button": ["exit_dialogs", None]
}
},
"call_end":{
"dialog": 5,
"window": 2,
"popup": 0,
"numbers": {
"row1": "callerid",
"row2": "calltimer"
},
"choices": {}
},
"call_start":{
"dialog": 4,
"window": 2,
"popup": 0,
"numbers": {
"row1": "callerid",
"row2": "calltimer"
},
"choices": {
"no_button": ["call_hangup", None]
}
}
},
"screens": {
"main": {
"screenid": 1,
"window": 0,
"popup": 0,
"numbers": {
"row1": None,
"row2": "systemtime"
},
"selectors": {},
"choices": {
"yes_button": ["screen", "phonebook"]
}
},
"phonebook": {
"screenid": 2,
"window": 0,
"popup": 0,
"numbers": {
"row1": "phonebook",
"row2": "entry"
},
"selectors": {},
"choices": {
"yes_button": ["dialog", "call_confirm"],
"no_button": ["screen", "main"],
"ok_button": ["phonebook_switch", "next"],
"cancel_button": ["phonebook_switch", "prev"]
}
}
}
}
}
self.current_config = None
def get_by_key(self, key: str):
return self.current_config.get(key)
def update(self, key: str, nextValue):
if (key in self.current_config):
self.current_config[key] = nextValue
def read_config_from_disk(self):
appdata_path = os.environ.get('LOCALAPPDATA')
app_directory = os.path.join(appdata_path, self.APP_NAME)
os.makedirs(app_directory, exist_ok=True)
config_path = os.path.join(app_directory, 'config.json')
if os.path.exists(config_path):
with open(config_path, 'r') as file:
data = json.load(file)
data = merge_dicts(self.default_config, data)
return data
else:
with open(config_path, 'w') as file:
json.dump(self.default_config, file, indent=4)
return self.default_config
def write_config_to_disk(self):
if self.current_config == None:
return
appdata_path = os.environ.get('LOCALAPPDATA')
app_directory = os.path.join(appdata_path, self.APP_NAME)
os.makedirs(app_directory, exist_ok=True)
config_path = os.path.join(app_directory, 'config.json')
with open(config_path, 'w') as file:
json.dump(self.current_config, file, indent=4)
def init(self):
self.current_config = self.read_config_from_disk()