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:
@@ -1,5 +1,10 @@
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
FilePath::FilePath()
|
||||
: m_exists(false)
|
||||
{
|
||||
}
|
||||
|
||||
FilePath::FilePath(const char* filePath)
|
||||
: m_path(filePath)
|
||||
, m_exists(false)
|
||||
@@ -21,21 +26,100 @@ FilePath::FilePath(const boost::filesystem::path& filePath)
|
||||
init();
|
||||
}
|
||||
|
||||
boost::filesystem::path FilePath::path() const
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
bool FilePath::empty() const
|
||||
{
|
||||
return m_path.empty();
|
||||
}
|
||||
|
||||
bool FilePath::exists() const
|
||||
{
|
||||
return m_exists;
|
||||
}
|
||||
|
||||
bool FilePath::isDirectory() const
|
||||
{
|
||||
return boost::filesystem::is_directory(m_path);
|
||||
}
|
||||
|
||||
bool FilePath::isAbsolute() const
|
||||
{
|
||||
return m_path.is_absolute();
|
||||
}
|
||||
|
||||
FilePath FilePath::parentDirectory() const
|
||||
{
|
||||
return m_path.parent_path();
|
||||
}
|
||||
|
||||
FilePath FilePath::absolute() const
|
||||
{
|
||||
return boost::filesystem::absolute(m_path);
|
||||
}
|
||||
|
||||
FilePath FilePath::canonical() const
|
||||
{
|
||||
if (m_exists)
|
||||
{
|
||||
return boost::filesystem::canonical(m_path);
|
||||
}
|
||||
|
||||
return FilePath(m_path);
|
||||
}
|
||||
|
||||
FilePath FilePath::relativeTo(const FilePath& other) const
|
||||
{
|
||||
boost::filesystem::path a = m_path;
|
||||
boost::filesystem::path b = other.m_path;
|
||||
|
||||
if (a.root_path() != b.root_path())
|
||||
{
|
||||
return str();
|
||||
}
|
||||
|
||||
boost::filesystem::path::const_iterator itA = a.begin();
|
||||
boost::filesystem::path::const_iterator itB = b.begin();
|
||||
|
||||
while (*itA == *itB && itA != a.end() && itB != b.end())
|
||||
{
|
||||
itA++;
|
||||
itB++;
|
||||
}
|
||||
|
||||
boost::filesystem::path r;
|
||||
|
||||
if (itB != b.end())
|
||||
{
|
||||
itB++;
|
||||
|
||||
for (; itB != b.end(); itB++)
|
||||
{
|
||||
r /= "..";
|
||||
}
|
||||
}
|
||||
|
||||
for (; itA != a.end(); itA++)
|
||||
{
|
||||
r /= *itA;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
FilePath FilePath::concat(const FilePath& other) const
|
||||
{
|
||||
return boost::filesystem::path(m_path) / other.m_path;
|
||||
}
|
||||
|
||||
std::string FilePath::str() const
|
||||
{
|
||||
return m_path.generic_string();
|
||||
}
|
||||
|
||||
std::string FilePath::absoluteStr() const
|
||||
{
|
||||
return boost::filesystem::absolute(m_path).generic_string();
|
||||
}
|
||||
|
||||
std::string FilePath::fileName() const
|
||||
{
|
||||
return m_path.filename().generic_string();
|
||||
@@ -89,6 +173,5 @@ void FilePath::init()
|
||||
if (boost::filesystem::exists(m_path))
|
||||
{
|
||||
m_exists = true;
|
||||
m_path = boost::filesystem::canonical(m_path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user