// constructor Config::Config() { _settings = new QSettings(getConfigFile(), QSettings::IniFormat ); _shortcuts = new ShortcutManager(_settings); // check existing config file if (!QFile::exists(getConfigFile())) { // creating conf file from set defaults QFile cf(getConfigFile()); if (cf.open(QIODevice::WriteOnly)) { cf.close(); qDebug() << "creating"; } setDefaultSettings(); saveSettings(); } _imageFormats << "png" << "jpg" << "bmp"; #if QT_VERSION >= 0x040500 _settings->setIniCodec("UTF-8"); #endif _scrNum = 0; }
Settings::~Settings() { if(changed) { std::ofstream o; o.open(getConfigFile().c_str(), ios::out | ios::trunc); if(o.is_open()) { CfgMap::iterator end = cfg.end(); for (CfgMap::const_iterator it = cfg.begin(); it != end; ++it) { std::string section(it->first); if(section.size() != 0) { o << "[" << section << "]" << endl; std::map <std::string, std::string> m = it->second; for(std::map <std::string, std::string>::iterator _it = m.begin(); _it != m.end(); _it++) { o << _it->first << "=" << _it->second << endl; } o << endl; } } o.close(); } else { cerr << "Can't update/write config file '" << getConfigFile() << "'" << endl; } } cfg.clear(); }
bool Utils::del_config_option(std::string key) { TiXmlDocument document(getConfigFile(LOCAL_CONFIG).c_str()); if (!document.LoadFile()) { cError() << "There was an exception in XML parsing."; cError() << "Parse error: " << document.ErrorDesc(); cError() << "In file " << getConfigFile(LOCAL_CONFIG) << " At line " << document.ErrorRow(); return false; } TiXmlHandle docHandle(&document); TiXmlElement *key_node = docHandle.FirstChildElement("calaos:config").FirstChildElement().ToElement(); if (key_node) { for(; key_node; key_node = key_node->NextSiblingElement()) { if (key_node->ValueStr() == "calaos:option" && key_node->Attribute("name") && key_node->Attribute("name") == key) { docHandle.FirstChild("calaos:config").Element()->RemoveChild(key_node); break; } } document.SaveFile(); } return true; }
bool Utils::get_config_options(Params &options) { TiXmlDocument document(getConfigFile(LOCAL_CONFIG).c_str()); if (!document.LoadFile()) { cError() << "There was an exception in XML parsing."; cError() << "Parse error: " << document.ErrorDesc(); cError() << "In file " << getConfigFile(LOCAL_CONFIG) << " At line " << document.ErrorRow(); return false; } TiXmlHandle docHandle(&document); TiXmlElement *key_node = docHandle.FirstChildElement("calaos:config").FirstChildElement().ToElement(); if (key_node) { for(; key_node; key_node = key_node->NextSiblingElement()) { if (key_node->ValueStr() == "calaos:option" && key_node->Attribute("name") && key_node->Attribute("value")) { options.Add(key_node->Attribute("name"), key_node->Attribute("value")); } } } return true; }
bool ConfigManager::save() { if (!_config) return true; UString file = getConfigFile(); try { // Open and save the config DumpFile config; if (!config.open(file)) throw Exception(kOpenError); _config->save(config); } catch (Exception &e) { e.add("Failed saving config file \"%s\"", file.c_str()); printException(e, "WARNING: "); return false; } // We saved our changes, so we're no in a not-changed state again _changed = false; return true; }
bool ConfigManager::load() { clear(); // Check that the config file actually exists. UString file = getConfigFile(); if (!File::exists(file)) return false; try { // Open and load the config File config; if (!config.open(file)) throw Exception(kOpenError); _config = new ConfigFile; _config->load(config); // Get the application domain _domainApp = _config->addDomain(kDomainApp); } catch (Exception &e) { e.add("Failed loading config file \"%s\"", file.c_str()); printException(e, "WARNING: "); return false; } return true; }
void Cursynth::loadConfiguration() { // Try to open the configuration file. std::ifstream config_file; config_file.open(getConfigFile().c_str()); if (!config_file.is_open()) return; // Read file contents into buffer. config_file.seekg(0, std::ios::end); int length = config_file.tellg(); config_file.seekg(0, std::ios::beg); char file_contents[length]; config_file.read(file_contents, length); // Parse the JSON configuration file. cJSON* root = cJSON_Parse(file_contents); // For all controls, try to load the MIDI learn assignment. std::string current = gui_.getCurrentControl(); std::string name = current; do { cJSON* value = cJSON_GetObjectItem(root, name.c_str()); if (value) midi_learn_[value->valueint] = name; name = gui_.getNextControl(); } while(name != current); // Delete the parsing data. cJSON_Delete(root); }
bool ConfigManager::save() { if (!_config) return true; if (!getBool("saveconf", true)) return true; // Create the directories in the path, if necessary UString file = FilePath::canonicalize(getConfigFile()); try { FilePath::createDirectories(FilePath::getDirectory(file)); // Open and save the config WriteFile config; if (!config.open(file)) throw Exception(kOpenError); save(config, true); } catch (...) { exceptionDispatcherWarning("Failed saving config file \"%s\"", file.c_str()); return false; } return true; }
std::string Utils::get_config_option(std::string _key) { std::string value = ""; TiXmlDocument document(getConfigFile(LOCAL_CONFIG).c_str()); if (!document.LoadFile()) { cError() << "There was an exception in XML parsing."; cError() << "Parse error: " << document.ErrorDesc(); cError() << " At line " << document.ErrorRow(); return value; } TiXmlHandle docHandle(&document); TiXmlElement *key_node = docHandle.FirstChildElement("calaos:config").FirstChildElement().ToElement(); if (key_node) { for(; key_node; key_node = key_node->NextSiblingElement()) { if (key_node->ValueStr() == "calaos:option" && key_node->Attribute("name") && key_node->Attribute("name") == _key && key_node->Attribute("value")) { value = key_node->Attribute("value"); break; } } } return value; }
bool ConfigManager::load() { clear(); // Check that the config file actually exists. UString file = getConfigFile(); if (!FilePath::isRegularFile(file)) return false; try { // Open and load the config ReadFile config; if (!config.open(file)) throw Exception(kOpenError); _config = new ConfigFile; _config->load(config); // Get the application domain _domainApp = _config->addDomain(kDomainApp); } catch (...) { exceptionDispatcherWarning("Failed loading config file \"%s\"", file.c_str()); return false; } return true; }
GsRenderEngine::GsRenderEngine(QObject *parent) : QObject(parent) { QString path=getConfigFile(); QSettings FicheroIni(path,QSettings::IniFormat,0); FicheroIni.beginGroup(QString("RENDER")); m_strExecutable=FicheroIni.value(QString("Application"),DEFAULT_EXECUTABLE).toString(); if (m_strExecutable.length()){ if (m_strExecutable.at(0)=='.'){ //Suponemos directorio local QString foo=m_strExecutable; foo.remove(0,1); m_strExecutable=QString("%1%2").arg(QApplication::applicationDirPath()).arg(foo); } } m_strDevice=FicheroIni.value(QString("Device"),DEFAULT_DEVICE).toString(); m_strResolution=FicheroIni.value(QString("Resolution"),DEFAULT_RESOLUTION).toString(); m_strExtraOptions=FicheroIni.value(QString("Options"),DEFAULT_OPTIONS).toString(); m_strICCFile=FicheroIni.value(QString("ICC"),DEFAULT_ICC).toString(); QString foo=FicheroIni.value(QString("Installer"),DEFAULT_INSTALLER).toString(); if (!foo.isEmpty()) { if (foo.at(0)=='.') m_strInstaller=QString("%1%2").arg(QApplication::applicationDirPath()).arg(foo.mid(1,foo.count()-1)); else m_strInstaller=QString("%1\\Installers\\%2").arg(QApplication::applicationDirPath()).arg(foo); } m_command=""; m_doubleRes=false; FicheroIni.endGroup(); }
void LoadSave::saveVarToConfig(var config_state) { File config_file = getConfigFile(); if (!config_file.exists()) config_file.create(); config_file.replaceWithText(JSON::toString(config_state)); }
bool Utils::set_config_option(std::string key, std::string value) { TiXmlDocument document(getConfigFile(LOCAL_CONFIG).c_str()); if (!document.LoadFile()) { cError() << "There was an exception in XML parsing."; cError() << "Parse error: " << document.ErrorDesc(); cError() << "In file " << getConfigFile(LOCAL_CONFIG) << " At line " << document.ErrorRow(); return false; } TiXmlHandle docHandle(&document); bool found = false; TiXmlElement *key_node = docHandle.FirstChildElement("calaos:config").FirstChildElement().ToElement(); if (key_node) { for(; key_node; key_node = key_node->NextSiblingElement()) { if (key_node->ValueStr() == "calaos:option" && key_node->Attribute("name") && key_node->Attribute("name") == key) { key_node->SetAttribute("value", value); found = true; break; } } //the option was not found, we create it if (!found) { TiXmlElement *element = new TiXmlElement("calaos:option"); element->SetAttribute("name", key); element->SetAttribute("value", value); docHandle.FirstChild("calaos:config").ToElement()->LinkEndChild(element); } document.SaveFile(); } return true; }
void Utils::initConfigOptions(char *configdir, char *cachedir, bool quiet) { if (configdir) _configBase = configdir; if (cachedir) _cacheBase = cachedir; std::string file = getConfigFile(LOCAL_CONFIG); if (!quiet) { cInfo() << "Using config path: " << getConfigFile(""); cInfo() << "Using cache path: " << getCacheFile(""); } if (!ecore_file_can_write(getConfigFile("").c_str())) throw (std::runtime_error("config path is not writable")); if (!ecore_file_can_write(getCacheFile("").c_str())) throw (std::runtime_error("cache path is not writable")); if (!fileExists(file)) { //create a defaut config std::ofstream conf(file.c_str(), std::ofstream::out); conf << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << std::endl; conf << "<calaos:config xmlns:calaos=\"http://www.calaos.fr\">" << std::endl; conf << "<calaos:option name=\"fw_version\" value=\"0\" />" << std::endl; conf << "</calaos:config>" << std::endl; conf.close(); set_config_option("fw_target", "calaos_tss"); set_config_option("fw_version", "0"); set_config_option("show_cursor", "true"); set_config_option("use_ntp", "true"); set_config_option("device_type", "calaos_server"); set_config_option("dpms_enable", "false"); set_config_option("smtp_server", ""); set_config_option("cn_user", "user"); set_config_option("cn_pass", "pass"); set_config_option("longitude", "2.322235"); set_config_option("latitude", "48.864715"); if (!quiet) std::cout << "WARNING: no local_config.xml found, generating default config with username: \"user\" and password: \"pass\"" << std::endl; } }
// CTOR creates settings hash Settings::Settings() { valid = false; changed = false; std::string line; std::string filename (getConfigFile()); std::ifstream f (filename.c_str()); if(f.is_open()) { int numSettings = 0; // we have 3 std::string section; bool enterSection = false; // only valid for the first section while(getline(f, line)) { if(StringUtils::startsWith(line, "[") && StringUtils::endsWith(line, "]")) { std::string s1 = line.substr(1); std::string s2 = s1.substr(0, s1.length()-1); section = s2; std::map< std::string, std::string > _line; cfg[section] = _line; enterSection = true; // at least one section was found } else { if(enterSection == false) continue; if(line.size() > 0) { std::vector<std::string> tokens = StringUtils::split(line, "="); if(tokens.size() >= 2) { std::string v; if(tokens.size() > 2) { // combine 1 to end for(int a = 1; a < tokens.size(); ++a) { if(a > 1) { v += "="; } v += tokens.at(a); } } else { v = tokens.at(1); } std::map< std::string, std::string > _map = cfg[section]; _map.insert(std::pair<std::string, std::string>(tokens.at(0), v)); cfg[section] = _map; numSettings++; } } } } f.close(); if( numSettings > 0 && (numSettings % 3) == 0) valid = true; } }
void ADLSearchManager::save() const { // Prepare xml string for saving try { SimpleXML xml; xml.addTag("ADLSearch"); xml.stepIn(); // Predicted several groups of searches to be differentiated // in multiple categories. Not implemented yet. xml.addTag("SearchGroup"); xml.stepIn(); // Save all searches for (auto i = collection.cbegin(); i != collection.cend(); ++i) { const ADLSearch& search = *i; if (search.searchString.empty()) { continue; } xml.addTag("Search"); xml.stepIn(); xml.addTag("SearchString", search.searchString); xml.addTag("SourceType", search.SourceTypeToString(search.sourceType)); xml.addTag("DestDirectory", search.destDir); xml.addTag("IsActive", search.isActive); xml.addTag("IsForbidden", search.isForbidden); xml.addTag("Raw", search.raw); xml.addTag("MaxSize", search.maxFileSize); xml.addTag("MinSize", search.minFileSize); xml.addTag("SizeType", search.SizeTypeToString(search.typeFileSize)); xml.addTag("IsAutoQueue", search.isAutoQueue); xml.stepOut(); } xml.stepOut(); xml.stepOut(); // Save string to file try { File fout(getConfigFile(), File::WRITE, File::CREATE | File::TRUNCATE); fout.write(SimpleXML::utf8Header); fout.write(xml.toXML()); fout.close(); } catch (const FileException&) { } } catch (const SimpleXMLException&) { } }
/** * Deletes a nick from the key store. */ bool keystore_delete_nick(const char *nick) { GKeyFile *keyfile = getConfigFile(); // Delete entry bool ok = delete_nick(keyfile, nick); // Save if (ok) save_keystore(keyfile); g_key_file_free(keyfile); return ok; }
void CharacterModel::changed(BitVector whichField, UInt32 origin) { Inherited::changed(whichField, origin); if(whichField & ConfigFileFieldMask) { _coreModel = loadConfig(getConfigFile()); if(_coreModel) { // Only need to do this once, not every time the // Cal3D Model is needed, that's why it's not // done in loadConfig() convertMaterials(getConfigFile()); CharacterModelPtr cp(this); beginEditCP(cp, NumAnimationsFieldMask); cp->setNumAnimations(_coreModel->getCoreAnimationCount()); endEditCP(cp, NumAnimationsFieldMask); } } }
var LoadSave::getConfigVar() { File config_file = getConfigFile(); var config_state; if (!JSON::parse(config_file.loadFileAsString(), config_state).wasOk()) return var(); if (!config_state.isObject()) return var(); return config_state; }
void CheckBox::applyProperty() { View::applyProperty(); QString prop; prop = getPropertyByKey("normalImage"); if(prop.isEmpty() == false) { QString imageName = getConfigFile()->getFullPath(prop); bool load = bgPixmap.load(imageName); if(!load) LOG(imageName + "加载失败"); } prop = getPropertyByKey("onChecked"); if(prop.isEmpty() == false) { } prop = getPropertyByKey("checkedImage"); if(prop.isEmpty() == false) { QString imageName = getConfigFile()->getFullPath(prop); bool load = onPixmap.load(imageName); if(!load) LOG(imageName + "加载失败"); } prop = getPropertyByKey("checked"); if(prop.isEmpty() == false) { if(prop == "false") checked = false; else if(prop == "true") checked = true; } prepareGeometryChange(); }
/** Guarda fichero de configuracion*/ void GsRenderEngine::saveConfigFile(){ QString path=getConfigFile(); if (QFile::exists(path)){ QSettings FicheroIni(path,QSettings::IniFormat,0); FicheroIni.beginGroup(QString("RENDER")); FicheroIni.setValue(QString("Application"),QString("%1").arg(m_strExecutable)); FicheroIni.setValue(QString("Device"),QString("%1").arg(m_strDevice)); FicheroIni.setValue(QString("Resolution"),QString("%1").arg(m_strResolution)); FicheroIni.setValue(QString("Options"),QString("%1").arg(m_strExtraOptions)); FicheroIni.setValue(QString("ICC"),QString("%1").arg(m_strICCFile)); FicheroIni.endGroup(); FicheroIni.sync(); } }
// constructor Config::Config() { _settings = new QSettings(getConfigFile(), QSettings::IniFormat); _shortcuts = new ShortcutManager(_settings); // check existing config file if (!QFile::exists(getConfigFile())) { // creating conf file from set defaults QFile cf(getConfigFile()); if (cf.open(QIODevice::WriteOnly)) { cf.close(); } setDefaultSettings(); saveSettings(); } _settings->setIniCodec("UTF-8"); _scrNum = 0; }
Bool ccsReadConfig (ConfigOption option, char **value) { IniDictionary *iniFile; char *entry = NULL; char *section; Bool ret; iniFile = getConfigFile(); if (!iniFile) return ccsReadGlobalConfig (option, value); switch (option) { case OptionProfile: entry = "profile"; break; case OptionBackend: entry = "backend"; break; case OptionIntegration: entry = "integration"; break; case OptionAutoSort: entry = "plugin_list_autosort"; break; default: break; } if (!entry) { ccsIniClose (iniFile); return FALSE; } *value = NULL; section = getSectionName(); ret = ccsIniGetString (iniFile, section, entry, value); free (section); ccsIniClose (iniFile); if (!ret) ret = ccsReadGlobalConfig (option, value); return ret; }
LogType::LogType(LogType& copy): LogSyslog(false) { copy.closeUdp(); setVerbose(copy.getVerbose()); setConfigFile(copy.getConfigFile()); setStorageType(copy.getStorageType()); setIpAddress(copy.getIpAddress()); setRemotePort(copy.getRemotePort()); setSourcePort(copy.getSourcePort()); setUdpBufferSize(copy.getUdpBufferSize()); __swaParser = boost::make_shared<SWAParser>( boost::bind(&LogType::callbackSWA, this, _1, _2, _3)); if (!__swaParser) { writeError ("SWA Parser not allocated"); // impossible, but if something corrupt memory. throw std::runtime_error( "Wrong log priority." ); } // check if config file exists if( !iniParse(getConfigFile()) ) { writeError ("Can't parse config FILE = %s", getConfigFile().c_str()); // impossible, but if something corrupt memory. throw std::runtime_error( "Wrong log priority." ); } __threadRun = false; __swaHelloReceive = false; __terminate = false; __udp_socket = NULL; __udp_remote_endpoint = NULL; }
/** * Extracts a key from the key store file. */ char *keystore_get_key(const char *nick) { // Get the key GKeyFile *keyfile = getConfigFile(); gchar *value = get_nick_value(keyfile, nick, "key"); g_key_file_free(keyfile); if (!value) return NULL; if (strncmp(value, "+OK ", 4) != 0) { // Key is stored in plaintext return import_glib_string(value); } else { // Key is encrypted const char *encrypted = value+4; const char *password = get_keystore_password(); char *decrypted = fish_decrypt(password, strlen(password), encrypted); g_free(value); return decrypted; } }
bool LogType::validate() { writeInfo ( "config FILE = %s", getConfigFile().c_str()); // check if config file exists if( !fileExists(getConfigFile()) ) { writeError ("Can't find config FILE = %s", getConfigFile().c_str()); return false; } // check if config file can read if( !fileReadable(getConfigFile()) ) { writeError ("Can't read from config FILE = %s", getConfigFile().c_str()); return false; } // check if config file exists if( !iniParse(getConfigFile()) ) { writeError ("Can't parse config FILE = %s", getConfigFile().c_str()); return false; } bool result = parseStorageType() && parseIpAddress() && parseRemotePort() && parseSourcePort() && parseUdpBufferSize(); if (result) { __udp_socket = new boost::asio::ip::udp::socket( __io_service, boost::asio::ip::udp::endpoint( boost::asio::ip::address::from_string(getIpAddress()), getSourcePort())); __udp_remote_endpoint = new boost::asio::ip::udp::endpoint( boost::asio::ip::udp::endpoint( boost::asio::ip::address::from_string(getIpAddress()), getRemotePort())); } return result; }
int main(int argc, char *argv[]) { int listenfd = 0, connfd = 0, n = 0, len = 0; char sendBuff[1025] = {0}; struct sockaddr_in client_addr; FILE *infile = 0; if((listenfd = serverInit()) == -1) { //error setting up server fprintf(stderr, "Error: unable to initialize server\n"); return 1; } if(!(infile = getConfigFile())) { //unable to open config file fprintf(stderr, "Cannot open config file \"%s\", make s", CONFIG_FILE); fprintf(stderr, "ure the file exists and you have read permissions.\n"); return 1; } while(1) { //loop continually to connect to client len = sizeof(client_addr); connfd = accept(listenfd, (struct sockaddr *)&client_addr, (socklen_t *)&len); printf("Client connected from IP=%s on PORT=%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); while(1) { //processing loop n = read(connfd, sendBuff, sizeof(sendBuff)); if(!n) { //client died printf("Client died, waiting for new connection\n"); close(connfd); break; } else if(n == -1) { //client hasn't sent anything yet continue; } executeInput(sendBuff, connfd, infile); }//end while sleep(1); //sleep for a tiny bit to we don't use all CPU power, hehehe }//end while fclose(infile); //close config file }//end main
void Cursynth::saveConfiguration() { confirmPathExists(getConfigPath()); // Store all the MIDI learn data into JSON. cJSON* root = cJSON_CreateObject(); std::map<int, std::string>::iterator iter = midi_learn_.begin(); for (; iter != midi_learn_.end(); ++iter) { cJSON* midi = cJSON_CreateNumber(iter->first); cJSON_AddItemToObject(root, iter->second.c_str(), midi); } // Write the configuration JSON to the configuration file. char* json = cJSON_Print(root); std::ofstream save_file; save_file.open(getConfigFile().c_str()); MOPO_ASSERT(save_file.is_open()); save_file << json; save_file.close(); free(json); cJSON_Delete(root); }
GameConfig::GameConfig(const std::string& configName, const std::string& configPath) : m_configName(configName) , m_configPath(configPath) , m_valid(false) , m_inputInvertY(false) { if (m_configPath.empty()) { m_configPath = getDefaultConfigPath(); } // Look up the path to use auto configFile = getConfigFile(); if (ini_parse(configFile.c_str(), handler, this) < 0) { m_valid = false; } else { m_valid = true; } }
/** * Sets a key in the key store file. */ bool keystore_store_key(const char *nick, const char *key) { const char *password; char *encrypted; char *wrapped; bool ok = false; GKeyFile *keyfile = getConfigFile(); // Remove old key delete_nick(keyfile, nick); // Add new key password = get_keystore_password(); if (password) { // Encrypt the password encrypted = fish_encrypt(password, strlen(password), key); if (!encrypted) goto end; // Prepend "+OK " wrapped = g_strconcat("+OK ", encrypted, NULL); g_free(encrypted); // Store encrypted in file g_key_file_set_string(keyfile, nick, "key", wrapped); free(wrapped); } else { // Store unencrypted in file g_key_file_set_string(keyfile, nick, "key", key); } // Save key store file ok = save_keystore(keyfile); end: g_key_file_free(keyfile); return ok; }