From c664990d2ec3020fc8d6dde52b9d0b096d41b3c8 Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Wed, 15 Dec 2021 10:21:49 +0100 Subject: Implement DiskSpaceInfo() using std::filesystem::space() --- zencore/filesystem.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'zencore/filesystem.cpp') 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(Free.QuadPart), .Total = static_cast(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 -- cgit v1.2.3