aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/filesystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/filesystem.cpp')
-rw-r--r--src/zencore/filesystem.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp
index d79a39880..7ca076daa 100644
--- a/src/zencore/filesystem.cpp
+++ b/src/zencore/filesystem.cpp
@@ -93,6 +93,8 @@ CreateDirectories(const wchar_t* Dir)
// Erase all files and directories in a given directory, leaving an empty directory
// behind
+bool DeleteDirectoriesInternal(const wchar_t* DirPath);
+
static bool
WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles)
{
@@ -159,7 +161,7 @@ WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles)
}
}
- bool Succeeded = DeleteDirectories(Path.c_str());
+ bool Succeeded = DeleteDirectoriesInternal(Path.c_str());
if (!Succeeded)
{
@@ -193,26 +195,13 @@ WipeDirectory(const wchar_t* DirPath, bool KeepDotFiles)
}
bool
-DeleteDirectories(const wchar_t* DirPath)
+DeleteDirectoriesInternal(const wchar_t* DirPath)
{
const bool KeepDotFiles = false;
return WipeDirectory(DirPath, KeepDotFiles) && RemoveDirectoryW(DirPath) == TRUE;
}
bool
-CleanDirectory(const wchar_t* DirPath)
-{
- if (std::filesystem::exists(DirPath))
- {
- const bool KeepDotFiles = false;
-
- return WipeDirectory(DirPath, KeepDotFiles);
- }
-
- return CreateDirectories(DirPath);
-}
-
-bool
CleanDirectory(const wchar_t* DirPath, bool KeepDotFiles)
{
if (std::filesystem::exists(DirPath))
@@ -222,7 +211,6 @@ CleanDirectory(const wchar_t* DirPath, bool KeepDotFiles)
return CreateDirectories(DirPath);
}
-
#endif // ZEN_PLATFORM_WINDOWS
bool
@@ -252,35 +240,29 @@ CreateDirectories(const std::filesystem::path& Dir)
bool
DeleteDirectories(const std::filesystem::path& Dir)
{
-#if ZEN_PLATFORM_WINDOWS
- return DeleteDirectories(Dir.c_str());
-#else
std::error_code ErrorCode;
return std::filesystem::remove_all(Dir, ErrorCode);
-#endif
}
bool
CleanDirectory(const std::filesystem::path& Dir)
{
-#if ZEN_PLATFORM_WINDOWS
- return CleanDirectory(Dir.c_str());
-#else
if (std::filesystem::exists(Dir))
{
bool Success = true;
- std::error_code ErrorCode;
for (const auto& Item : std::filesystem::directory_iterator(Dir))
{
- Success &= std::filesystem::remove_all(Item, ErrorCode);
+ std::error_code ErrorCode;
+ const uintmax_t RemovedCount = std::filesystem::remove_all(Item, ErrorCode);
+
+ Success = Success && !ErrorCode && RemovedCount;
}
return Success;
}
return CreateDirectories(Dir);
-#endif
}
bool