Added try/catch statements to a couple of std::filesystem functions in FileSystemUtil

This commit is contained in:
Leon Styhre 2023-08-02 19:32:46 +02:00
parent 5705672957
commit 05cfbb55bd

View file

@ -70,6 +70,7 @@ namespace Utils
if (!isDirectory(genericPath))
return contentList;
try {
if (recursive) {
for (auto& entry : std::filesystem::recursive_directory_iterator(genericPath)) {
#if defined(_WIN64)
@ -90,6 +91,10 @@ namespace Utils
#endif
}
}
}
catch (...) {
return contentList;
}
contentList.sort();
return contentList;
@ -884,6 +889,7 @@ namespace Utils
bool exists(const std::string& path)
{
try {
const std::string& genericPath {getGenericPath(path)};
#if defined(_WIN64)
return std::filesystem::exists(Utils::String::stringToWideString(genericPath));
@ -891,6 +897,10 @@ namespace Utils
return std::filesystem::exists(genericPath);
#endif
}
catch (...) {
return false;
}
}
bool driveExists(const std::string& path)
{
@ -911,6 +921,7 @@ namespace Utils
bool isAbsolute(const std::string& path)
{
try {
const std::string& genericPath {getGenericPath(path)};
#if defined(_WIN64)
return ((genericPath.size() > 1) && (genericPath[1] == ':'));
@ -918,29 +929,46 @@ namespace Utils
return ((genericPath.size() > 0) && (genericPath[0] == '/'));
#endif
}
catch (...) {
return false;
}
}
bool isRegularFile(const std::string& path)
{
try {
const std::string& genericPath {getGenericPath(path)};
#if defined(_WIN64)
return std::filesystem::is_regular_file(Utils::String::stringToWideString(genericPath));
return std::filesystem::is_regular_file(
Utils::String::stringToWideString(genericPath));
#else
return std::filesystem::is_regular_file(genericPath);
#endif
}
catch (...) {
return false;
}
}
bool isDirectory(const std::string& path)
{
try {
const std::string& genericPath {getGenericPath(path)};
#if defined(_WIN64)
return std::filesystem::is_directory(Utils::String::stringToWideString(genericPath));
return std::filesystem::is_directory(
Utils::String::stringToWideString(genericPath));
#else
return std::filesystem::is_directory(genericPath);
#endif
}
catch (...) {
return false;
}
}
bool isSymlink(const std::string& path)
{
try {
const std::string& genericPath {getGenericPath(path)};
#if defined(_WIN64)
return std::filesystem::is_symlink(Utils::String::stringToWideString(genericPath));
@ -948,6 +976,10 @@ namespace Utils
return std::filesystem::is_symlink(genericPath);
#endif
}
catch (...) {
return false;
}
}
bool isHidden(const std::string& path)
{