From 54cb6deab95fcc9f2690b7a98a6cd7f87b8fb818 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 2 Sep 2011 20:01:24 +0200 Subject: [PATCH 1/2] Issue #168: Configuration cleanup, part 2 --- apps/launcher/graphicspage.cpp | 26 +++----------- apps/openmw/engine.cpp | 32 ++++-------------- apps/openmw/engine.hpp | 2 -- apps/openmw/main.cpp | 4 +-- components/cfg/configurationmanager.cpp | 45 ++++++++++++++++++++++++- components/cfg/configurationmanager.hpp | 8 +++++ 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 622b00ef5..300be2791 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -147,37 +147,19 @@ void GraphicsPage::createPages() void GraphicsPage::setupConfig() { - QString ogreCfg = (mCfg.getRuntimeConfigPath() / "ogre.cfg").string().c_str(); + QString ogreCfg = mCfg.getOgreConfigPath().string().c_str(); QFile file(ogreCfg); - - if (!file.exists()) { - ogreCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "ogre.cfg").string()); - } - mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); - } void GraphicsPage::setupOgre() { - QString pluginCfg = (mCfg.getRuntimeConfigPath() / "plugins.cfg").string().c_str(); + QString pluginCfg = mCfg.getPluginsConfigPath().string().c_str(); 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 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 { @@ -475,4 +457,4 @@ void GraphicsPage::rendererChanged(const QString &renderer) } mSelectedRenderSystem = mOgre->getRenderSystemByName(renderer.toStdString()); -} \ No newline at end of file +} diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 4854eae91..03e8a6838 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -327,25 +327,6 @@ void OMW::Engine::setNewGame(bool 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. void OMW::Engine::go() @@ -357,11 +338,10 @@ void OMW::Engine::go() test.name = ""; total = 0; - - std::string cfgDir(getOgreFilesDir("ogre.cfg")); - std::string pluginsFile(getOgreFilesDir("plugins.cfg") + std::string("plugins.cfg")); - - mOgre.configure(cfgDir.empty(), cfgDir, pluginsFile, false); + mOgre.configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), + mCfgMgr.getOgreConfigPath().string(), + mCfgMgr.getLogPath().string() + std::string("/"), + mCfgMgr.getPluginsConfigPath().string(), false); // This has to be added BEFORE MyGUI is initialized, as it needs // to find core.xml here. @@ -381,7 +361,9 @@ void OMW::Engine::go() mResDir, mNewGame, mEnvironment, mEncoding); // 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("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 9ee3298d7..306c475e1 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -157,8 +157,6 @@ namespace OMW void setEncoding(const std::string& encoding); private: - std::string getOgreFilesDir(const std::string& ogreFile); - Cfg::ConfigurationManager& mCfgMgr; }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 3fef2b0bd..ff5725690 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -109,12 +109,12 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio bpo::variables_map variables; - cfgMgr.readConfiguration(variables, desc); - // Runtime options override settings from all configs bpo::store(valid_opts, variables); bpo::notify(variables); + cfgMgr.readConfiguration(variables, desc); + bool run = true; if (variables.count ("help")) diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp index 7c210f72c..9b4aa5a26 100644 --- a/components/cfg/configurationmanager.cpp +++ b/components/cfg/configurationmanager.cpp @@ -15,19 +15,47 @@ static const char* const pluginsCfgFile = "plugins.cfg"; ConfigurationManager::ConfigurationManager() : 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() { } +void setupPath(const char* const cfgFile, boost::filesystem::path& path) +{ +} + void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, boost::program_options::options_description& description) { - loadConfig(mPath.getGlobalConfigPath(), variables, description); loadConfig(mPath.getLocalConfigPath(), variables, description); + boost::program_options::notify(variables); loadConfig(mPath.getRuntimeConfigPath(), variables, description); boost::program_options::notify(variables); + loadConfig(mPath.getGlobalConfigPath(), variables, description); + boost::program_options::notify(variables); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -115,4 +143,19 @@ void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& new 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 */ diff --git a/components/cfg/configurationmanager.hpp b/components/cfg/configurationmanager.hpp index f0123d48a..7f13d0914 100644 --- a/components/cfg/configurationmanager.hpp +++ b/components/cfg/configurationmanager.hpp @@ -41,12 +41,20 @@ struct ConfigurationManager const boost::filesystem::path& getRuntimeDataPath() const; 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: void loadConfig(const boost::filesystem::path& path, boost::program_options::variables_map& variables, boost::program_options::options_description& description); Files::Path<> mPath; + + boost::filesystem::path mOgreCfgPath; + boost::filesystem::path mPluginsCfgPath; + boost::filesystem::path mLogPath; }; } /* namespace Cfg */ From d43455fd571ec2567040fa7468525e846868e512 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 2 Sep 2011 22:45:21 +0200 Subject: [PATCH 2/2] Issue #168: Configuration cleanup, part 2 Corrected --data and --data-local parameters handling. Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 12 ++++++------ apps/openmw/engine.cpp | 10 ++++------ apps/openmw/engine.hpp | 2 +- apps/openmw/main.cpp | 8 ++++---- components/files/collections.cpp | 2 +- components/files/collections.hpp | 7 ++----- components/files/multidircollection.cpp | 16 ++++++++++------ components/files/multidircollection.hpp | 4 +++- 8 files changed, 31 insertions(+), 30 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 2abe0aed4..7f4662e42 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -127,7 +127,7 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) { // Put the paths in a boost::filesystem vector to use with Files::Collections - std::vector dataDirs; + Files::PathContainer dataDirs; foreach (const QString ¤tPath, paths) { dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); @@ -142,8 +142,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) { - std::string filename = boost::filesystem::path (iter->second.filename()).string(); - QString currentMaster = QString::fromStdString(filename); + QString currentMaster = QString::fromStdString( + boost::filesystem::path (iter->second.filename()).string()); const QList itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly); @@ -164,7 +164,7 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) ESMReader fileReader; QStringList availableMasters; // Will contain all found masters - fileReader.setEncoding("win1252"); + fileReader.setEncoding("win1252"); // FIXME: This should be configurable! fileReader.open(iter->second.string()); // First we fill the availableMasters and the mMastersWidget @@ -190,8 +190,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) // Now we put the current plugin in the mDataFilesModel under its masters QStandardItem *parent = new QStandardItem(availableMasters.join(",")); - std::string filename = boost::filesystem::path (iter->second.filename()).string(); - QStandardItem *child = new QStandardItem(QString::fromStdString(std::string(filename))); + QStandardItem *child = new QStandardItem(QString::fromStdString( + boost::filesystem::path (iter->second.filename()).string())); const QList masterList = mDataFilesModel->findItems(availableMasters.join(",")); diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 03e8a6838..e9ceea2f3 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -252,9 +252,8 @@ void OMW::Engine::loadBSA() Bsa::addBSA (iter->second.string()); } - std::string m = mDataDir.string(); - std::cout << "Data dir" << m << "\n"; - Bsa::addDir(m, mFSStrict); + std::cout << "Data dir " << mDataDir.string() << std::endl; + Bsa::addDir(mDataDir.string(), mFSStrict); } // add resources directory @@ -273,12 +272,11 @@ void OMW::Engine::enableFSStrict(bool fsStrict) // Set data dir -void OMW::Engine::setDataDirs (const std::vector& dataDirs) +void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs) { /// \todo remove mDataDir, once resources system can handle multiple directories assert (!dataDirs.empty()); - mDataDir = dataDirs[0]; - + mDataDir = dataDirs.back(); mFileCollections = Files::Collections (dataDirs, !mFSStrict); } diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 306c475e1..3df0d0b3a 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -115,7 +115,7 @@ namespace OMW void enableFSStrict(bool fsStrict); /// Set data dirs - void setDataDirs(const Files::Collections::PathContainer& dataDirs); + void setDataDirs(const Files::PathContainer& dataDirs); /// Set resource dir void setResourceDir(const boost::filesystem::path& parResDir); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index ff5725690..aa8b13b80 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -57,7 +57,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio desc.add_options() ("help", "print help message") ("version", "print version information and quit") - ("data", bpo::value()->default_value(Files::Collections::PathContainer(), "data") + ("data", bpo::value()->default_value(Files::PathContainer(), "data") ->multitoken(), "set data directories (later directories have higher priority)") ("data-local", bpo::value()->default_value(""), @@ -153,17 +153,17 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio // directory settings engine.enableFSStrict(variables["fs-strict"].as()); - Files::Collections::PathContainer dataDirs = variables["data"].as(); + Files::PathContainer dataDirs(variables["data"].as()); std::string local(variables["data-local"].as()); if (!local.empty()) { - dataDirs.push_back(local); + dataDirs.push_back(Files::PathContainer::value_type(local)); } if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath().string()); + dataDirs.push_back(cfgMgr.getLocalDataPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/collections.cpp b/components/files/collections.cpp index cb32768b4..424b558e6 100644 --- a/components/files/collections.cpp +++ b/components/files/collections.cpp @@ -10,7 +10,7 @@ namespace Files { } - Collections::Collections(const std::vector& directories, bool foldCase) + Collections::Collections(const Files::PathContainer& directories, bool foldCase) : mDirectories(directories) , mFoldCase(foldCase) , mCollections() diff --git a/components/files/collections.hpp b/components/files/collections.hpp index 102ab3050..1ddca9a5b 100644 --- a/components/files/collections.hpp +++ b/components/files/collections.hpp @@ -1,7 +1,6 @@ #ifndef COMPONENTS_FILES_COLLECTION_HPP #define COMPONENTS_FILES_COLLECTION_HPP -#include #include #include #include @@ -13,12 +12,10 @@ namespace Files class Collections { public: - typedef std::vector PathContainer; - Collections(); ///< Directories are listed with increasing priority. - Collections(const PathContainer& directories, bool foldCase); + Collections(const Files::PathContainer& directories, bool foldCase); ///< Return a file collection for the given extension. Extension must contain the /// leading dot and must be all lower-case. @@ -26,7 +23,7 @@ namespace Files private: typedef std::map MultiDirCollectionContainer; - PathContainer mDirectories; + Files::PathContainer mDirectories; bool mFoldCase; mutable MultiDirCollectionContainer mCollections; diff --git a/components/files/multidircollection.cpp b/components/files/multidircollection.cpp index 9a0d31c42..c64f64376 100644 --- a/components/files/multidircollection.cpp +++ b/components/files/multidircollection.cpp @@ -39,21 +39,25 @@ namespace Files } }; - MultiDirCollection::MultiDirCollection (const std::vector& directories, + MultiDirCollection::MultiDirCollection(const Files::PathContainer& directories, const std::string& extension, bool foldCase) : mFiles (NameLess (!foldCase)) { NameEqual equal (!foldCase); - for (std::vector::const_iterator iter = directories.begin(); + for (PathContainer::const_iterator iter = directories.begin(); iter!=directories.end(); ++iter) { - boost::filesystem::path dataDirectory = *iter; + if (!boost::filesystem::is_directory(*iter)) + { + std::cout << "Skipping invalid directory: " << (*iter).string() << std::endl; + continue; + } - for (boost::filesystem::directory_iterator iter (dataDirectory); - iter!=boost::filesystem::directory_iterator(); ++iter) + for (boost::filesystem::directory_iterator dirIter(*iter); + dirIter != boost::filesystem::directory_iterator(); ++dirIter) { - boost::filesystem::path path = *iter; + boost::filesystem::path path = *dirIter; if (!equal (extension, boost::filesystem::path (path.extension()).string())) continue; diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index 898700c06..391f8b6a4 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -11,6 +11,8 @@ namespace Files { + typedef std::vector PathContainer; + struct NameLess { bool mStrict; @@ -58,7 +60,7 @@ namespace Files public: - MultiDirCollection (const std::vector& directories, + MultiDirCollection (const Files::PathContainer& directories, const std::string& extension, bool foldCase); ///< Directories are listed with increasing priority. /// \param extension The extension that should be listed in this collection. Must