aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
Diffstat (limited to 'zencore')
-rw-r--r--zencore/filesystem.cpp21
-rw-r--r--zencore/include/zencore/filesystem.h16
2 files changed, 37 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index bcbb36c73..53e6f1f38 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -634,6 +634,27 @@ ToUtf8(const std::filesystem::path& Path)
#endif
}
+DiskSpace
+DiskSpaceInfo(std::filesystem::path Directory, std::error_code& Error)
+{
+#if ZEN_PLATFORM_WINDOWS
+ ULARGE_INTEGER Free, Total;
+ if (GetDiskFreeSpaceExA(Directory.string().c_str(), &Free, &Total, nullptr))
+ {
+ return {.Free = static_cast<uint64_t>(Free.QuadPart), .Total = static_cast<uint64_t>(Total.QuadPart)};
+ }
+ else
+ {
+ Error = std::error_code(::GetLastError(), std::system_category());
+ return {};
+ }
+#else
+ ZEN_ERROR("DiskSpaceInfo() is not implemented on this platform");
+ Error = std::error_code(1, std::system_category());
+ return {};
+#endif
+}
+
void
FileSystemTraversal::TraverseFileSystem(const std::filesystem::path& RootDir, TreeVisitor& Visitor)
{
diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h
index c7ac7140d..155291e67 100644
--- a/zencore/include/zencore/filesystem.h
+++ b/zencore/include/zencore/filesystem.h
@@ -57,6 +57,22 @@ ZENCORE_API bool SupportsBlockRefCounting(std::filesystem::path Path);
ZENCORE_API std::string ToUtf8(const std::filesystem::path& Path);
+struct DiskSpace
+{
+ uint64_t Free{};
+ uint64_t Total{};
+};
+
+ZENCORE_API DiskSpace DiskSpaceInfo(std::filesystem::path Directory, std::error_code& Error);
+
+inline bool
+DiskSpaceInfo(std::filesystem::path Directory, DiskSpace& Space)
+{
+ std::error_code Err;
+ Space = DiskSpaceInfo(Directory, Err);
+ return !!Err;
+}
+
/**
* Efficient file system traversal
*