1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "ConfigFileManager.h" |
---|
30 | #include "ConfigValueContainer.h" |
---|
31 | #include "ConsoleCommand.h" |
---|
32 | #include "Identifier.h" |
---|
33 | #include "util/Convert.h" |
---|
34 | #include "util/String.h" |
---|
35 | |
---|
36 | #define CONFIG_FILE_MAX_LINELENGHT 1024 |
---|
37 | |
---|
38 | namespace orxonox |
---|
39 | { |
---|
40 | SetConsoleCommandShortcutExtern(config).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); |
---|
41 | SetConsoleCommandShortcutExtern(tconfig).setArgumentCompleter(0, autocompletion::configvalueclasses()).setArgumentCompleter(1, autocompletion::configvalues()).setArgumentCompleter(2, autocompletion::configvalue()); |
---|
42 | SetConsoleCommandShortcutExtern(reloadConfig); |
---|
43 | SetConsoleCommandShortcutExtern(cleanConfig); |
---|
44 | SetConsoleCommandShortcutExtern(loadSettings).setArgumentCompleter(0, autocompletion::files()); |
---|
45 | SetConsoleCommandShortcutExtern(loadKeybindings).setArgumentCompleter(0, autocompletion::files()); |
---|
46 | |
---|
47 | bool config(const std::string& classname, const std::string& varname, const std::string& value) |
---|
48 | { |
---|
49 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); |
---|
50 | if (identifier != Identifier::getLowercaseIdentifierMapEnd()) |
---|
51 | { |
---|
52 | std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); |
---|
53 | if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) |
---|
54 | return (*variable).second->set(value); |
---|
55 | } |
---|
56 | return false; |
---|
57 | } |
---|
58 | |
---|
59 | bool tconfig(const std::string& classname, const std::string& varname, const std::string& value) |
---|
60 | { |
---|
61 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); |
---|
62 | if (identifier != Identifier::getLowercaseIdentifierMapEnd()) |
---|
63 | { |
---|
64 | std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); |
---|
65 | if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) |
---|
66 | return (*variable).second->tset(value); |
---|
67 | } |
---|
68 | return false; |
---|
69 | } |
---|
70 | |
---|
71 | void reloadConfig() |
---|
72 | { |
---|
73 | ConfigFileManager::getSingleton()->load(); |
---|
74 | } |
---|
75 | |
---|
76 | void cleanConfig() |
---|
77 | { |
---|
78 | ConfigFileManager::getSingleton()->clean(false); |
---|
79 | } |
---|
80 | |
---|
81 | void loadSettings(const std::string& filename) |
---|
82 | { |
---|
83 | ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename, false); |
---|
84 | } |
---|
85 | |
---|
86 | void loadKeybindings(const std::string& filename) |
---|
87 | { |
---|
88 | ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, filename); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | ////////////////////////// |
---|
93 | // ConfigFileEntryValue // |
---|
94 | ////////////////////////// |
---|
95 | |
---|
96 | void ConfigFileEntryValue::setValue(const std::string& value) |
---|
97 | { |
---|
98 | if (!this->bString_) |
---|
99 | this->value_ = value; |
---|
100 | else |
---|
101 | this->value_ = "\"" + addSlashes(stripEnclosingQuotes(value)) + "\""; |
---|
102 | } |
---|
103 | |
---|
104 | std::string ConfigFileEntryValue::getValue() const |
---|
105 | { |
---|
106 | if (!this->bString_) |
---|
107 | return this->value_; |
---|
108 | else |
---|
109 | return removeSlashes(stripEnclosingQuotes(this->value_)); |
---|
110 | } |
---|
111 | |
---|
112 | std::string ConfigFileEntryValue::getFileEntry() const |
---|
113 | { |
---|
114 | if (this->additionalComment_ == "" || this->additionalComment_.size() == 0) |
---|
115 | return (this->name_ + "=" + this->value_); |
---|
116 | else |
---|
117 | return (this->name_ + "=" + this->value_ + " " + this->additionalComment_); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | /////////////////////////////// |
---|
122 | // ConfigFileEntryVectorValue // |
---|
123 | /////////////////////////////// |
---|
124 | std::string ConfigFileEntryVectorValue::getFileEntry() const |
---|
125 | { |
---|
126 | if (this->additionalComment_ == "" || this->additionalComment_.size() == 0) |
---|
127 | return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]" + "=" + this->value_); |
---|
128 | else |
---|
129 | return (this->name_ + "[" + getConvertedValue<unsigned int, std::string>(this->index_, "0") + "]=" + this->value_ + " " + this->additionalComment_); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /////////////////////// |
---|
134 | // ConfigFileSection // |
---|
135 | /////////////////////// |
---|
136 | ConfigFileSection::~ConfigFileSection() |
---|
137 | { |
---|
138 | for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ) |
---|
139 | delete (*(it++)); |
---|
140 | } |
---|
141 | |
---|
142 | void ConfigFileSection::deleteVectorEntries(const std::string& name, unsigned int startindex) |
---|
143 | { |
---|
144 | for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ) |
---|
145 | { |
---|
146 | if (((*it)->getName() == name) && ((*it)->getIndex() >= startindex)) |
---|
147 | { |
---|
148 | delete (*it); |
---|
149 | this->entries_.erase(it++); |
---|
150 | } |
---|
151 | else |
---|
152 | { |
---|
153 | ++it; |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | unsigned int ConfigFileSection::getVectorSize(const std::string& name) |
---|
159 | { |
---|
160 | unsigned int size = 0; |
---|
161 | for (std::list<ConfigFileEntry*>::const_iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) |
---|
162 | if ((*it)->getName() == name) |
---|
163 | if ((*it)->getIndex() > size) |
---|
164 | size = (*it)->getIndex(); |
---|
165 | return (size + 1); |
---|
166 | } |
---|
167 | |
---|
168 | std::string ConfigFileSection::getFileEntry() const |
---|
169 | { |
---|
170 | if (this->additionalComment_ == "" || this->additionalComment_.size() == 0) |
---|
171 | return ("[" + this->name_ + "]"); |
---|
172 | else |
---|
173 | return ("[" + this->name_ + "] " + this->additionalComment_); |
---|
174 | } |
---|
175 | |
---|
176 | std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, const std::string& fallback, bool bString) |
---|
177 | { |
---|
178 | for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) |
---|
179 | { |
---|
180 | if ((*it)->getName() == name) |
---|
181 | { |
---|
182 | (*it)->setString(bString); |
---|
183 | return it; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | this->bUpdated_ = true; |
---|
188 | |
---|
189 | return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryValue(name, fallback, bString))); |
---|
190 | } |
---|
191 | |
---|
192 | std::list<ConfigFileEntry*>::iterator ConfigFileSection::getEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString) |
---|
193 | { |
---|
194 | for (std::list<ConfigFileEntry*>::iterator it = this->entries_.begin(); it != this->entries_.end(); ++it) |
---|
195 | { |
---|
196 | if (((*it)->getName() == name) && ((*it)->getIndex() == index)) |
---|
197 | { |
---|
198 | (*it)->setString(bString); |
---|
199 | return it; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | this->bUpdated_ = true; |
---|
204 | |
---|
205 | if (index == 0) |
---|
206 | return this->entries_.insert(this->entries_.end(), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString))); |
---|
207 | else |
---|
208 | return this->entries_.insert(++this->getEntryIterator(name, index - 1, "", bString), (ConfigFileEntry*)(new ConfigFileEntryVectorValue(name, index, fallback, bString))); |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | //////////////// |
---|
213 | // ConfigFile // |
---|
214 | //////////////// |
---|
215 | ConfigFile::~ConfigFile() |
---|
216 | { |
---|
217 | for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ) |
---|
218 | delete (*(it++)); |
---|
219 | } |
---|
220 | |
---|
221 | void ConfigFile::load(bool bCreateIfNotExisting) |
---|
222 | { |
---|
223 | if (bCreateIfNotExisting) |
---|
224 | { |
---|
225 | // This creates the default config file if it's not existing |
---|
226 | std::ofstream createFile; |
---|
227 | createFile.open(this->filename_.c_str(), std::fstream::app); |
---|
228 | createFile.close(); |
---|
229 | } |
---|
230 | |
---|
231 | // Open the file |
---|
232 | std::ifstream file; |
---|
233 | file.open(this->filename_.c_str(), std::fstream::in); |
---|
234 | |
---|
235 | if (!file.is_open()) |
---|
236 | { |
---|
237 | COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; |
---|
238 | COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; |
---|
239 | return; |
---|
240 | } |
---|
241 | |
---|
242 | char linearray[CONFIG_FILE_MAX_LINELENGHT]; |
---|
243 | |
---|
244 | ConfigFileSection* newsection = 0; |
---|
245 | |
---|
246 | while (file.good() && !file.eof()) |
---|
247 | { |
---|
248 | file.getline(linearray, CONFIG_FILE_MAX_LINELENGHT); |
---|
249 | |
---|
250 | std::string line = std::string(linearray); |
---|
251 | |
---|
252 | std::string temp = getStripped(line); |
---|
253 | if (!isEmpty(temp) && !isComment(temp)) |
---|
254 | { |
---|
255 | unsigned int pos1 = temp.find('['); |
---|
256 | if (pos1 == 0) pos1 = line.find('['); else pos1 = std::string::npos; |
---|
257 | unsigned int pos2 = line.find(']'); |
---|
258 | |
---|
259 | if (pos1 != std::string::npos && pos2 != std::string::npos && pos2 > pos1 + 1) |
---|
260 | { |
---|
261 | // New section |
---|
262 | std::string comment = line.substr(pos2 + 1); |
---|
263 | if (isComment(comment)) |
---|
264 | newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1), comment); |
---|
265 | else |
---|
266 | newsection = new ConfigFileSection(line.substr(pos1 + 1, pos2 - pos1 - 1)); |
---|
267 | this->sections_.insert(this->sections_.end(), newsection); |
---|
268 | continue; |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | if (newsection != 0) |
---|
273 | { |
---|
274 | if (isComment(line)) |
---|
275 | { |
---|
276 | // New comment |
---|
277 | newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryComment(removeTrailingWhitespaces(line))); |
---|
278 | continue; |
---|
279 | } |
---|
280 | else |
---|
281 | { |
---|
282 | unsigned int pos1 = line.find('='); |
---|
283 | |
---|
284 | if (pos1 != std::string::npos && pos1 > 0) |
---|
285 | { |
---|
286 | // New entry |
---|
287 | unsigned int pos2 = line.find('['); |
---|
288 | unsigned int pos3 = line.find(']'); |
---|
289 | unsigned int commentposition = getNextCommentPosition(line, pos1 + 1); |
---|
290 | while (isBetweenQuotes(line, commentposition)) |
---|
291 | { |
---|
292 | commentposition = getNextCommentPosition(line, commentposition + 1); |
---|
293 | } |
---|
294 | std::string value = "", comment = ""; |
---|
295 | if (commentposition == std::string::npos) |
---|
296 | { |
---|
297 | value = removeTrailingWhitespaces(line.substr(pos1 + 1)); |
---|
298 | } |
---|
299 | else |
---|
300 | { |
---|
301 | value = removeTrailingWhitespaces(line.substr(pos1 + 1, commentposition - pos1 - 1)); |
---|
302 | comment = removeTrailingWhitespaces(line.substr(commentposition)); |
---|
303 | } |
---|
304 | |
---|
305 | if (pos2 != std::string::npos && pos3 != std::string::npos && pos3 > pos2 + 1) |
---|
306 | { |
---|
307 | // There might be an array index |
---|
308 | unsigned int index = 0; |
---|
309 | if (ConvertValue(&index, line.substr(pos2 + 1, pos3 - pos2 - 1))) |
---|
310 | { |
---|
311 | // New array |
---|
312 | std::list<ConfigFileEntry*>::iterator it = newsection->getEntryIterator(getStripped(line.substr(0, pos2)), index, value, false); |
---|
313 | (*it)->setValue(value); |
---|
314 | (*it)->setComment(comment); |
---|
315 | continue; |
---|
316 | } |
---|
317 | } |
---|
318 | |
---|
319 | // New value |
---|
320 | newsection->getEntries().insert(newsection->getEntries().end(), new ConfigFileEntryValue(getStripped(line.substr(0, pos1)), value, false, comment)); |
---|
321 | continue; |
---|
322 | } |
---|
323 | } |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | file.close(); |
---|
328 | |
---|
329 | COUT(3) << "Loaded config file \"" << this->filename_ << "\"." << std::endl; |
---|
330 | |
---|
331 | // Save the file in case something changed (like stripped whitespaces) |
---|
332 | this->save(); |
---|
333 | } |
---|
334 | |
---|
335 | void ConfigFile::save() const |
---|
336 | { |
---|
337 | std::ofstream file; |
---|
338 | file.open(this->filename_.c_str(), std::fstream::out); |
---|
339 | file.setf(std::ios::fixed, std::ios::floatfield); |
---|
340 | file.precision(6); |
---|
341 | |
---|
342 | if (!file.is_open()) |
---|
343 | { |
---|
344 | COUT(1) << "An error occurred in ConfigFileManager.cc:" << std::endl; |
---|
345 | COUT(1) << "Error: Couldn't open config-file \"" << this->filename_ << "\"." << std::endl; |
---|
346 | return; |
---|
347 | } |
---|
348 | |
---|
349 | for (std::list<ConfigFileSection*>::const_iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) |
---|
350 | { |
---|
351 | file << (*it)->getFileEntry() << std::endl; |
---|
352 | |
---|
353 | for (std::list<ConfigFileEntry*>::const_iterator it_entries = (*it)->getEntriesBegin(); it_entries != (*it)->getEntriesEnd(); ++it_entries) |
---|
354 | { |
---|
355 | file << (*it_entries)->getFileEntry() << std::endl; |
---|
356 | } |
---|
357 | |
---|
358 | file << std::endl; |
---|
359 | } |
---|
360 | |
---|
361 | file.close(); |
---|
362 | |
---|
363 | COUT(4) << "Saved config file \"" << this->filename_ << "\"." << std::endl; |
---|
364 | } |
---|
365 | |
---|
366 | void ConfigFile::clean(bool bCleanComments) |
---|
367 | { |
---|
368 | for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) |
---|
369 | { |
---|
370 | std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName()); |
---|
371 | if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues()) |
---|
372 | { |
---|
373 | // The section exists, delete comment |
---|
374 | if (bCleanComments) |
---|
375 | (*it1)->setComment(""); |
---|
376 | for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); ) |
---|
377 | { |
---|
378 | std::map<std::string, ConfigValueContainer*>::const_iterator it4 = (*it2).second->getConfigValueMap().find((*it3)->getName()); |
---|
379 | if (it4 != (*it2).second->getConfigValueMapEnd()) |
---|
380 | { |
---|
381 | // The config-value exists, delete comment |
---|
382 | if (bCleanComments) |
---|
383 | (*it3)->setComment(""); |
---|
384 | ++it3; |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | // The config-value doesn't exist |
---|
389 | delete (*it3); |
---|
390 | (*it1)->entries_.erase(it3++); |
---|
391 | } |
---|
392 | } |
---|
393 | ++it1; |
---|
394 | } |
---|
395 | else |
---|
396 | { |
---|
397 | // The section doesn't exist |
---|
398 | delete (*it1); |
---|
399 | this->sections_.erase(it1++); |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | // Save the file |
---|
404 | this->save(); |
---|
405 | } |
---|
406 | |
---|
407 | ConfigFileSection* ConfigFile::getSection(const std::string& section) |
---|
408 | { |
---|
409 | for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) |
---|
410 | if ((*it)->getName() == section) |
---|
411 | return (*it); |
---|
412 | |
---|
413 | this->bUpdated_ = true; |
---|
414 | |
---|
415 | return (*this->sections_.insert(this->sections_.end(), new ConfigFileSection(section))); |
---|
416 | } |
---|
417 | |
---|
418 | void ConfigFile::saveIfUpdated() |
---|
419 | { |
---|
420 | bool sectionsUpdated = false; |
---|
421 | |
---|
422 | for (std::list<ConfigFileSection*>::iterator it = this->sections_.begin(); it != this->sections_.end(); ++it) |
---|
423 | { |
---|
424 | if ((*it)->bUpdated_) |
---|
425 | { |
---|
426 | sectionsUpdated = true; |
---|
427 | (*it)->bUpdated_ = false; |
---|
428 | } |
---|
429 | } |
---|
430 | |
---|
431 | if (this->bUpdated_ || sectionsUpdated) |
---|
432 | { |
---|
433 | this->bUpdated_ = false; |
---|
434 | this->save(); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | /////////////////////// |
---|
440 | // ConfigFileManager // |
---|
441 | /////////////////////// |
---|
442 | ConfigFileManager::ConfigFileManager() |
---|
443 | { |
---|
444 | this->setFile(CFT_Settings, DEFAULT_CONFIG_FILE); |
---|
445 | } |
---|
446 | |
---|
447 | ConfigFileManager::~ConfigFileManager() |
---|
448 | { |
---|
449 | for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ) |
---|
450 | delete (*(it++)).second; |
---|
451 | } |
---|
452 | |
---|
453 | ConfigFileManager* ConfigFileManager::getSingleton() |
---|
454 | { |
---|
455 | static ConfigFileManager instance; |
---|
456 | return (&instance); |
---|
457 | } |
---|
458 | |
---|
459 | void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting) |
---|
460 | { |
---|
461 | std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); |
---|
462 | if (it != this->configFiles_.end()) |
---|
463 | if ((*it).second != 0) |
---|
464 | delete (*it).second; |
---|
465 | |
---|
466 | this->configFiles_[type] = new ConfigFile(this->getFilePath(filename)); |
---|
467 | this->load(type, bCreateIfNotExisting); |
---|
468 | } |
---|
469 | |
---|
470 | void ConfigFileManager::load(bool bCreateIfNotExisting) |
---|
471 | { |
---|
472 | for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) |
---|
473 | (*it).second->load(bCreateIfNotExisting); |
---|
474 | |
---|
475 | this->updateConfigValues(); |
---|
476 | } |
---|
477 | |
---|
478 | void ConfigFileManager::save() |
---|
479 | { |
---|
480 | for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) |
---|
481 | (*it).second->save(); |
---|
482 | } |
---|
483 | |
---|
484 | void ConfigFileManager::clean(bool bCleanComments) |
---|
485 | { |
---|
486 | for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) |
---|
487 | this->clean((*it).first, bCleanComments); |
---|
488 | } |
---|
489 | |
---|
490 | void ConfigFileManager::load(ConfigFileType type, bool bCreateIfNotExisting) |
---|
491 | { |
---|
492 | this->getFile(type)->load(bCreateIfNotExisting); |
---|
493 | this->updateConfigValues(type); |
---|
494 | } |
---|
495 | |
---|
496 | void ConfigFileManager::save(ConfigFileType type) |
---|
497 | { |
---|
498 | this->getFile(type)->save(); |
---|
499 | } |
---|
500 | |
---|
501 | void ConfigFileManager::clean(ConfigFileType type, bool bCleanComments) |
---|
502 | { |
---|
503 | this->getFile(type)->clean(bCleanComments); |
---|
504 | } |
---|
505 | |
---|
506 | void ConfigFileManager::updateConfigValues() const |
---|
507 | { |
---|
508 | for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) |
---|
509 | this->updateConfigValues((*it).first); |
---|
510 | } |
---|
511 | |
---|
512 | void ConfigFileManager::updateConfigValues(ConfigFileType type) const |
---|
513 | { |
---|
514 | if (type == CFT_Settings) |
---|
515 | { |
---|
516 | for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) |
---|
517 | { |
---|
518 | if ((*it).second->hasConfigValues() /* && (*it).second != ClassManager<KeyBinder>::getIdentifier()*/) |
---|
519 | { |
---|
520 | for (std::map<std::string, ConfigValueContainer*>::const_iterator it2 = (*it).second->getConfigValueMapBegin(); it2 != (*it).second->getConfigValueMapEnd(); ++it2) |
---|
521 | (*it2).second->update(); |
---|
522 | |
---|
523 | (*it).second->updateConfigValues(); |
---|
524 | } |
---|
525 | } |
---|
526 | } |
---|
527 | else if (type == CFT_Keybindings) |
---|
528 | { |
---|
529 | // todo |
---|
530 | } |
---|
531 | } |
---|
532 | |
---|
533 | ConfigFile* ConfigFileManager::getFile(ConfigFileType type) |
---|
534 | { |
---|
535 | std::map<ConfigFileType, ConfigFile*>::iterator it = this->configFiles_.find(type); |
---|
536 | if (it != this->configFiles_.end()) |
---|
537 | return (*it).second; |
---|
538 | |
---|
539 | if (type == CFT_Settings) |
---|
540 | return this->configFiles_[type] = new ConfigFile(DEFAULT_CONFIG_FILE); |
---|
541 | else |
---|
542 | return this->configFiles_[type] = new ConfigFile(""); |
---|
543 | } |
---|
544 | |
---|
545 | std::string ConfigFileManager::getFilePath(const std::string& name) const |
---|
546 | { |
---|
547 | return name; |
---|
548 | } |
---|
549 | } |
---|