Added wxGetDiskSpace implementation (patch #1625514).
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user