- Timestamp:
- Apr 10, 2008, 6:44:38 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core2/src/orxonox/core/ConfigFileManager.cc
r1026 r1027 38 38 { 39 39 ConsoleCommandShortcutExtern(reloadConfig, AccessLevel::None); 40 ConsoleCommandShortcutExtern(saveConfig, AccessLevel::None);41 40 ConsoleCommandShortcutExtern(cleanConfig, AccessLevel::None); 42 41 ConsoleCommandShortcutExtern(loadSettings, AccessLevel::None); … … 48 47 } 49 48 50 void saveConfig()51 {52 ConfigFileManager::getSingleton()->save();53 }54 55 49 void cleanConfig() 56 50 { … … 60 54 void loadSettings(const std::string& filename) 61 55 { 62 ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename );56 ConfigFileManager::getSingleton()->setFile(CFT_Settings, filename, false); 63 57 } 64 58 … … 145 139 } 146 140 147 void ConfigFile::load() 148 { 149 // This creates the file if it's not existing 150 std::ofstream createFile; 151 createFile.open(this->filename_.c_str(), std::fstream::app); 152 createFile.close(); 141 void ConfigFile::load(bool bCreateIfNotExisting) 142 { 143 if (bCreateIfNotExisting) 144 { 145 // This creates the default config file if it's not existing 146 std::ofstream createFile; 147 createFile.open(this->filename_.c_str(), std::fstream::app); 148 createFile.close(); 149 } 153 150 154 151 // Open the file … … 289 286 void ConfigFile::clean() 290 287 { 288 for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) 289 { 290 std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getIdentifierMap().find((*it1)->getName()); 291 if (it2 != Identifier::getIdentifierMapEnd() && (*it2).second->hasConfigValues()) 292 { 293 // The section exists, delete comment 294 (*it1)->setComment(""); 295 for (std::list<ConfigFileEntry*>::iterator it3 = (*it1)->entries_.begin(); it3 != (*it1)->entries_.end(); ) 296 { 297 std::map<std::string, ConfigValueContainer*>::const_iterator it4 = (*it2).second->getConfigValueMap().find((*it3)->getName()); 298 if (it4 != (*it2).second->getConfigValueMapEnd()) 299 { 300 // The config-value exists, delete comment 301 (*it3)->setComment(""); 302 ++it3; 303 } 304 else 305 { 306 // The config-value doesn't exist 307 delete (*it3); 308 (*it1)->entries_.erase(it3++); 309 } 310 } 311 ++it1; 312 } 313 else 314 { 315 // The section doesn't exist 316 delete (*it1); 317 this->sections_.erase(it1++); 318 } 319 } 320 321 // Save the file 322 this->save(); 291 323 } 292 324 … … 343 375 } 344 376 345 void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename )377 void ConfigFileManager::setFile(ConfigFileType type, const std::string& filename, bool bCreateIfNotExisting) 346 378 { 347 379 std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.find(type); … … 351 383 352 384 this->configFiles_[type] = new ConfigFile(this->getFilePath(filename)); 353 this->load(type );354 } 355 356 void ConfigFileManager::load( )385 this->load(type, bCreateIfNotExisting); 386 } 387 388 void ConfigFileManager::load(bool bCreateIfNotExisting) 357 389 { 358 390 for(std::map<ConfigFileType, ConfigFile*>::const_iterator it = this->configFiles_.begin(); it != this->configFiles_.end(); ++it) 359 (*it).second->load( );391 (*it).second->load(bCreateIfNotExisting); 360 392 361 393 this->updateConfigValues(); … … 374 406 } 375 407 376 void ConfigFileManager::load(ConfigFileType type )377 { 378 this->getFile(type)->load( );408 void ConfigFileManager::load(ConfigFileType type, bool bCreateIfNotExisting) 409 { 410 this->getFile(type)->load(bCreateIfNotExisting); 379 411 this->updateConfigValues(type); 380 412 }
Note: See TracChangeset
for help on using the changeset viewer.