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:
@@ -6,8 +6,8 @@
|
||||
#include "utility/file/FileSystem.h"
|
||||
|
||||
FileManager::FileManager(
|
||||
std::vector<std::string> sourcePaths,
|
||||
std::vector<std::string> includePaths,
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> includePaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
)
|
||||
@@ -22,12 +22,12 @@ FileManager::~FileManager()
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<std::string>& FileManager::getSourcePaths() const
|
||||
const std::vector<FilePath>& FileManager::getSourcePaths() const
|
||||
{
|
||||
return m_sourcePaths;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& FileManager::getIncludePaths() const
|
||||
const std::vector<FilePath>& FileManager::getIncludePaths() const
|
||||
{
|
||||
return m_includePaths;
|
||||
}
|
||||
@@ -51,14 +51,14 @@ void FileManager::fetchFilePaths()
|
||||
m_removedFiles.insert(it->first);
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::vector<std::string>, std::vector<std::string>>> pathsExtensionsPairs;
|
||||
std::vector<std::pair<std::vector<FilePath>, std::vector<std::string>>> pathsExtensionsPairs;
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_includePaths, m_includeExtensions));
|
||||
pathsExtensionsPairs.push_back(std::make_pair(m_sourcePaths, m_sourceExtensions));
|
||||
|
||||
for (size_t i = 0; i < pathsExtensionsPairs.size(); i++)
|
||||
{
|
||||
std::vector<FileInfo> fileInfos =
|
||||
FileSystem::getFileInfosFromDirectoryPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second);
|
||||
FileSystem::getFileInfosFromPaths(pathsExtensionsPairs[i].first, pathsExtensionsPairs[i].second);
|
||||
|
||||
for (FileInfo fileInfo: fileInfos)
|
||||
{
|
||||
|
||||
@@ -11,15 +11,15 @@ class FileManager
|
||||
{
|
||||
public:
|
||||
FileManager(
|
||||
std::vector<std::string> sourcePaths,
|
||||
std::vector<std::string> includePaths,
|
||||
std::vector<FilePath> sourcePaths,
|
||||
std::vector<FilePath> includePaths,
|
||||
std::vector<std::string> sourceExtensions,
|
||||
std::vector<std::string> includeExtensions
|
||||
);
|
||||
~FileManager();
|
||||
|
||||
const std::vector<std::string>& getSourcePaths() const;
|
||||
const std::vector<std::string>& getIncludePaths() const;
|
||||
const std::vector<FilePath>& getSourcePaths() const;
|
||||
const std::vector<FilePath>& getIncludePaths() const;
|
||||
|
||||
void reset();
|
||||
void fetchFilePaths();
|
||||
@@ -33,8 +33,8 @@ public:
|
||||
virtual bool hasIncludeExtension(const FilePath& filePath) const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_sourcePaths;
|
||||
std::vector<std::string> m_includePaths;
|
||||
std::vector<FilePath> m_sourcePaths;
|
||||
std::vector<FilePath> m_includePaths;
|
||||
std::vector<std::string> m_sourceExtensions;
|
||||
std::vector<std::string> m_includeExtensions;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,26 @@
|
||||
class FilePath
|
||||
{
|
||||
public:
|
||||
FilePath();
|
||||
FilePath(const char* filePath);
|
||||
FilePath(const std::string& filePath);
|
||||
FilePath(const boost::filesystem::path& filePath);
|
||||
|
||||
boost::filesystem::path path() const;
|
||||
|
||||
bool empty() const;
|
||||
bool exists() const;
|
||||
bool isDirectory() const;
|
||||
bool isAbsolute() const;
|
||||
|
||||
FilePath parentDirectory() const;
|
||||
|
||||
FilePath absolute() const;
|
||||
FilePath canonical() const;
|
||||
FilePath relativeTo(const FilePath& other) const;
|
||||
FilePath concat(const FilePath& other) const;
|
||||
|
||||
std::string str() const;
|
||||
std::string absoluteStr() const;
|
||||
std::string fileName() const;
|
||||
|
||||
std::string extension() const;
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
|
||||
std::vector<std::string> FileSystem::getFileNamesFromDirectory(
|
||||
const std::string& path, const std::vector<std::string>& extensions
|
||||
)
|
||||
{
|
||||
){
|
||||
std::vector<std::string> files;
|
||||
|
||||
if (boost::filesystem::is_directory(path))
|
||||
@@ -53,16 +52,15 @@ std::vector<std::string> FileSystem::getFileNamesFromDirectoryUpdatedAfter(
|
||||
return files;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> FileSystem::getFileInfosFromDirectoryPaths(
|
||||
const std::vector<std::string>& directoryPaths, const std::vector<std::string>& fileExtensions)
|
||||
{
|
||||
std::vector<FileInfo> FileSystem::getFileInfosFromPaths(
|
||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions
|
||||
){
|
||||
std::vector<FileInfo> files;
|
||||
for (const std::string& directoryPath: directoryPaths)
|
||||
for (const FilePath& path: paths)
|
||||
{
|
||||
boost::filesystem::path path(directoryPath);
|
||||
if (boost::filesystem::is_directory(path))
|
||||
if (path.isDirectory())
|
||||
{
|
||||
boost::filesystem::recursive_directory_iterator it(path);
|
||||
boost::filesystem::recursive_directory_iterator it(path.path());
|
||||
boost::filesystem::recursive_directory_iterator endit;
|
||||
while (it != endit)
|
||||
{
|
||||
@@ -75,9 +73,9 @@ std::vector<FileInfo> FileSystem::getFileInfosFromDirectoryPaths(
|
||||
++it;
|
||||
}
|
||||
}
|
||||
else if (boost::filesystem::exists(path) && hasExtension(path.string(), fileExtensions))
|
||||
else if (path.exists() && path.hasExtension(fileExtensions))
|
||||
{
|
||||
std::time_t t = boost::filesystem::last_write_time(path);
|
||||
std::time_t t = boost::filesystem::last_write_time(path.path());
|
||||
boost::posix_time::ptime lastWriteTime = boost::posix_time::from_time_t(t);
|
||||
files.push_back(FileInfo(path, lastWriteTime));
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ public:
|
||||
static std::vector<std::string> getFileNamesFromDirectoryUpdatedAfter(
|
||||
const std::string& path, const std::vector<std::string>& extensions, const std::string& timeString);
|
||||
|
||||
static std::vector<FileInfo> getFileInfosFromDirectoryPaths(
|
||||
const std::vector<std::string>& directoryPaths, const std::vector<std::string>& fileExtensions);
|
||||
static std::vector<FileInfo> getFileInfosFromPaths(
|
||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions);
|
||||
|
||||
static std::string getTimeStringNow();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user