bool Config::loadSetting(const std::string &line, const std::string &name, Set &var) const { size_t i = isSetting(line, name, "="); if(i != std::string::npos) { var.clear(); var.insert( trim(line.substr(i)) ); return true; } i = isSetting(line, name, "+="); if(i != std::string::npos) { var.insert( trim(line.substr(i)) ); return true; } i = isSetting(line, name, "-="); if(i != std::string::npos) { Set::iterator a = var.find( trim(line.substr(i)) ); if(a != var.end()) { var.erase(a); } return true; } return false; }
bool Config::loadSetting(const std::string &line, const std::string &name, Path &var) const { size_t i = isSetting(line, name, "="); if(i == std::string::npos) { return false; } var = trim(line.substr(i)); return true; }
void initConfiguration(int argc, const char *argv[]) { /* load some more defaults from config file */ runScript(PATH_SCRIPTS, "config.lua"); runScript(PATH_SCRIPTS, "artpack.lua"); /* go for .gltronrc (or whatever is defined in RC_NAME) */ { char *path; path = getPossiblePath(PATH_PREFERENCES, RC_NAME); if (path != NULL) { if (fileExists(path)) { printf("[status] loading settings from %s\n", path); scripting_RunFile(path); } else { printf("[error] cannot load %s from %s\n", RC_NAME, path); } free(path); } else { printf("[fatal] can't get valid pref path for %s\n", RC_NAME); exit(1); // something is seriously wrong } } if(!isSetting("version") || getSettingf("version") < 0.70f) { /* load some more defaults from config file */ runScript(PATH_SCRIPTS, "config.lua"); runScript(PATH_SCRIPTS, "artpack.lua"); printf("[warning] old config file found, overriding using defaults\n"); } // check if config is valid scripting_GetGlobal("save_completed", NULL); if(scripting_IsNilResult()) { runScript(PATH_SCRIPTS, "config.lua"); runScript(PATH_SCRIPTS, "artpack.lua"); printf("[warning] defunct config file found, overriding using defaults\n"); } setSettingf("version", 0.70f); /* parse any comandline switches overrinding the loaded settings */ parse_args(argc, argv); /* sanity check some settings */ checkSettings(); /* intialize the settings cache, remember to do that everytime you change something */ updateSettingsCache(); }
bool Config::loadSetting(const std::string &line, const std::string &name, PPMap &var) const { size_t i = isSetting(line, name, "="); if(i != std::string::npos) { size_t j = line.find(':', i); if(j == std::string::npos) { return false; } var.clear(); var.insert(PPMap::value_type( trim(line.substr(i, j - i)), trim(line.substr(j + 1)) )); return true; } i = isSetting(line, name, "+="); if(i != std::string::npos) { size_t j = line.find(':', i); if(j == std::string::npos) { return false; } var.insert(PPMap::value_type( trim(line.substr(i, j - i)), trim(line.substr(j + 1)) )); return true; } i = isSetting(line, name, "-="); if(i != std::string::npos) { size_t j = line.find(':', i); if(j == std::string::npos) { return false; } PPMap::iterator a = var.find(PPMap::value_type( trim(line.substr(i, j - i)), trim(line.substr(j + 1)) )); if(a != var.end()) { var.erase(a); } return true; } return false; }
bool Config::loadSetting(const std::string &line, const std::string &name, bool &var) const { const size_t i = isSetting(line, name, "="); if(i == std::string::npos) { return false; } const std::string value = line.substr(i); if(value == "true" || value == "1" || value == "on") { var = true; } else if(value == "false" || value == "0" || value == "off") { var = false; } else { throw std::runtime_error(std::string("can not parse as boolean: ") + value); } return true; }