-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigmanager.cpp
More file actions
executable file
·314 lines (278 loc) · 6.32 KB
/
configmanager.cpp
File metadata and controls
executable file
·314 lines (278 loc) · 6.32 KB
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
#include "configmanager.h"
const wchar *configname = L"mainconfig.xml";
ConfigManager* ConfigManager::instance = NULL;
ConfigManager::ConfigManager()
{
rootnode = NULL;
}
ConfigManager::~ConfigManager()
{
}
bool ConfigManager::Open()
{
bool ret;
rootnode = mainconfig_xml.openXML(configname);
ret = rootnode == NULL ? false : true;
if( ret == false)
rootnode = new CXmlNode;
return ret;
}
void ConfigManager::Save()
{
if(rootnode)
mainconfig_xml.saveXML(configname, rootnode->getChild());
}
void ConfigManager::Close()
{
Save();
rootnode = NULL;
}
// COMMON
void ConfigManager::SetConfig(String key, String value)
{
// 있으면 overwrite, 없으면 생성
CXmlNode *node = CXmlNode::findChild(rootnode, key.c_str());
if( node )
{
node->setValue(value.c_str());
}
else
{
rootnode->addChild(key.c_str(), value.c_str());
}
}
String ConfigManager::GetConfigValue(String key)
{
CXmlNode *node = CXmlNode::findChild(rootnode, key.c_str());
if( node )
return String(node->getValue());
else
rootnode->addChild(key.c_str(), L"");
return String(L"");
}
int ConfigManager::GetConfigInt(String key)
{
CXmlNode *node = CXmlNode::findChild(rootnode, key.c_str());
if( node )
{
int ret = unicode::atoi(node->getValue());
return ret;
}
else
rootnode->addChild(key.c_str(), L"");
return -1;
}
// Function Key
String ConfigManager::GetFuntionKey(String key, String subkey)
{
CXmlNode *node = CXmlNode::findChild(rootnode, key.c_str());
if( node )
{
CXmlNode *cnode = CXmlNode::findChild(node, subkey.c_str());
if( cnode )
{
return String(cnode->getValue());
}
}
return String(L"");
}
void ConfigManager::SetFuntionKey(String key, String subkey, String value)
{
CXmlNode *node = CXmlNode::findChild(rootnode, key.c_str());
if( node )
{
CXmlNode *cnode = CXmlNode::findChild(node, subkey.c_str());
if( cnode )
{
cnode->setValue(value.c_str());
}
else
{
node->addChild(subkey.c_str(), value.c_str());
}
}
else
{
node = rootnode->addChild(key.c_str(), L"");
node->addChild(subkey.c_str(), value.c_str());
}
}
void ConfigManager::SetSVN(String name, String exec, String path)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"svnconfig");
if( node )
{
node = node->addChild(L"svn", L"");
node->addAttribute(L"name", name.c_str());
node->addAttribute(L"exec", exec.c_str());
node->addAttribute(L"path", path.c_str());
}
else
{
// 생성
node = rootnode->addChild(L"svnconfig", L"");
node = node->addChild(L"svn", L"");
node->addAttribute(L"name", name.c_str());
node->addAttribute(L"exec", exec.c_str());
node->addAttribute(L"path", path.c_str());
}
}
bool ConfigManager::GetSVN(String name , SVNInfo &info)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"svnconfig");
if( node )
{
CXmlNode *child = node->getChild();
for ( ; child != NULL; child = child->getNext() )
{
String cname = child->getAttiribute(L"name");
if( cname == name )
{
info.name = cname;
info.exec = child->getAttiribute(L"exec");
info.path = child->getAttiribute(L"path");
return true;
}
}
}
return false;
}
void ConfigManager::GetSVN(std::vector<SVNInfo> &info)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"svnconfig");
if( node )
{
CXmlNode *child = node->getChild();
for ( ; child != NULL; child = child->getNext() )
{
SVNInfo f;
f.name = child->getAttiribute(L"name");
f.exec = child->getAttiribute(L"exec");
f.path = child->getAttiribute(L"path");
info.push_back(f);
}
}
}
bool ConfigManager::ExistSVN(String name)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"svnconfig");
if( node )
{
CXmlNode *child = node->getChild();
for ( ; child != NULL; child = child->getNext() )
{
String n = child->getAttiribute(L"name");
if( name == n )
return true;
}
}
return false;
}
void ConfigManager::RemoveSVN(String name)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"svnconfig");
if( node )
{
CXmlNode *child = node->getChild();
for ( ; child != NULL; child = child->getNext() )
{
String n = child->getAttiribute(L"name");
if( name == n )
{
CXmlNode::removeNode(child);
return;
}
}
}
}
// SVN
CXmlNode* ConfigManager::FindNode(String key)
{
return CXmlNode::findChild(rootnode, key.c_str());
}
// Common
String ConfigManager::GetCommonOption(String key)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"commonconfig");
if( node )
{
CXmlNode *cnode = CXmlNode::findChild(node, key.c_str());
if( cnode )
{
return String(cnode->getValue());
}
}
return String(L"");
}
void ConfigManager::SetTortoisePath(String path)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"tortoisesvn");
if( node )
{
node = node->addChild(L"path", path.c_str());
}
else
{
// 생성
node = rootnode->addChild(L"tortoisesvn", L"");
node = node->addChild(L"path", path.c_str());
}
}
String ConfigManager::GetTortoisePath()
{
/*
CXmlNode *node = CXmlNode::findChild(rootnode, L"tortoisesvn");
if( node )
{
CXmlNode *cnode = CXmlNode::findChild(node, L"path");
if( cnode )
{
return String(cnode->getValue());
}
}
*/
// regsitry에서 읽자
wxRegKey key(wxRegKey::HKLM, "Software\\TortoiseSVN");
wxString strValue;
bool ret = key.QueryValue("ProcPath", strValue, false);
if( ret == true )
{
return String(strValue);
}
return String(L"");
}
bool ConfigManager::GetCommonOptionBool(String key)
{
String ret = GetCommonOption(key);
if( ret == L"true")
return true;
else
return false;
}
void ConfigManager::SetCommonOption(String key, String value)
{
CXmlNode *node = CXmlNode::findChild(rootnode, L"commonconfig");
if( node )
{
CXmlNode *cnode = CXmlNode::findChild(node, key.c_str());
if( cnode )
{
cnode->setValue(value.c_str());
}
else
{
node->addChild(key.c_str(), value.c_str());
}
}
else
{
// 생성
node = rootnode->addChild(L"commonconfig", L"");
node = node->addChild(key.c_str(), L"");
node->setValue(value.c_str());
}
}
void ConfigManager::SetCommonOptionBool(String key, bool value)
{
SetCommonOption(key, value ? L"true" : L"false");
}