1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 13:09:40 +00:00

Issue #168 - Configuration cleanup

Corrected tokens processing. If directory exist then tokens
shall be replaced by correct path, otherwise they are silently
removed from path container.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
This commit is contained in:
Lukasz Gromanowski 2012-01-28 09:49:09 +01:00
parent f4b6caac59
commit c5dee2c4fb
3 changed files with 17 additions and 42 deletions

View file

@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager()
void ConfigurationManager::setupTokensMapping() void ConfigurationManager::setupTokensMapping()
{ {
mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath));
mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath));
mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath));
mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath));
} }
void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables,
@ -87,27 +87,22 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
{ {
const std::string& path = it->string(); const std::string& path = it->string();
if (!path.empty() && path[0] == '?')
// Check if path contains a token
if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?')
{ {
std::string::size_type pos = path.find('?', 1); TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path);
if (pos != std::string::npos) if (tokenIt != mTokensMapping.end())
{ {
++pos; boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))());
TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos));
if (tokenIt != mTokensMapping.end()) if (boost::filesystem::is_directory(tempPath))
{ {
boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); (*it) = tempPath;
}
if (boost::filesystem::is_directory(tempPath)) else
{ {
((mFixedPath).*(tokenIt->second))(tempPath); (*it).clear();
(*it) = tempPath;
}
else
{
(*it).clear();
}
} }
} }
} }

View file

@ -44,7 +44,7 @@ struct ConfigurationManager
private: private:
typedef Files::FixedPath<> FixedPathType; typedef Files::FixedPath<> FixedPathType;
typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const;
typedef std::tr1::unordered_map<std::string, path_type_f> TokensMappingContainer; typedef std::tr1::unordered_map<std::string, path_type_f> TokensMappingContainer;
void loadConfig(const boost::filesystem::path& path, void loadConfig(const boost::filesystem::path& path,

View file

@ -125,41 +125,21 @@ struct FixedPath
return mInstallPath; return mInstallPath;
} }
void setInstallPath(const boost::filesystem::path& path)
{
mInstallPath = path;
}
const boost::filesystem::path& getGlobalDataPath() const const boost::filesystem::path& getGlobalDataPath() const
{ {
return mGlobalDataPath; return mGlobalDataPath;
} }
void setGlobalDataPath(const boost::filesystem::path& path)
{
mGlobalDataPath = path;
}
const boost::filesystem::path& getUserDataPath() const const boost::filesystem::path& getUserDataPath() const
{ {
return mUserDataPath; return mUserDataPath;
} }
void setUserDataPath(const boost::filesystem::path& path)
{
mUserDataPath = path;
}
const boost::filesystem::path& getLocalDataPath() const const boost::filesystem::path& getLocalDataPath() const
{ {
return mLocalDataPath; return mLocalDataPath;
} }
void setLocalDataPath(const boost::filesystem::path& path)
{
mLocalDataPath = path;
}
private: private:
PathType mPath; PathType mPath;