logic: paths in ProjectSettings relative to file not working directory

This change checks all paths in the ProjectSettings file for relativity and makes them relative to the location of the
ProjectSettings file if necessary. The paths are also correctly saved relative to the file.
This commit is contained in:
Eberhard Graether
2015-07-29 22:20:26 +02:00
parent 336df76912
commit 5f25311389
31 changed files with 407 additions and 148 deletions
+85 -8
View File
@@ -9,11 +9,11 @@ Settings::~Settings()
{
}
bool Settings::load(const std::string& filePath)
bool Settings::load(const FilePath& filePath)
{
if (FileSystem::exists(filePath))
if (filePath.exists())
{
m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(filePath));
m_config = ConfigManager::createAndLoad(TextAccess::createFromFile(filePath.str()));
m_filePath = filePath;
return true;
}
@@ -27,9 +27,9 @@ bool Settings::load(const std::string& filePath)
void Settings::save()
{
if (m_config.get() && m_filePath.size())
if (m_config.get() && m_filePath.exists())
{
m_config->save(m_filePath);
m_config->save(m_filePath.str());
}
else
{
@@ -37,11 +37,13 @@ void Settings::save()
}
}
void Settings::save(const std::string& filePath)
void Settings::save(const FilePath& filePath)
{
setFilePath(filePath);
if (m_config)
{
m_config->save(filePath);
m_config->save(filePath.str());
}
else
{
@@ -52,10 +54,85 @@ void Settings::save(const std::string& filePath)
void Settings::clear()
{
m_config = ConfigManager::createEmpty();
m_filePath.clear();
m_filePath = FilePath();
}
Settings::Settings()
{
clear();
}
const FilePath& Settings::getFilePath() const
{
return m_filePath;
}
void Settings::setFilePath(const FilePath& filePath)
{
m_filePath = filePath;
}
std::vector<FilePath> Settings::getPathValues(const std::string& key) const
{
std::vector<std::string> values;
values = getValues(key, values);
std::vector<FilePath> paths;
for (const std::string& path : values)
{
paths.push_back(FilePath(path));
}
return paths;
}
std::vector<FilePath> Settings::getRelativePathValues(const std::string& key) const
{
std::vector<std::string> values;
values = getValues(key, values);
std::vector<FilePath> paths;
for (const std::string& path : values)
{
FilePath filePath(path);
if (!filePath.isAbsolute())
{
filePath = m_filePath.parentDirectory().concat(filePath);
}
paths.push_back(filePath.canonical());
}
return paths;
}
bool Settings::setPathValues(const std::string& key, const std::vector<FilePath>& paths)
{
std::vector<std::string> values;
for (const FilePath& path : paths)
{
values.push_back(path.str());
}
return setValues(key, values);
}
bool Settings::moveRelativePathValues(const std::string& key, const FilePath& filePath)
{
std::vector<std::string> values;
values = getValues(key, values);
FilePath oldPath = m_filePath.absolute();
FilePath newPath = filePath.absolute();
for (size_t i = 0; i < values.size(); i++)
{
FilePath path(values[i]);
if (!path.isAbsolute())
{
path = oldPath.parentDirectory().concat(path);
path = path.canonical().relativeTo(newPath);
values[i] = path.str();
}
}
return setValues(key, values);
}