MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / saveUserConfig

Method saveUserConfig

source/utils/ConfigManager.cpp:1304–1350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302}
1303
1304bool ConfigManager::saveUserConfig()
1305{
1306 if (mFilenameUserCfg.empty())
1307 {
1308 OD_LOG_ERR("Can't save config. The user config file isn't set.");
1309 return false;
1310 }
1311
1312 std::ofstream userFile(mFilenameUserCfg.c_str(), std::ifstream::out);
1313 if (!userFile.is_open())
1314 {
1315 OD_LOG_ERR("Couldn't open user config for writing: " + mFilenameUserCfg);
1316 return false;
1317 }
1318
1319 // Split config in categories.
1320 std::map<std::string, std::string>& mAudioUserConfig = mUserConfig.at(Config::Ctg::AUDIO);
1321 std::map<std::string, std::string>& mVideoUserConfig = mUserConfig.at(Config::Ctg::VIDEO);
1322 std::map<std::string, std::string>& mInputUserConfig = mUserConfig.at(Config::Ctg::INPUT);
1323 std::map<std::string, std::string>& mGameUserConfig = mUserConfig.at(Config::Ctg::GAME);
1324
1325 userFile << "[Configuration]" << std::endl;
1326
1327 userFile << "[Audio]" << std::endl;
1328 for(std::pair<std::string, std::string> audio : mAudioUserConfig)
1329 userFile << audio.first << "\t" << audio.second << std::endl;
1330 userFile << "[/Audio]" << std::endl;
1331
1332 userFile << "[Video]" << std::endl;
1333 for(std::pair<std::string, std::string> video : mVideoUserConfig)
1334 userFile << video.first << "\t" << video.second << std::endl;
1335 userFile << "[/Video]" << std::endl;
1336
1337 userFile << "[Input]" << std::endl;
1338 for(std::pair<std::string, std::string> input : mInputUserConfig)
1339 userFile << input.first << "\t" << input.second << std::endl;
1340 userFile << "[/Input]" << std::endl;
1341
1342 userFile << "[Game]" << std::endl;
1343 for(std::pair<std::string, std::string> input : mGameUserConfig)
1344 userFile << input.first << "\t" << input.second << std::endl;
1345 userFile << "[/Game]" << std::endl;
1346
1347 userFile << "[/Configuration]" << std::endl;
1348 userFile.close();
1349 return true;
1350}
1351
1352const std::string ConfigManager::getUserValue(Config::Ctg category,
1353 const std::string& param,

Callers 1

saveConfigMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected