I wrote this back when I wrote the question (after voting on QTBUG-3780); I figure I'll save someone (or myself) from doing this from scratch.
#ifdef WIN32
/*
* getDiskFreeSpaceInGB
*
* Returns the amount of free drive space for the given drive in GB. The
* value is rounded to the nearest integer value.
*/
int getDiskFreeSpaceInGB( LPCWSTR drive )
{
ULARGE_INTEGER freeBytesToCaller;
freeBytesToCaller.QuadPart = 0L;
if( !GetDiskFreeSpaceEx( drive, &freeBytesToCaller, NULL, NULL ) )
{
qDebug() << "ERROR: Call to GetDiskFreeSpaceEx() failed.";
}
int freeSpace_gb = freeBytesToCaller.QuadPart / B_per_GB;
qDebug() << "Free drive space: " << freeSpace_gb << "GB";
return freeSpace_gb;
}
#endif
Usage:
// Check available hard drive space
#ifdef WIN32
// The L in front of the string does some WINAPI magic to convert
// a string literal into a Windows LPCWSTR beast.
if( getDiskFreeSpaceInGB( L"c:" ) < MinDriveSpace_GB )
{
errString = "ERROR: Less than the recommended amount of free space available!";
isReady = false;
}
#else
# pragma message( "WARNING: Hard drive space will not be checked at application start-up!" )
#endif