From be092841924870af40bcdc7df25c661187410771 Mon Sep 17 00:00:00 2001 From: sledgehammer_999 Date: Thu, 22 Sep 2011 20:37:39 +0300 Subject: [PATCH] Simplify available disk size calculation code The new code uses boost so that we don't need platform-specific code anymore. It also fixes a calculation issue on the Windows platform with the original code. --- src/misc.cpp | 50 +++++--------------------------------------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index eeaf93b2e..4b7b4ba18 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef DISABLE_GUI #include @@ -60,14 +61,7 @@ const int UNLEN = 256; #include #endif -#ifndef Q_WS_WIN -#if defined(Q_WS_MAC) || defined(Q_OS_FREEBSD) -#include -#include -#else -#include -#endif -#else +#ifdef Q_WS_WIN #include #endif @@ -168,43 +162,9 @@ long long misc::freeDiskSpaceOnPath(QString path) { if(!dir_path.exists()) return -1; } Q_ASSERT(dir_path.exists()); -#ifndef Q_WS_WIN - unsigned long long available; - struct statfs stats; - const QString statfs_path = dir_path.path()+"/."; - const int ret = statfs (qPrintable(statfs_path), &stats) ; - if(ret == 0) { - available = ((unsigned long long)stats.f_bavail) * - ((unsigned long long)stats.f_bsize) ; - return available; - } else { - return -1; - } -#else - typedef BOOL (WINAPI *GetDiskFreeSpaceEx_t)(LPCTSTR, - PULARGE_INTEGER, - PULARGE_INTEGER, - PULARGE_INTEGER); - GetDiskFreeSpaceEx_t - pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress - ( - ::GetModuleHandle(TEXT("kernel32.dll")), - "GetDiskFreeSpaceExW" - ); - if ( pGetDiskFreeSpaceEx ) - { - ULARGE_INTEGER bytesFree, bytesTotal; - unsigned long long *ret; - if (pGetDiskFreeSpaceEx((LPCTSTR)path.utf16(), &bytesFree, &bytesTotal, NULL)) { - ret = (unsigned long long*)&bytesFree; - return *ret; - } else { - return -1; - } - } else { - return -1; - } -#endif + namespace fs = boost::filesystem; + fs::space_info sp_in = fs::space(fs::path(dir_path.path().toLocal8Bit())); + return sp_in.available; } #ifndef DISABLE_GUI