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 <lgromanowski@gmail.com>
actorid
Lukasz Gromanowski 13 years ago
parent 80008ed09f
commit 0c0b594090

@ -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);

@ -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);

@ -5,6 +5,11 @@
#include <iostream>
#include <algorithm>
#include <boost/bind.hpp>
/**
* \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<const boost::filesystem::path&, bool>
{
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();

@ -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;
};

@ -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/";

@ -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.
*

@ -28,6 +28,10 @@
#include <pwd.h>
#include <unistd.h>
/**
* 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;

@ -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;
};

@ -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("");

@ -39,7 +39,8 @@ namespace Files
struct WindowsPath
{
/**
* \brief Returns "X:\Documents And Settings\<User name>\My Documents\My Games\"
* \brief Returns user path i.e.:
* "X:\Documents And Settings\<User name>\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.
*

Loading…
Cancel
Save