From 231adad93f009839614c6d7638a7ccd2df3e60d5 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 26 Jul 2011 19:51:07 +0000 Subject: [PATCH] Implement agi::util::freespace for Windows Originally committed to SVN as r5497. --- aegisub/libaegisub/include/libaegisub/util.h | 2 +- aegisub/libaegisub/unix/util.cpp | 2 +- aegisub/libaegisub/windows/util_win.cpp | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/aegisub/libaegisub/include/libaegisub/util.h b/aegisub/libaegisub/include/libaegisub/util.h index 55c21dec7..8e9d73596 100644 --- a/aegisub/libaegisub/include/libaegisub/util.h +++ b/aegisub/libaegisub/include/libaegisub/util.h @@ -65,7 +65,7 @@ namespace agi { /// Check for amount of free space on a Path. // @param path[in] Path to check // @param type PathType (default is TypeDir) - uint64_t freespace(std::string &path, PathType type=TypeDir); + uint64_t freespace(std::string const& path, PathType type=TypeDir); struct delete_ptr { template diff --git a/aegisub/libaegisub/unix/util.cpp b/aegisub/libaegisub/unix/util.cpp index c9215bf81..50708f268 100644 --- a/aegisub/libaegisub/unix/util.cpp +++ b/aegisub/libaegisub/unix/util.cpp @@ -66,7 +66,7 @@ void time_log(timeval &tv) { gettimeofday(&tv, (struct timezone *)NULL); } -uint64_t freespace(std::string &path, PathType type) { +uint64_t freespace(std::string const& path, PathType type) { struct statvfs fs; std::string check(path); diff --git a/aegisub/libaegisub/windows/util_win.cpp b/aegisub/libaegisub/windows/util_win.cpp index 437518751..5fe1f3d0c 100644 --- a/aegisub/libaegisub/windows/util_win.cpp +++ b/aegisub/libaegisub/windows/util_win.cpp @@ -111,5 +111,19 @@ void time_log(agi_timeval &tv) { tv.tv_usec = (long)(tmpres % 1000000UL); } +uint64_t freespace(std::string const& path, PathType type) { + if (type == TypeFile) + return freespace(DirName(path)); + + ULARGE_INTEGER bytes_available; + if (GetDiskFreeSpaceEx(ConvertW(path).c_str(), &bytes_available, 0, 0)) + return bytes_available.QuadPart; + + acs::CheckDirRead(path); + + /// @todo GetLastError -> Exception mapping + throw "Unknown error getting free space"; +} + } // namespace io } // namespace agi