Issue #168: Configuration cleanup, part 2

pull/21/head
Lukasz Gromanowski 14 years ago
parent 8c621298a2
commit 54cb6deab9

@ -147,37 +147,19 @@ void GraphicsPage::createPages()
void GraphicsPage::setupConfig() void GraphicsPage::setupConfig()
{ {
QString ogreCfg = (mCfg.getRuntimeConfigPath() / "ogre.cfg").string().c_str(); QString ogreCfg = mCfg.getOgreConfigPath().string().c_str();
QFile file(ogreCfg); QFile file(ogreCfg);
if (!file.exists()) {
ogreCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "ogre.cfg").string());
}
mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat);
} }
void GraphicsPage::setupOgre() void GraphicsPage::setupOgre()
{ {
QString pluginCfg = (mCfg.getRuntimeConfigPath() / "plugins.cfg").string().c_str(); QString pluginCfg = mCfg.getPluginsConfigPath().string().c_str();
QFile file(pluginCfg); QFile file(pluginCfg);
if (!file.exists()) {
pluginCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "plugins.cfg").string());
}
// Reopen the file from user directory
file.setFileName(pluginCfg);
if (!file.exists()) {
// There's no plugins.cfg in the user directory, use global directory
pluginCfg = QString::fromStdString((mCfg.getGlobalConfigPath() / "plugins.cfg").string());
}
// Create a log manager so we can surpress debug text to stdout/stderr // Create a log manager so we can surpress debug text to stdout/stderr
Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager; Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager;
logMgr->createLog("launcherOgre.log", true, false, false); logMgr->createLog((mCfg.getLogPath().string() + "/launcherOgre.log"), true, false, false);
try try
{ {
@ -475,4 +457,4 @@ void GraphicsPage::rendererChanged(const QString &renderer)
} }
mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString());
} }

@ -327,25 +327,6 @@ void OMW::Engine::setNewGame(bool newGame)
mNewGame = newGame; mNewGame = newGame;
} }
std::string OMW::Engine::getOgreFilesDir(const std::string& ogreFile)
{
boost::filesystem::path cfgPath(mCfgMgr.getRuntimeConfigPath());
if (!boost::filesystem::exists(cfgPath / ogreFile))
{
cfgPath = mCfgMgr.getLocalConfigPath();
if (!boost::filesystem::exists(cfgPath / ogreFile ))
{
cfgPath = mCfgMgr.getGlobalConfigPath();
if (!boost::filesystem::exists(cfgPath / ogreFile))
{
cfgPath.clear();
}
}
}
return (!cfgPath.empty()) ? cfgPath.string() + std::string("/") : std::string();
}
// Initialise and enter main loop. // Initialise and enter main loop.
void OMW::Engine::go() void OMW::Engine::go()
@ -357,11 +338,10 @@ void OMW::Engine::go()
test.name = ""; test.name = "";
total = 0; total = 0;
mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()),
std::string cfgDir(getOgreFilesDir("ogre.cfg")); mCfgMgr.getOgreConfigPath().string(),
std::string pluginsFile(getOgreFilesDir("plugins.cfg") + std::string("plugins.cfg")); mCfgMgr.getLogPath().string() + std::string("/"),
mCfgMgr.getPluginsConfigPath().string(), false);
mOgre.configure(cfgDir.empty(), cfgDir, pluginsFile, false);
// This has to be added BEFORE MyGUI is initialized, as it needs // This has to be added BEFORE MyGUI is initialized, as it needs
// to find core.xml here. // to find core.xml here.
@ -381,7 +361,9 @@ void OMW::Engine::go()
mResDir, mNewGame, mEnvironment, mEncoding); mResDir, mNewGame, mEnvironment, mEncoding);
// Set up the GUI system // Set up the GUI system
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, cfgDir); mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false,
mCfgMgr.getLogPath().string() + std::string("/"));
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");

@ -157,8 +157,6 @@ namespace OMW
void setEncoding(const std::string& encoding); void setEncoding(const std::string& encoding);
private: private:
std::string getOgreFilesDir(const std::string& ogreFile);
Cfg::ConfigurationManager& mCfgMgr; Cfg::ConfigurationManager& mCfgMgr;
}; };
} }

