mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-23 06:41:08 +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:
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,21 +87,17 @@ 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] == '?')
|
||||
{
|
||||
std::string::size_type pos = path.find('?', 1);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
++pos;
|
||||
TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos));
|
||||
|
||||
// Check if path contains a token
|
||||
if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?')
|
||||
{
|
||||
TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path);
|
||||
if (tokenIt != mTokensMapping.end())
|
||||
{
|
||||
boost::filesystem::path tempPath(path.substr(pos, path.length() - pos));
|
||||
boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))());
|
||||
|
||||
if (boost::filesystem::is_directory(tempPath))
|
||||
{
|
||||
((mFixedPath).*(tokenIt->second))(tempPath);
|
||||
(*it) = tempPath;
|
||||
}
|
||||
else
|
||||
@ -111,7 +107,6 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end());
|
||||
}
|
||||
|
@ -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…
x
Reference in New Issue
Block a user