From: Stefan Neis Date: Sun, 7 Jan 2007 13:52:22 +0000 (+0000) Subject: Added wxGetDiskSpace implementation (patch #1625514). X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/783388d5d9d025ddc1b4fe1d8edb4e2bf32df66b Added wxGetDiskSpace implementation (patch #1625514). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/os2/utils.cpp b/src/os2/utils.cpp index 33d262725b..c32be9c6e6 100644 --- a/src/os2/utils.cpp +++ b/src/os2/utils.cpp @@ -21,6 +21,7 @@ #include "wx/os2/private.h" #include "wx/apptrait.h" +#include "wx/filename.h" #include #ifdef __EMX__ @@ -438,6 +439,51 @@ wxChar* wxGetUserHome ( const wxString &rUser ) return (wxChar*)wxEmptyString; // No home known! } +bool wxGetDiskSpace(const wxString& path, + wxDiskspaceSize_t *pTotal, + wxDiskspaceSize_t *pFree) +{ + if (path.empty()) + return false; + + wxFileName fn(path); + FSALLOCATE fsaBuf = {0}; + APIRET rc = NO_ERROR; + ULONG disknum = 0; + + fn.MakeAbsolute(); + + if (wxDirExists(fn.GetFullPath()) == false) + return false; + + disknum = 1 + wxToupper(fn.GetVolume().GetChar(0)) - _T('A'); + + rc = ::DosQueryFSInfo(disknum, // 1 = A, 2 = B, 3 = C, ... + FSIL_ALLOC, // allocation info + (PVOID)&fsaBuf, + sizeof(FSALLOCATE)); + + if (rc != NO_ERROR) + return false; + else + { + if(pTotal) + { + // to try to avoid 32-bit overflow, let's not multiply right away + // (num of alloc units) + *pTotal = fsaBuf.cUnit; + // * (num of sectors per alloc unit) * (num of bytes per sector) + (*pTotal) *= fsaBuf.cSectorUnit * fsaBuf.cbSector; + } + if(pFree) + { + *pFree = fsaBuf.cUnitAvail; + (*pFree) *= fsaBuf.cSectorUnit * fsaBuf.cbSector; + } + return true; + } +} + wxString wxPMErrorToStr(ERRORID vError) { wxString sError;