]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxGetDiskSpace implementation (patch #1625514).
authorStefan Neis <Stefan.Neis@t-online.de>
Sun, 7 Jan 2007 13:52:22 +0000 (13:52 +0000)
committerStefan Neis <Stefan.Neis@t-online.de>
Sun, 7 Jan 2007 13:52:22 +0000 (13:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/os2/utils.cpp

index 33d262725b7d3c74273123a1480d3ffd73482c93..c32be9c6e697d12bba4b8ba711e1fbdcf7c4f450 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "wx/os2/private.h"
 #include "wx/apptrait.h"
+#include "wx/filename.h"
 
 #include <ctype.h>
 #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;