Issue #168 - Configuration cleanup - WIP

Sources update.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
actorid
Lukasz Gromanowski 13 years ago
parent 7c24ae9ac7
commit 406897aa64

@ -166,7 +166,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
if (dataDirs.empty())
{
dataDirs.push_back(cfgMgr.getDataPath("local:data?"));
dataDirs.push_back(cfgMgr.getDataPath(Files::localDataToken));
}
engine.setDataDirs(dataDirs);

@ -12,10 +12,10 @@ static const char* const openmwCfgFile = "openmw.cfg";
static const char* const ogreCfgFile = "ogre.cfg";
static const char* const pluginsCfgFile = "plugins.cfg";
static const char* const mwDataToken = "?mw:data?";
static const char* const localDataToken = "?local:data?";
static const char* const userDataToken = "?user:data?";
static const char* const globalDataToken = "?global:data?";
const char* const mwDataToken = "?mw:data?";
const char* const localDataToken = "?local:data?";
const char* const userDataToken = "?user:data?";
const char* const globalDataToken = "?global:data?";
ConfigurationManager::ConfigurationManager()
: mFixedPath("openmw")
@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager()
void ConfigurationManager::setupTokensMapping()
{
mTokensMapping.insert(std::make_pair(mwDataToken, &ConfigurationManager::getInstallPath));
mTokensMapping.insert(std::make_pair(localDataToken, &ConfigurationManager::getLocalDataPath));
mTokensMapping.insert(std::make_pair(userDataToken, &ConfigurationManager::getUserDataPath));
mTokensMapping.insert(std::make_pair(globalDataToken, &ConfigurationManager::getGlobalDataPath));
mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath));
mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath));
mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath));
mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath));
}
void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables,
@ -117,48 +117,12 @@ const boost::filesystem::path& ConfigurationManager::getDataPath(const std::stri
TokensMappingContainer::const_iterator it = mTokensMapping.find(type);
if (it != mTokensMapping.end())
{
return ((this)->*(it->second))();
return ((mFixedPath).*(it->second))();
}
return mFixedPath.getLocalDataPath();
}
const boost::filesystem::path& ConfigurationManager::getInstallPath() const
{
// TODO: It will be corrected later.
static boost::filesystem::path p("./");
return p;
//return mFixedPath.getInstallPath();
}
const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const
{
// TODO: It will be corrected later.
static boost::filesystem::path p("./");
return p;
//return mFixedPath.getGlobalDataPath();
}
const boost::filesystem::path& ConfigurationManager::getUserDataPath() const
{
// TODO: It will be corrected later.
static boost::filesystem::path p("./");
return p;
//return mFixedPath.getUserDataPath();
}
const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const
{
// TODO: It will be corrected later.
static boost::filesystem::path p("./");
return p;
//return mFixedPath.getLocalDataPath();
}
const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const
{
return mOgreCfgPath;

@ -14,6 +14,12 @@
namespace Files
{
extern const char* const mwDataToken;
extern const char* const localDataToken;
extern const char* const userDataToken;
extern const char* const globalDataToken;
/**
* \struct ConfigurationManager
*/
@ -37,7 +43,9 @@ struct ConfigurationManager
const boost::filesystem::path& getLogPath() const;
private:
typedef const boost::filesystem::path& (ConfigurationManager::*path_type_f)() const;
typedef Files::FixedPath<> FixedPathType;
typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const;
typedef std::tr1::unordered_map<std::string, path_type_f> TokensMappingContainer;
void loadConfig(const boost::filesystem::path& path,
@ -46,12 +54,7 @@ struct ConfigurationManager
void setupTokensMapping();
const boost::filesystem::path& getInstallPath() const;
const boost::filesystem::path& getGlobalDataPath() const;
const boost::filesystem::path& getUserDataPath() const;
const boost::filesystem::path& getLocalDataPath() const;
Files::FixedPath<> mFixedPath;
FixedPathType mFixedPath;
boost::filesystem::path mOgreCfgPath;
boost::filesystem::path mPluginsCfgPath;

@ -73,9 +73,10 @@ struct FixedPath
, mUserPath(mPath.getUserPath())
, mGlobalPath(mPath.getGlobalPath())
, mLocalPath(mPath.getLocalPath())
, mLocalDataPath()
, mGlobalDataPath()
, mRuntimeDataPath()
, mUserDataPath(mPath.getUserDataPath())
, mGlobalDataPath(mPath.getGlobalDataPath())
, mLocalDataPath(mPath.getLocalDataPath())
, mInstallPath(mPath.getInstallPath())
{
if (!application_name.empty())
{
@ -119,64 +120,28 @@ struct FixedPath
return mLocalPath;
}
/**
* \brief Return path pointing to the user local data directory.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getLocalDataPath() const
const boost::filesystem::path& getInstallPath() const
{
return mLocalDataPath;
}
// TODO: It will be corrected later.
static boost::filesystem::path p("./");
return p;
/**
* \brief Sets new local data path.
*
* \param [in] path - New path
*/
void setLocalDataPath(const boost::filesystem::path& path)
{
mLocalDataPath = path;
//return mFixedPath.getInstallPath();
}
/**
* \brief Return path pointing to the global (system) data directory.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getGlobalDataPath() const
{
return mGlobalDataPath;
}
/**
* \brief Sets new global (system) data directory.
*
* \param [in] path - New path
*/
void setGlobalDataPath(const boost::filesystem::path& path)
const boost::filesystem::path& getUserDataPath() const
{
mGlobalDataPath = path;
return mUserDataPath;
}
/**
* \brief Return path pointing to the directory where application was started.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getRuntimeDataPath() const
{
return mRuntimeDataPath;
}
/**
* \brief Sets new runtime data directory.
*
* \param [in] path - New path
*/
void setRuntimeDataPath(const boost::filesystem::path& path)
const boost::filesystem::path& getLocalDataPath() const
{
mRuntimeDataPath = path;
return mLocalDataPath;
}
private:
@ -186,11 +151,12 @@ struct FixedPath
boost::filesystem::path mGlobalPath; /**< Global path */
boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */
boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */
boost::filesystem::path mGlobalDataPath; /**< Global application data path */
boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files.
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;
};

@ -95,6 +95,71 @@ 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("/");
}
}
return globalDataPath;
}
boost::filesystem::path LinuxPath::getLocalDataPath() const
{
return boost::filesystem::path("./data/");
}
boost::filesystem::path LinuxPath::getInstallPath() const
{
return boost::filesystem::path("./");
}
} /* namespace Files */
#endif /* defined(__linux__) || defined(__FreeBSD__) */

@ -59,6 +59,29 @@ struct LinuxPath
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalPath() const;
/**
* \brief
*
* \return boost::filesystem::path
*/
boost::filesystem::path getUserDataPath() const;
/**
* \brief
*
* \return boost::filesystem::path
*/
boost::filesystem::path getGlobalDataPath() const;
/**
* \brief
*
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalDataPath() const;
boost::filesystem::path getInstallPath() const;
};
} /* namespace Files */

@ -69,6 +69,54 @@ 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/");
}
boost::filesystem::path MacOsPath::getInstallPath() const;
{
return boost::filesystem::path("./");
}
} /* namespace Files */
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */

@ -59,6 +59,8 @@ struct MacOsPath
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalPath() const;
boost::filesystem::path getInstallPath() const;
};
} /* namespace Files */

@ -52,6 +52,35 @@ 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;
{
return boost::filesystem::path("./");
}
} /* namespace Files */
#endif /* defined(_WIN32) || defined(__WINDOWS__) */

@ -59,6 +59,30 @@ struct WindowsPath
* \return boost::filesystem::path
*/
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
*
* \return boost::filesystem::path
*/
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;
boost::filesystem::path getInstallPath() const;
};
} /* namespace Files */

Loading…
Cancel
Save