@ -109,12 +109,12 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio
bpo::variables_map variables; bpo::variables_map variables;
cfgMgr.readConfiguration(variables, desc);
// Runtime options override settings from all configs // Runtime options override settings from all configs
bpo::store(valid_opts, variables); bpo::store(valid_opts, variables);
bpo::notify(variables); bpo::notify(variables);
cfgMgr.readConfiguration(variables, desc);
bool run = true; bool run = true;
if (variables.count ("help")) if (variables.count ("help"))

@ -15,19 +15,47 @@ static const char* const pluginsCfgFile = "plugins.cfg";
ConfigurationManager::ConfigurationManager() ConfigurationManager::ConfigurationManager()
: mPath("openmw") : mPath("openmw")
{ {
/**
* According to task #168 plugins.cfg file shall be located in global
* configuration path or in runtime configuration path.
*/
mPluginsCfgPath = mPath.getGlobalConfigPath() / pluginsCfgFile;
if (!boost::filesystem::is_regular_file(mPluginsCfgPath))
{
mPluginsCfgPath = mPath.getRuntimeConfigPath() / pluginsCfgFile;
if (!boost::filesystem::is_regular_file(mPluginsCfgPath))
{
std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl;
mPluginsCfgPath.clear();
}
}
/**
* According to task #168 ogre.cfg file shall be located only
* in user configuration path.
*/
mOgreCfgPath = mPath.getLocalConfigPath() / ogreCfgFile;
mLogPath = mPath.getLocalConfigPath();
} }
ConfigurationManager::~ConfigurationManager() ConfigurationManager::~ConfigurationManager()
{ {
} }
void setupPath(const char* const cfgFile, boost::filesystem::path& path)
{
}
void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables,
boost::program_options::options_description& description) boost::program_options::options_description& description)
{ {
loadConfig(mPath.getGlobalConfigPath(), variables, description);
loadConfig(mPath.getLocalConfigPath(), variables, description); loadConfig(mPath.getLocalConfigPath(), variables, description);
boost::program_options::notify(variables);
loadConfig(mPath.getRuntimeConfigPath(), variables, description); loadConfig(mPath.getRuntimeConfigPath(), variables, description);
boost::program_options::notify(variables); boost::program_options::notify(variables);
loadConfig(mPath.getGlobalConfigPath(), variables, description);
boost::program_options::notify(variables);
} }
void ConfigurationManager::loadConfig(const boost::filesystem::path& path, void ConfigurationManager::loadConfig(const boost::filesystem::path& path,
@ -115,4 +143,19 @@ void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& new
mPath.setRuntimeDataPath(newPath); mPath.setRuntimeDataPath(newPath);
} }
const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const
{
return mOgreCfgPath;
}
const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const
{
return mPluginsCfgPath;
}
const boost::filesystem::path& ConfigurationManager::getLogPath() const
{
return mLogPath;
}
} /* namespace Cfg */ } /* namespace Cfg */

@ -41,12 +41,20 @@ struct ConfigurationManager
const boost::filesystem::path& getRuntimeDataPath() const; const boost::filesystem::path& getRuntimeDataPath() const;
void setRuntimeDataPath(const boost::filesystem::path& newPath); void setRuntimeDataPath(const boost::filesystem::path& newPath);
const boost::filesystem::path& getOgreConfigPath() const;
const boost::filesystem::path& getPluginsConfigPath() const;
const boost::filesystem::path& getLogPath() const;
private: private:
void loadConfig(const boost::filesystem::path& path, void loadConfig(const boost::filesystem::path& path,
boost::program_options::variables_map& variables, boost::program_options::variables_map& variables,
boost::program_options::options_description& description); boost::program_options::options_description& description);
Files::Path<> mPath; Files::Path<> mPath;
boost::filesystem::path mOgreCfgPath;
boost::filesystem::path mPluginsCfgPath;
boost::filesystem::path mLogPath;
}; };
} /* namespace Cfg */ } /* namespace Cfg */

Loading…
Cancel
Save