直接用代码实现:
bool SdManager::checkDiskCapacity()
{
bool res = true;
BOOL fResult;
ULARGE_INTEGER i64FreeBytesToCaller;
ULARGE_INTEGER i64TotalBytes;
ULARGE_INTEGER i64FreeBytes;
int freespace = 0;
quint64 totalspace = 0;
QString cachePath = QDir::toNativeSeparators(PathUtils::getSdAppDataPath());
if (cachePath.isEmpty())
{
#ifdef Q_OS_WIN
SdLog("get the curentdir with error %d", GetLastError());
#else
SdLog("get the curentdir with error");
#endif
return res;
}
QString rootPath = cachePath.left(3);
wchar_t rootDisk[32] = { 0 };
wcsncpy_s(rootDisk, sizeof(wchar_t) * 32, rootPath.toStdWString().data(), 3 * sizeof(wchar_t));
fResult = GetDiskFreeSpaceEx(rootDisk,
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult)
{
totalspace = (quint64)i64TotalBytes.QuadPart / 1024 / 1024;
freespace = (quint64)i64FreeBytes.QuadPart / 1024 / 1024;
}
if (freespace < 1024)//小于1G
{
res = false;
}
return res;
}