void Core::saveConfiguration() { if (!tox) { qWarning() << "Core::saveConfiguration: Tox not started, aborting!"; return; } QString path = Settings::getSettingsDirPath(); QDir directory(path); if (!directory.exists() && !directory.mkpath(directory.absolutePath())) { qCritical() << "Error while creating directory " << path; return; } path += '/' + CONFIG_FILE_NAME; QSaveFile configurationFile(path); if (!configurationFile.open(QIODevice::WriteOnly)) { qCritical() << "File " << path << " cannot be opened"; return; } qDebug() << "Core: writing tox_save"; uint32_t fileSize = tox_size(tox); if (fileSize > 0 && fileSize <= INT32_MAX) { uint8_t *data = new uint8_t[fileSize]; tox_save(tox, data); configurationFile.write(reinterpret_cast<char *>(data), fileSize); configurationFile.commit(); delete[] data; } }
void Core::loadConfiguration() { QString path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME; QFile configurationFile(path); if (!configurationFile.exists()) { qWarning() << "The Tox configuration file was not found"; return; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; return; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { QByteArray data = configurationFile.readAll(); tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size()); } configurationFile.close(); // set GUI with user and statusmsg QString name = getUsername(); if (name != "") emit usernameSet(name); QString msg = getStatusMessage(); if (msg != "") emit statusMessageSet(msg); loadFriends(); }
void Core::loadConfiguration() { QString path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME; QFile configurationFile(path); if (!configurationFile.exists()) { qWarning() << "The Tox configuration file was not found"; return; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; return; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { QByteArray data = configurationFile.readAll(); tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size()); } configurationFile.close(); loadFriends(); }
void LoadConfigFileinStore(po::options_description& fileConfig, po::variables_map& vm, const std::string& configFileName) { if(!configFileName.empty()) { try { std::ifstream configurationFile(configFileName.c_str()); if(configurationFile.is_open()) { store(po::parse_config_file(configurationFile, fileConfig), vm); notify(vm); configurationFile.close(); LOGINFO("Config file loaded"); } else { LOGERROR("Impossible to load file " << configFileName); } } catch(std::exception e) { LOGERROR(e.what()); } } }
void Configurator::readGeneralConfiguration() { std::string line; std::ifstream configurationFile(CONFIGURATIONFILE); while(!configurationFile.eof()) { getline(configurationFile, line, '\n'); handleConfigurationFileLine(line); } configurationFile.close(); }
bool Core::loadConfiguration() { QString path = QDir(Settings::getSettingsDirPath()).filePath(CONFIG_FILE_NAME); QFile configurationFile(path); if (!configurationFile.exists()) { qWarning() << "The Tox configuration file was not found"; return true; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; return true; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { QByteArray data = configurationFile.readAll(); int error = tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size()); if (error < 0) { qWarning() << "Core: tox_load failed with error "<<error; } else if (error == 1) // Encrypted data save { qWarning() << "Core: Can not open encrypted tox save"; if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"), tr("Your tox profile seems to be encrypted, qTox can't open it\nDo you want to erase this profile ?"), QMessageBox::Ok | QMessageBox::Cancel)) { qWarning() << "Core: Couldn't open encrypted save, giving up"; configurationFile.close(); return false; } } } configurationFile.close(); // set GUI with user and statusmsg QString name = getUsername(); if (name != "") emit usernameSet(name); QString msg = getStatusMessage(); if (msg != "") emit statusMessageSet(msg); loadFriends(); return true; }
void Configurator::readObjectSpecificConfiguration() { std::string line; if(numberOfObjectTypes <= 0) {return;} for(int i = 0; i < numberOfObjectTypes; i++) { std::ifstream configurationFile(TYPEFOLDER + std::to_string(i + 1) + ".txt"); while(!configurationFile.eof()) { getline(configurationFile, line, '\n'); handleConfigurationFileLine(line, i); } configurationFile.close(); } }
bool Configurator::loadSettingsFile() { // check if we can read the file QFile configurationFile( _configurationFileName ); if( false == configurationFile.open(QIODevice::ReadOnly) ) return false; // loading settings file into memory if( false == _domDocument.setContent(&configurationFile) ) { configurationFile.close(); return false; } configurationFile.close(); // validating the root node QDomNode configurator = _domDocument.documentElement(); if( configurator.isNull() ) return false; if( configurator.nodeName() != c_configuratorNodeName ) return false; if( false == configurator.hasChildNodes() ) return false; // set title text QDomNamedNodeMap configuratorAttributes = configurator.attributes(); setWindowTitle( configuratorAttributes.namedItem(c_attributeTitleText).nodeValue() ); // validating and adding the sections nodes QDomNode section = configurator.firstChild(); while( false == section.isNull() ) { if( QDomNode::CommentNode != section.nodeType() ) if( false == loadSection(section) ) return false; section = section.nextSibling(); } return true; }
void Configurator::saveSettings() { QListWidget* listWidget = qobject_cast<QListWidget*>( _sections->currentWidget() ); if( 0 != listWidget ) saveItem( listWidget->currentItem() ); // cheking if we can open file for writing QFile configurationFile( _configurationFileName ); if( false == configurationFile.open(QIODevice::WriteOnly) ) return; // saving content QTextStream textStream( &configurationFile ); _domDocument.save( textStream, 4 ); configurationFile.close(); emit configurationChanged(); accept(); }
void WServer::setServerConfiguration(int argc, char *argv[], const std::string& serverConfigurationFile) { std::string wtConfigFile, appRoot; parseArgsPartially(argc, argv, serverConfigurationFile, wtConfigFile, appRoot); if (!appRoot.empty()) setAppRoot(appRoot); if (configurationFile().empty()) setConfiguration(wtConfigFile); webController_ = new Wt::WebController(*this); impl_->serverConfiguration_ = new http::server::Configuration(logger()); if (argc != 0) impl_->serverConfiguration_->setOptions(argc, argv, serverConfigurationFile); }
void Core::saveConfiguration(const QString& path) { if (QThread::currentThread() != coreThread) return (void) QMetaObject::invokeMethod(this, "saveConfiguration", Q_ARG(const QString&, path)); if (!isReady()) { qWarning() << "saveConfiguration: Tox not started, aborting!"; return; } QSaveFile configurationFile(path); if (!configurationFile.open(QIODevice::WriteOnly)) { qCritical() << "File " << path << " cannot be opened"; return; } qDebug() << "writing tox_save to " << path; uint32_t fileSize = tox_get_savedata_size(tox); bool encrypt = Settings::getInstance().getEncryptTox(); if (fileSize > 0 && fileSize <= std::numeric_limits<int32_t>::max()) { uint8_t *data = new uint8_t[fileSize]; if (encrypt) { if (!pwsaltedkeys[ptMain]) { // probably zero chance event GUI::showWarning(tr("NO Password"), tr("Local file encryption is enabled, but there is no password! It will be disabled.")); Settings::getInstance().setEncryptTox(false); tox_get_savedata(tox, data); } else { tox_get_savedata(tox, data); uint8_t* newData = new uint8_t[fileSize+TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; if (tox_pass_key_encrypt(data, fileSize, pwsaltedkeys[ptMain], newData, nullptr)) { delete[] data; data = newData; fileSize+=TOX_PASS_ENCRYPTION_EXTRA_LENGTH; } else { delete[] newData; delete[] data; qCritical() << "Core::saveConfiguration(QString): Encryption failed, couldn't save"; configurationFile.cancelWriting(); return; } } } else { tox_get_savedata(tox, data); } configurationFile.write(reinterpret_cast<char *>(data), fileSize); configurationFile.commit(); delete[] data; } Settings::getInstance().save(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); qint64 xSize(400), ySize(440); QString locale = QLocale::system().name().section('_', 0, 0); QString programLanguage = locale; QFileInfo configurationFile("WALoader.ini"); QSettings programGenericSettings("WALoader.ini", QSettings::IniFormat); if (!configurationFile.exists()) { // Let's create the file programGenericSettings.beginGroup("Program"); programGenericSettings.setValue("Language", locale); programGenericSettings.setValue("XSize", 400); programGenericSettings.setValue("YSize", 440); programGenericSettings.endGroup(); } else { programGenericSettings.beginGroup("Program"); if (programGenericSettings.contains("Language")) { programLanguage = programGenericSettings.value("Language").toString(); } else { programGenericSettings.setValue("Language", QVariant(locale)); } if (programGenericSettings.contains("XSize")) { xSize = programGenericSettings.value("XSize").toInt(); } else { programGenericSettings.setValue("XSize", QVariant(xSize)); } if (programGenericSettings.contains("YSize")) { ySize = programGenericSettings.value("YSize").toInt(); } else { programGenericSettings.setValue("YSize", QVariant(ySize)); } programGenericSettings.endGroup(); } QTranslator customTranslationFile; customTranslationFile.load(QString("WALoader_") + programLanguage); app.installTranslator(&customTranslationFile); QTranslator qtTranslationFile; qtTranslationFile.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&qtTranslationFile); WaLoaderWindow appWindow(xSize, ySize); appWindow.show(); return app.exec(); }
QByteArray Core::loadToxSave(QString path) { QByteArray data; loadPath = ""; // if not empty upon return, then user forgot a password and is switching // If we can't get a lock, then another instance is already using that profile while (!ProfileLocker::lock(QFileInfo(path).baseName())) { qWarning() << "Profile "<<QFileInfo(path).baseName()<<" is already in use, pick another"; GUI::showWarning(tr("Profile already in use"), tr("Your profile is already used by another qTox\n" "Please select another profile")); QString tmppath = Settings::getInstance().askProfiles(); if (tmppath.isEmpty()) continue; Settings::getInstance().switchProfile(tmppath); path = QDir(Settings::getSettingsDirPath()).filePath(tmppath + TOX_EXT); HistoryKeeper::resetInstance(); } QFile configurationFile(path); qDebug() << "Core::loadConfiguration: reading from " << path; if (!configurationFile.exists()) { qWarning() << "The Tox configuration file "<<path<<" was not found"; return data; } if (!configurationFile.open(QIODevice::ReadOnly)) { qCritical() << "File " << path << " cannot be opened"; return data; } qint64 fileSize = configurationFile.size(); if (fileSize > 0) { data = configurationFile.readAll(); if (tox_is_data_encrypted((uint8_t*)data.data())) { if (!loadEncryptedSave(data)) { configurationFile.close(); QString profile; do { profile = Settings::getInstance().askProfiles(); } while (profile.isEmpty()); if (!profile.isEmpty()) { Settings::getInstance().switchProfile(profile); HistoryKeeper::resetInstance(); return loadToxSave(QDir(Settings::getSettingsDirPath()).filePath(profile + TOX_EXT)); } return QByteArray(); } } } configurationFile.close(); return data; }