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>
actorid
Lukasz Gromanowski 13 years ago
parent f4b6caac59
commit c5dee2c4fb

@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager()
void ConfigurationManager::setupTokensMapping()
{
mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath));
mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath));
mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath));
mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath));
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,
@ -87,27 +87,22 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it)
{
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);
if (pos != std::string::npos)
TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path);
if (tokenIt != mTokensMapping.end())
{
++pos;
TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos));
boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))());
if (tokenIt != mTokensMapping.end())
if (boost::filesystem::is_directory(tempPath))
{
(*it) = tempPath;
}
else
{
boost::filesystem::path tempPath(path.substr(pos, path.length() - pos));
if (boost::filesystem::is_directory(tempPath))
{
((mFixedPath).*(tokenIt->second))(tempPath);
(*it) = tempPath;
}
else
{
(*it).clear();
}
(*it).clear();
}
}
}

@ -44,7 +44,7 @@ struct ConfigurationManager
private:
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;
void loadConfig(const boost::filesystem::path& path,

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

Loading…
Cancel
Save