From 0c0b5940908c2ea385a9564fd02431d27792bd85 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 19 Feb 2012 23:39:37 +0100 Subject: [PATCH] Issue #168 - Configuration cleanup Removed unnecessary path methods - according to forum disscusion: http://openmw.org/forum/viewtopic.php?f=6&t=448 Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 2 + apps/openmw/main.cpp | 2 +- components/files/configurationmanager.cpp | 56 ++++--------- components/files/fixedpath.hpp | 20 +---- components/files/linuxpath.cpp | 97 +++-------------------- components/files/linuxpath.hpp | 14 ---- components/files/macospath.cpp | 44 +--------- components/files/macospath.hpp | 7 ++ components/files/windowspath.cpp | 26 ++---- components/files/windowspath.hpp | 18 +---- 10 files changed, 50 insertions(+), 236 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 8b59f1b81..6eb459037 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -135,6 +135,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); } + mCfgMgr.processPaths(dataDirs); + // Create a file collection for the dataDirs Files::Collections mFileCollections(dataDirs, strict); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 9f70fac15..6bdfdd91f 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -167,7 +167,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath()); + dataDirs.push_back(cfgMgr.getLocalPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46cd0e053..c5561d652 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -5,6 +5,11 @@ #include #include +#include + +/** + * \namespace Files + */ namespace Files { @@ -22,10 +27,6 @@ ConfigurationManager::ConfigurationManager() { setupTokensMapping(); - /** - * According to task #168 plugins.cfg file shall be located in global - * configuration path or in local configuration path. - */ mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) { @@ -37,15 +38,7 @@ ConfigurationManager::ConfigurationManager() } } - /** - * According to task #168 ogre.cfg file shall be located only - * in user configuration path. - */ mOgreCfgPath = mFixedPath.getUserPath() / ogreCfgFile; - - /** - * FIXME: Logs shoudn't be stored in the same dir where configuration is placed. - */ mLogPath = mFixedPath.getUserPath(); } @@ -56,8 +49,8 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } @@ -74,14 +67,6 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m } -struct EmptyPath : public std::unary_function -{ - bool operator()(const boost::filesystem::path& path) const - { - return path.empty(); - } -}; - void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) { for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) @@ -105,14 +90,7 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) tempPath /= path.substr(pos + 1, path.length() - pos); } - if (boost::filesystem::is_directory(tempPath)) - { - (*it) = tempPath; - } - else - { - (*it).clear(); - } + *it = tempPath; } else { @@ -121,9 +99,15 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) } } } + + if (!boost::filesystem::is_directory(*it)) + { + (*it).clear(); + } } - dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end()); + dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), + boost::bind(&boost::filesystem::path::empty, _1)), dataDirs.end()); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -171,16 +155,6 @@ const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const return mFixedPath.getGlobalDataPath(); } -const boost::filesystem::path& ConfigurationManager::getUserDataPath() const -{ - return mFixedPath.getUserDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ - return mFixedPath.getLocalDataPath(); -} - const boost::filesystem::path& ConfigurationManager::getInstallPath() const { return mFixedPath.getInstallPath(); diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 0e052fd24..4e054b17f 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -73,9 +73,7 @@ struct FixedPath , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) - , mUserDataPath(mPath.getUserDataPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) - , mLocalDataPath(mPath.getLocalDataPath()) , mInstallPath(mPath.getInstallPath()) { if (!application_name.empty()) @@ -84,9 +82,6 @@ struct FixedPath mUserPath /= suffix; mGlobalPath /= suffix; - - mLocalDataPath /= suffix; - mUserDataPath /= suffix; mGlobalDataPath /= suffix; } } @@ -131,16 +126,6 @@ struct FixedPath return mGlobalDataPath; } - const boost::filesystem::path& getUserDataPath() const - { - return mUserDataPath; - } - - const boost::filesystem::path& getLocalDataPath() const - { - return mLocalDataPath; - } - private: PathType mPath; @@ -148,11 +133,8 @@ struct FixedPath boost::filesystem::path mGlobalPath; /**< Global path */ boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ - boost::filesystem::path mUserDataPath; /**< User data path */ boost::filesystem::path mGlobalDataPath; /**< Global application data path */ - boost::filesystem::path mLocalDataPath; /**< Local path to the configuration files. - By default it is a 'data' directory in same - directory where application was run */ + boost::filesystem::path mInstallPath; }; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 41891661e..0b315ccfb 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -41,29 +41,19 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); - const char* theDir = getenv("OPENMW_CONFIG"); + const char* theDir = getenv("HOME"); if (theDir == NULL) { - theDir = getenv("XDG_CONFIG_HOME"); - if (theDir == NULL) + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.config/"); - } + theDir = pwd->pw_dir; } } - if (theDir != NULL) { + if (theDir != NULL) + { + suffix = boost::filesystem::path("/.config/"); userPath = boost::filesystem::path(theDir); } @@ -74,20 +64,7 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path LinuxPath::getGlobalPath() const { - boost::filesystem::path globalPath("/etc/xdg/"); - - char* theDir = getenv("XDG_CONFIG_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalPath = boost::filesystem::path(ptr); - globalPath /= boost::filesystem::path("/"); - } - } - + boost::filesystem::path globalPath("/etc/"); return globalPath; } @@ -96,65 +73,12 @@ boost::filesystem::path LinuxPath::getLocalPath() const return boost::filesystem::path("./"); } -boost::filesystem::path LinuxPath::getUserDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("XDG_DATA_HOME"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.local/share/"); - } - } - } - - if (theDir != NULL) { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - boost::filesystem::path LinuxPath::getGlobalDataPath() const { - boost::filesystem::path globalDataPath("/usr/local/share/"); - - char* theDir = getenv("XDG_DATA_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalDataPath = boost::filesystem::path(ptr); - globalDataPath /= boost::filesystem::path("/"); - } - } - + boost::filesystem::path globalDataPath("/usr/share/games/"); return globalDataPath; } -boost::filesystem::path LinuxPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - boost::filesystem::path LinuxPath::getInstallPath() const { boost::filesystem::path installPath; @@ -211,7 +135,8 @@ boost::filesystem::path LinuxPath::getInstallPath() const if (!mwpath.empty()) { - // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + // Change drive letter to lowercase, so we could use + // ~/.wine/dosdevices symlinks mwpath[0] = tolower(mwpath[0]); installPath /= homePath; installPath /= ".wine/dosdevices/"; diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 71f45ae32..873f8801d 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -60,13 +60,6 @@ struct LinuxPath */ boost::filesystem::path getLocalPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getUserDataPath() const; - /** * \brief * @@ -74,13 +67,6 @@ struct LinuxPath */ boost::filesystem::path getGlobalDataPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - /** * \brief Gets the path of the installed Morrowind version if there is one. * diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 789c87709..6225fc01f 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -28,6 +28,10 @@ #include #include +/** + * FIXME: Someone with MacOS system should check this and correct if necessary + */ + /** * \namespace Files */ @@ -69,52 +73,12 @@ boost::filesystem::path MacOsPath::getLocalPath() const return boost::filesystem::path("./"); } -boost::filesystem::path MacOsPath::getUserDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/Library/Application Support/"); - } - } - - if (theDir != NULL) - { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - boost::filesystem::path MacOsPath::getGlobalDataPath() const { boost::filesystem::path globalDataPath("/Library/Application Support/"); return globalDataPath; } -boost::filesystem::path MacOsPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - -/** - * FIXME: This should be verified on MacOS system! - */ boost::filesystem::path MacOsPath::getInstallPath() const { boost::filesystem::path installPath; diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 2194dbb94..7656538c1 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -60,6 +60,13 @@ struct MacOsPath */ boost::filesystem::path getLocalPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + boost::filesystem::path getInstallPath() const; }; diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 9bb66a3cb..e81041272 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,6 +10,13 @@ #pragma comment(lib, "Shlwapi.lib") +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ + +/** + * \namespace Files + */ namespace Files { @@ -55,30 +62,11 @@ boost::filesystem::path WindowsPath::getLocalPath() const return boost::filesystem::path("./"); } -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ -boost::filesystem::path WindowsPath::getUserDataPath() const -{ - return getUserConfigPath(); -} - -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ boost::filesystem::path WindowsPath::getGlobalDataPath() const { return getGlobalConfigPath(); } -/** - * FIXME: Someone with Windows system should check this and correct if necessary - */ -boost::filesystem::path WindowsPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - boost::filesystem::path WindowsPath::getInstallPath() const { boost::filesystem::path installPath(""); diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 0240de257..919d087f1 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -39,7 +39,8 @@ namespace Files struct WindowsPath { /** - * \brief Returns "X:\Documents And Settings\\My Documents\My Games\" + * \brief Returns user path i.e.: + * "X:\Documents And Settings\\My Documents\My Games\" * * \return boost::filesystem::path */ @@ -60,13 +61,6 @@ struct WindowsPath */ boost::filesystem::path getLocalPath() const; - /** - * \brief Return same path like getUserConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getUserDataPath() const; - /** * \brief Return same path like getGlobalConfigPath * @@ -74,14 +68,6 @@ struct WindowsPath */ boost::filesystem::path getGlobalDataPath() const; - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - /** * \brief Gets the path of the installed Morrowind version if there is one. *