Utility::freeDiskSpace()

Does not yet work for UNC locations
This commit is contained in:
Daniel Molkentin 2013-07-07 01:23:25 +02:00
parent 6c7700c2e7
commit 748ff13bce
2 changed files with 28 additions and 3 deletions

View File

@ -23,11 +23,14 @@
#include <QWidget>
#include <QDebug>
#ifdef Q_OS_MAC
#ifdef Q_OS_UNIX
#include <sys/statvfs.h>
#include <sys/types.h>
#elif defined(Q_OS_MAC)
#include <CoreServices/CoreServices.h>
#endif
#ifdef Q_OS_WIN
#elif defined(Q_OS_WIN)
#include <shlobj.h>
#include <winbase.h>
#endif
namespace Mirall {
@ -240,4 +243,25 @@ void Utility::setLaunchOnStartup(const QString &appName, const QString& guiName,
#endif
}
qint64 Utility::freeDiskSpace(const QString &path, bool *ok)
{
#ifdef Q_OS_UNIX
Q_UNUSED(ok)
struct statvfs64 stat;
statvfs64(path.toUtf8().data(), &stat);
return (qint64) stat.f_bavail * stat.f_frsize;
#elif defined(Q_OS_WIN)
ULARGE_INTEGER freeBytes;
freeBytes.QuadPart = 0L;
QString drive = QDir().absoluteFilePath(path).left(2);
if( !GetDiskFreeSpaceEx( reinterpret_cast<const wchar_t *>(drive.utf16()), &freeBytes, NULL, NULL ) ) {
if (ok) *ok = false;
}
return freeBytes.QuadPart;
#else
if (ok) *ok = false;
return 0;
#endif
}
} // namespace Mirall

View File

@ -31,6 +31,7 @@ namespace Utility
void raiseDialog(QWidget *);
bool hasLaunchOnStartup(const QString &appName);
void setLaunchOnStartup(const QString &appName, const QString& guiName, bool launch);
qint64 freeDiskSpace(const QString &path, bool *ok = 0);
}
}