diff options
| author | Martin Ridgers <[email protected]> | 2021-12-15 10:21:49 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-12-15 10:21:49 +0100 |
| commit | c664990d2ec3020fc8d6dde52b9d0b096d41b3c8 (patch) | |
| tree | fa9b4dc54bb8bbc222eaf35b06141ed71cca55f0 /zencore/filesystem.cpp | |
| parent | Implemented DiskSpaceInfo() for POSIX platforms (diff) | |
| download | zen-c664990d2ec3020fc8d6dde52b9d0b096d41b3c8.tar.xz zen-c664990d2ec3020fc8d6dde52b9d0b096d41b3c8.zip | |
Implement DiskSpaceInfo() using std::filesystem::space()
Diffstat (limited to 'zencore/filesystem.cpp')
| -rw-r--r-- | zencore/filesystem.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index 7c55be3e8..2e4e876e9 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -757,25 +757,18 @@ PathToUtf8(const std::filesystem::path& Path) 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 - struct statvfs Stat; - if (statvfs(Directory.c_str(), &Stat) == 0) + using namespace std::filesystem; + + space_info SpaceInfo = space(Directory, Error); + if (Error) { - return { - .Free = uint64_t(Stat.f_bsize * Stat.f_bavail), - .Total = uint64_t(Stat.f_frsize * Stat.f_blocks), - }; + return {}; } -#endif - Error = std::error_code(zen::GetLastError(), std::system_category()); - return {}; + return { + .Free = uint64_t(SpaceInfo.available), + .Total = uint64_t(SpaceInfo.capacity), + }; } void |