bool ConfigService::loadSavedConfig ( const std::string& filename, const StringConfigMap& commandLineSettings ) { S_LOG_INFO ( "Loading shared config file from " << getSharedConfigDirectory() + "/"+ filename << "." ); bool success = mGlobalConfig->readFromFile ( getSharedConfigDirectory() + "/"+ filename, varconf::GLOBAL ); std::string userConfigPath ( getHomeDirectory() + "/" + filename ); std::ifstream file ( userConfigPath.c_str() ); if ( !file.fail() ) { S_LOG_INFO ( "Loading user config file from "<< getHomeDirectory() + "/" + filename <<"." ); try { mUserConfig->parseStream ( file, varconf::USER ); } catch ( varconf::ParseError& p ) { S_LOG_FAILURE ( "Error loading user config file: " << p ); success = false; } } else { S_LOG_INFO ( "Could not find any user config file." ); } //after loading the config from file, override with command time settings for (StringConfigMap::const_iterator I = commandLineSettings.begin(); I != commandLineSettings.end(); ++I) { for (std::map<std::string, std::string>::const_iterator J = I->second.begin(); J != I->second.end(); ++J) { S_LOG_INFO("Setting command line config option " << I->first << ":" << J->first << " to " << J->second); mCommandLineConfig->setItem(I->first, J->first, J->second); EventChangedConfigItem(I->first, J->first); } } return success; }
VCMIDirs::VCMIDirs() { // initialize local directory and create folders to which VCMI needs write access boost::filesystem::create_directory(userDataPath()); boost::filesystem::create_directory(userCachePath()); boost::filesystem::create_directory(userConfigPath()); boost::filesystem::create_directory(userSavePath()); }
bool PointsLoader::loadPointsConfig(const std::string &mapPointsConfigPath) { m_mapPoints.clear(); m_userPoints.clear(); m_userPointsDirty = false; m_userConfigPath = userConfigPath(mapPointsConfigPath); loadMapPoints(mapPointsConfigPath); loadUserPoints(m_userConfigPath); return true; }
static bool initSettings(SettingsFile *settings, QLockFile **lockFile, QString &errorMessage) { /* If built in portable mode (default), configuration is stored in the 'config' * directory next to the binary. If not writable, launching fails. * * Portable OS X is an exception. In that case, configuration is stored in a * 'config.ricochet' folder next to the application bundle, unless the application * path contains "/Applications", in which case non-portable mode is used. * * When not in portable mode, a platform-specific per-user config location is used. * * This behavior may be overriden by passing a folder path as the first argument. */ QString configPath; QStringList args = qApp->arguments(); if (args.size() > 1) { configPath = args[1]; } else { #ifndef RICOCHET_NO_PORTABLE # ifdef Q_OS_MAC if (!qApp->applicationDirPath().contains(QStringLiteral("/Applications"))) { // Try old configuration path first configPath = appBundlePath() + QStringLiteral("config.torsion"); if (!QFile::exists(configPath)) configPath = appBundlePath() + QStringLiteral("config.ricochet"); } # else configPath = qApp->applicationDirPath() + QStringLiteral("/config"); # endif #endif if (configPath.isEmpty()) configPath = userConfigPath(); } QDir dir(configPath); if (!dir.exists() && !dir.mkpath(QStringLiteral("."))) { errorMessage = QStringLiteral("Cannot create directory: %1").arg(dir.path()); return false; } // Reset to config directory for consistency; avoid depending on this behavior for paths if (QDir::setCurrent(dir.absolutePath()) && dir.isRelative()) dir.setPath(QStringLiteral(".")); QLockFile *lock = new QLockFile(dir.filePath(QStringLiteral("ricochet.json.lock"))); *lockFile = lock; lock->setStaleLockTime(0); if (!lock->tryLock()) { if (lock->error() == QLockFile::LockFailedError) { // XXX Need to offer UI or heuristics for removeStaleLockFile errorMessage = QStringLiteral("Configuration file is already in use"); } else { errorMessage = QStringLiteral("Cannot write configuration file (failed to acquire lock)"); } return false; } settings->setFilePath(dir.filePath(QStringLiteral("ricochet.json"))); if (settings->hasError()) { errorMessage = settings->errorMessage(); return false; } if (settings->root()->data().isEmpty()) { QString filePath = dir.filePath(QStringLiteral("Torsion.ini")); if (!QFile::exists(filePath)) filePath = dir.filePath(QStringLiteral("ricochet.ini")); if (QFile::exists(filePath)) importLegacySettings(settings, filePath); } return true; }