|
@@ -52,24 +52,24 @@ using std::string;
|
|
|
using std::stringstream;
|
|
using std::stringstream;
|
|
|
using std::vector;
|
|
using std::vector;
|
|
|
|
|
|
|
|
-File::File(string _absoluteFilePath) : Class("File"), absoluteFilePath(File::_normalizePath(::move(_absoluteFilePath)))
|
|
|
|
|
|
|
+File::File(string _absoluteFilePath) : Class("File"), absoluteFilePath(_normalizePath(::move(_absoluteFilePath)))
|
|
|
{}
|
|
{}
|
|
|
|
|
|
|
|
File::~File() noexcept = default;
|
|
File::~File() noexcept = default;
|
|
|
|
|
|
|
|
bool File::operator==(const File &_file) const
|
|
bool File::operator==(const File &_file) const
|
|
|
{
|
|
{
|
|
|
- return File::_equals(*this, _file);
|
|
|
|
|
|
|
+ return _equals(*this, _file);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool File::operator!=(const File &_file) const
|
|
bool File::operator!=(const File &_file) const
|
|
|
{
|
|
{
|
|
|
- return !File::_equals(*this, _file);
|
|
|
|
|
|
|
+ return !_equals(*this, _file);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool File::canExecute() const
|
|
bool File::canExecute() const
|
|
|
{
|
|
{
|
|
|
- return File::_isExecutable(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _isExecutable(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool File::canRead() const
|
|
bool File::canRead() const
|
|
@@ -77,7 +77,7 @@ bool File::canRead() const
|
|
|
bool readable{};
|
|
bool readable{};
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
- readable = File::_isReadableUnix(this->absoluteFilePath);
|
|
|
|
|
|
|
+ readable = _isReadableUnix(this->absoluteFilePath);
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
readable = File::_isReadableWindows(this->absoluteFilePath);
|
|
readable = File::_isReadableWindows(this->absoluteFilePath);
|
|
@@ -88,12 +88,12 @@ bool File::canRead() const
|
|
|
|
|
|
|
|
bool File::canWrite() const
|
|
bool File::canWrite() const
|
|
|
{
|
|
{
|
|
|
- return File::_isWritable(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _isWritable(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void File::createNewFile() const
|
|
void File::createNewFile() const
|
|
|
{
|
|
{
|
|
|
- if (!File::_exists(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (!_exists(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
ofstream file{this->absoluteFilePath};
|
|
ofstream file{this->absoluteFilePath};
|
|
|
file.close();
|
|
file.close();
|
|
@@ -106,7 +106,7 @@ void File::createNewFile() const
|
|
|
|
|
|
|
|
bool File::exists() const
|
|
bool File::exists() const
|
|
|
{
|
|
{
|
|
|
- return File::_exists(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _exists(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
string File::getAbsoluteFilePath() const
|
|
string File::getAbsoluteFilePath() const
|
|
@@ -120,20 +120,20 @@ string File::getName() const
|
|
|
|
|
|
|
|
// if it's a directory, remove separator from end, if it does exist
|
|
// if it's a directory, remove separator from end, if it does exist
|
|
|
|
|
|
|
|
- if (File::_isDirectory(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_isDirectory(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
copy.erase(remove_if(copy.end() - 1, copy.end(), FilePathSeparatorMatch()), copy.end());
|
|
copy.erase(remove_if(copy.end() - 1, copy.end(), FilePathSeparatorMatch()), copy.end());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// now get the file / directory name
|
|
// now get the file / directory name
|
|
|
|
|
|
|
|
- auto base = find_if(copy.rbegin(), copy.rend(), FilePathSeparatorMatch()).base();
|
|
|
|
|
|
|
+ const auto base = find_if(copy.rbegin(), copy.rend(), FilePathSeparatorMatch()).base();
|
|
|
return string{base, copy.end()};
|
|
return string{base, copy.end()};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
string File::getParent() const
|
|
string File::getParent() const
|
|
|
{
|
|
{
|
|
|
- return File::_getParent(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _getParent(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
string File::getWorkingDirectory()
|
|
string File::getWorkingDirectory()
|
|
@@ -141,7 +141,7 @@ string File::getWorkingDirectory()
|
|
|
string workingDirectory{};
|
|
string workingDirectory{};
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
- workingDirectory = File::_getWorkingDirectoryUnix();
|
|
|
|
|
|
|
+ workingDirectory = _getWorkingDirectoryUnix();
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
workingDirectory = File::_getWorkingDirectoryWindows();
|
|
workingDirectory = File::_getWorkingDirectoryWindows();
|
|
@@ -154,7 +154,7 @@ size_t File::getSize() const
|
|
|
{
|
|
{
|
|
|
streampos fileSize{};
|
|
streampos fileSize{};
|
|
|
|
|
|
|
|
- if (File::_exists(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_exists(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
ifstream fileHandler{this->absoluteFilePath, ios::in};
|
|
ifstream fileHandler{this->absoluteFilePath, ios::in};
|
|
|
fileSize = fileHandler.tellg();
|
|
fileSize = fileHandler.tellg();
|
|
@@ -169,26 +169,26 @@ size_t File::getSize() const
|
|
|
|
|
|
|
|
bool File::isDirectory() const
|
|
bool File::isDirectory() const
|
|
|
{
|
|
{
|
|
|
- return File::_isDirectory(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _isDirectory(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool File::isFile() const
|
|
bool File::isFile() const
|
|
|
{
|
|
{
|
|
|
- return File::_isFile(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _isFile(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
time_t File::lastModified() const
|
|
time_t File::lastModified() const
|
|
|
{
|
|
{
|
|
|
- return File::_lastModified(this->absoluteFilePath);
|
|
|
|
|
|
|
+ return _lastModified(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
::list<string> File::list() const
|
|
::list<string> File::list() const
|
|
|
{
|
|
{
|
|
|
::list<string> fileList{};
|
|
::list<string> fileList{};
|
|
|
|
|
|
|
|
- if (File::_isDirectory(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_isDirectory(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
- fileList = File::_list(this->absoluteFilePath);
|
|
|
|
|
|
|
+ fileList = _list(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return fileList;
|
|
return fileList;
|
|
@@ -198,9 +198,9 @@ time_t File::lastModified() const
|
|
|
{
|
|
{
|
|
|
::list<string> fileList{};
|
|
::list<string> fileList{};
|
|
|
|
|
|
|
|
- if (File::_isDirectory(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_isDirectory(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
- fileList = File::_listFiles(this->absoluteFilePath);
|
|
|
|
|
|
|
+ fileList = _listFiles(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return fileList;
|
|
return fileList;
|
|
@@ -208,7 +208,7 @@ time_t File::lastModified() const
|
|
|
|
|
|
|
|
void File::makeDirectory() const
|
|
void File::makeDirectory() const
|
|
|
{
|
|
{
|
|
|
- if (!File::_makeDirectory(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (!_makeDirectory(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
throw FileOperationException{R"lit(directory ")lit" + this->absoluteFilePath + R"lit(" could not be created!)lit"};
|
|
throw FileOperationException{R"lit(directory ")lit" + this->absoluteFilePath + R"lit(" could not be created!)lit"};
|
|
|
}
|
|
}
|
|
@@ -216,7 +216,7 @@ void File::makeDirectory() const
|
|
|
|
|
|
|
|
void File::makeDirectories() const
|
|
void File::makeDirectories() const
|
|
|
{
|
|
{
|
|
|
- vector<string> subDirectories = File::_splitIntoSubDirectoryNames(this->absoluteFilePath);
|
|
|
|
|
|
|
+ const vector<string> subDirectories = _splitIntoSubDirectoryNames(this->absoluteFilePath);
|
|
|
const char separator = FilePathSeparator::get();
|
|
const char separator = FilePathSeparator::get();
|
|
|
string currentHierarchy{};
|
|
string currentHierarchy{};
|
|
|
|
|
|
|
@@ -224,7 +224,7 @@ void File::makeDirectories() const
|
|
|
{
|
|
{
|
|
|
currentHierarchy += subDirectory;
|
|
currentHierarchy += subDirectory;
|
|
|
|
|
|
|
|
- if (!File::_exists(currentHierarchy + separator) && !currentHierarchy.empty() && !File::_makeDirectory(currentHierarchy))
|
|
|
|
|
|
|
+ if (!_exists(currentHierarchy + separator) && !currentHierarchy.empty() && !_makeDirectory(currentHierarchy))
|
|
|
{
|
|
{
|
|
|
throw FileOperationException{"operation: create directory"};
|
|
throw FileOperationException{"operation: create directory"};
|
|
|
}
|
|
}
|
|
@@ -235,20 +235,20 @@ void File::makeDirectories() const
|
|
|
|
|
|
|
|
void File::remove() const
|
|
void File::remove() const
|
|
|
{
|
|
{
|
|
|
- if (File::_isFile(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_isFile(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
::remove(this->absoluteFilePath.c_str());
|
|
::remove(this->absoluteFilePath.c_str());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (File::_isDirectory(this->absoluteFilePath))
|
|
|
|
|
|
|
+ if (_isDirectory(this->absoluteFilePath))
|
|
|
{
|
|
{
|
|
|
- File::_remove(this->absoluteFilePath);
|
|
|
|
|
|
|
+ _remove(this->absoluteFilePath);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool File::renameTo(const string &_newName)
|
|
bool File::renameTo(const string &_newName)
|
|
|
{
|
|
{
|
|
|
- bool renamed = File::_renameTo(this->absoluteFilePath, _newName);
|
|
|
|
|
|
|
+ const bool renamed = _renameTo(this->absoluteFilePath, _newName);
|
|
|
|
|
|
|
|
if (renamed)
|
|
if (renamed)
|
|
|
{
|
|
{
|
|
@@ -260,7 +260,7 @@ bool File::renameTo(const string &_newName)
|
|
|
|
|
|
|
|
void File::reset(const string &_newPath)
|
|
void File::reset(const string &_newPath)
|
|
|
{
|
|
{
|
|
|
- this->absoluteFilePath = File::_normalizePath(_newPath);
|
|
|
|
|
|
|
+ this->absoluteFilePath = _normalizePath(_newPath);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
@@ -287,7 +287,7 @@ void File::_addToFileListWindows(const string &_path, bool _withDirectories, WIN
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
|
|
|
|
|
-void File::_addToFileListUnix(const string &_path, bool _withDirectories, const dirent *directoryEntity, ::list<string> &_list)
|
|
|
|
|
|
|
+void File::_addToFileListUnix(const string &_path, const bool _withDirectories, const dirent *directoryEntity, ::list<string> &_list)
|
|
|
{
|
|
{
|
|
|
const char separator = FilePathSeparator::get();
|
|
const char separator = FilePathSeparator::get();
|
|
|
string absolutePath = _path + separator + directoryEntity->d_name;
|
|
string absolutePath = _path + separator + directoryEntity->d_name;
|
|
@@ -298,7 +298,7 @@ void File::_addToFileListUnix(const string &_path, bool _withDirectories, const
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- if (File::_isFile(absolutePath))
|
|
|
|
|
|
|
+ if (_isFile(absolutePath))
|
|
|
{
|
|
{
|
|
|
_list.emplace_back(absolutePath);
|
|
_list.emplace_back(absolutePath);
|
|
|
}
|
|
}
|
|
@@ -385,7 +385,7 @@ bool File::_isDirectory(const string &_path)
|
|
|
|
|
|
|
|
if (struct stat _stat{}; stat(_path.c_str(), &_stat) == 0)
|
|
if (struct stat _stat{}; stat(_path.c_str(), &_stat) == 0)
|
|
|
{
|
|
{
|
|
|
- match = _stat.st_mode & (unsigned short) S_IFDIR;
|
|
|
|
|
|
|
+ match = _stat.st_mode & static_cast<unsigned short>(S_IFDIR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
return match;
|
|
@@ -395,7 +395,7 @@ bool File::_isExecutable(const string &_path)
|
|
|
{
|
|
{
|
|
|
bool executable{};
|
|
bool executable{};
|
|
|
|
|
|
|
|
- if (File::_exists(_path))
|
|
|
|
|
|
|
+ if (_exists(_path))
|
|
|
{
|
|
{
|
|
|
struct stat _stat
|
|
struct stat _stat
|
|
|
{
|
|
{
|
|
@@ -403,7 +403,7 @@ bool File::_isExecutable(const string &_path)
|
|
|
|
|
|
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
|
{
|
|
{
|
|
|
- executable = (_stat.st_mode & (unsigned short) S_IEXEC) != 0;
|
|
|
|
|
|
|
+ executable = (_stat.st_mode & static_cast<unsigned short>(S_IEXEC)) != 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -416,7 +416,7 @@ bool File::_isFile(const string &_path)
|
|
|
|
|
|
|
|
if (struct stat _stat{}; stat(_path.c_str(), &_stat) == 0)
|
|
if (struct stat _stat{}; stat(_path.c_str(), &_stat) == 0)
|
|
|
{
|
|
{
|
|
|
- match = _stat.st_mode & (unsigned) S_IFREG;
|
|
|
|
|
|
|
+ match = _stat.st_mode & static_cast<unsigned>(S_IFREG);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
return match;
|
|
@@ -428,7 +428,7 @@ bool File::_isReadableUnix(const string &_path)
|
|
|
{
|
|
{
|
|
|
bool readable{};
|
|
bool readable{};
|
|
|
|
|
|
|
|
- if (File::_exists(_path))
|
|
|
|
|
|
|
+ if (_exists(_path))
|
|
|
{
|
|
{
|
|
|
struct stat _stat
|
|
struct stat _stat
|
|
|
{
|
|
{
|
|
@@ -436,7 +436,7 @@ bool File::_isReadableUnix(const string &_path)
|
|
|
|
|
|
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
|
{
|
|
{
|
|
|
- readable = (_stat.st_mode & (unsigned) S_IREAD) != 0;
|
|
|
|
|
|
|
+ readable = (_stat.st_mode & static_cast<unsigned>(S_IREAD)) != 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -475,7 +475,7 @@ bool File::_isWritable(const string &_path)
|
|
|
{
|
|
{
|
|
|
bool writable{};
|
|
bool writable{};
|
|
|
|
|
|
|
|
- if (File::_exists(_path))
|
|
|
|
|
|
|
+ if (_exists(_path))
|
|
|
{
|
|
{
|
|
|
struct stat _stat
|
|
struct stat _stat
|
|
|
{
|
|
{
|
|
@@ -483,7 +483,7 @@ bool File::_isWritable(const string &_path)
|
|
|
|
|
|
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
if (stat(_path.c_str(), &_stat) == 0)
|
|
|
{
|
|
{
|
|
|
- writable = (_stat.st_mode & (unsigned) S_IWRITE) != 0;
|
|
|
|
|
|
|
+ writable = (_stat.st_mode & static_cast<unsigned>(S_IWRITE)) != 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -507,7 +507,7 @@ time_t File::_lastModified(const string &_path)
|
|
|
::list<string> filesInDirectory{};
|
|
::list<string> filesInDirectory{};
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
- filesInDirectory = File::_listUnix(_path, true);
|
|
|
|
|
|
|
+ filesInDirectory = _listUnix(_path, true);
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
filesInDirectory = File::_listWindows(_path, true);
|
|
filesInDirectory = File::_listWindows(_path, true);
|
|
@@ -521,7 +521,7 @@ time_t File::_lastModified(const string &_path)
|
|
|
::list<string> filesInDirectory{};
|
|
::list<string> filesInDirectory{};
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
- filesInDirectory = File::_listUnix(_path, false);
|
|
|
|
|
|
|
+ filesInDirectory = _listUnix(_path, false);
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
filesInDirectory = File::_listWindows(_path, false);
|
|
filesInDirectory = File::_listWindows(_path, false);
|
|
@@ -532,16 +532,16 @@ time_t File::_lastModified(const string &_path)
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
|
|
|
|
|
-::list<string> File::_listUnix(const string &_path, bool withDirectories)
|
|
|
|
|
|
|
+::list<string> File::_listUnix(const string &_path, const bool withDirectories)
|
|
|
{
|
|
{
|
|
|
::list<string> filesInDirectory{};
|
|
::list<string> filesInDirectory{};
|
|
|
DIR *directory = opendir(_path.c_str());
|
|
DIR *directory = opendir(_path.c_str());
|
|
|
- const struct dirent *directoryEntity;
|
|
|
|
|
|
|
+ const dirent *directoryEntity;
|
|
|
string absolutePath{};
|
|
string absolutePath{};
|
|
|
|
|
|
|
|
while ((directoryEntity = readdir(directory)) != nullptr)
|
|
while ((directoryEntity = readdir(directory)) != nullptr)
|
|
|
{
|
|
{
|
|
|
- File::_addToFileListUnix(_path, withDirectories, directoryEntity, filesInDirectory);
|
|
|
|
|
|
|
+ _addToFileListUnix(_path, withDirectories, directoryEntity, filesInDirectory);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
closedir(directory);
|
|
closedir(directory);
|
|
@@ -591,8 +591,8 @@ bool File::_makeDirectory(const string &_path)
|
|
|
|
|
|
|
|
string File::_normalizePath(string _path)
|
|
string File::_normalizePath(string _path)
|
|
|
{
|
|
{
|
|
|
- _path = File::_replaceWrongSeparator(_path);
|
|
|
|
|
- _path = File::_reduceSeparators(_path);
|
|
|
|
|
|
|
+ _path = _replaceWrongSeparator(_path);
|
|
|
|
|
+ _path = _reduceSeparators(_path);
|
|
|
|
|
|
|
|
return _path;
|
|
return _path;
|
|
|
}
|
|
}
|
|
@@ -627,7 +627,7 @@ string File::_reduceSeparators(const string &_path)
|
|
|
void File::_remove(const string &_path)
|
|
void File::_remove(const string &_path)
|
|
|
{
|
|
{
|
|
|
#if defined(unix) || defined(__APPLE__)
|
|
#if defined(unix) || defined(__APPLE__)
|
|
|
- File::_removeUnix(_path);
|
|
|
|
|
|
|
+ _removeUnix(_path);
|
|
|
#endif
|
|
#endif
|
|
|
#ifdef _WIN32
|
|
#ifdef _WIN32
|
|
|
File::_removeWindows(_path);
|
|
File::_removeWindows(_path);
|