mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Utility::freeDiskSpace()
Does not yet work for UNC locations
This commit is contained in:
parent
6c7700c2e7
commit
748ff13bce
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user