From 6a4a13b87ac07ed94cde679aa21d875c65ce597b Mon Sep 17 00:00:00 2001 From: bluebrother Date: Fri, 15 Jul 2011 18:13:31 +0000 Subject: [PATCH] Show the total size of the volume along with the free space. This should help identifying the correct player by size, since the free space is only useful to figure if there is enough space to install Rockbox. Change units to GiB since that is more useful given the size of current devices. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30139 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/base/utils.cpp | 36 +++++++++++++++++++++++++++++++----- rbutil/rbutilqt/base/utils.h | 7 +++++++ rbutil/rbutilqt/sysinfo.cpp | 5 +++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index bd2bce060..1a8607b8e 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -115,6 +115,18 @@ QString Utils::resolvePathCase(QString path) //! @return size in bytes qulonglong Utils::filesystemFree(QString path) { + return filesystemSize(path, FilesystemFree); +} + + +qulonglong Utils::filesystemTotal(QString path) +{ + return filesystemSize(path, FilesystemTotal); +} + + +qulonglong Utils::filesystemSize(QString path, enum Utils::Size type) +{ qlonglong size = 0; #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) // the usage of statfs() is deprecated by the LSB so use statvfs(). @@ -123,16 +135,30 @@ qulonglong Utils::filesystemFree(QString path) ret = statvfs(qPrintable(path), &fs); - if(ret == 0) - size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail; + if(ret == 0) { + if(type == FilesystemFree) { + size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_bavail; + } + if(type == FilesystemTotal) { + size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_blocks; + } + } #endif #if defined(Q_OS_WIN32) BOOL ret; ULARGE_INTEGER freeAvailBytes; + ULARGE_INTEGER totalNumberBytes; - ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes, NULL, NULL); - if(ret) - size = freeAvailBytes.QuadPart; + ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes, + &totalNumberBytes, NULL); + if(ret) { + if(type == FilesystemFree) { + size = freeAvailBytes.QuadPart; + } + if(type == FilesystemTotal) { + size = totalNumberBytes.QuadPart; + } + } #endif qDebug() << "[Utils] Filesystem free:" << path << size; return size; diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index ae02a2ca9..bff05cce0 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -31,9 +31,16 @@ class Utils : public QObject { public: + enum Size { + FilesystemTotal, + FilesystemFree + }; + static bool recursiveRmdir(const QString &dirName); static QString resolvePathCase(QString path); static qulonglong filesystemFree(QString path); + static qulonglong filesystemTotal(QString path); + static qulonglong filesystemSize(QString path, enum Size type); static QString findExecutable(QString name); static QString checkEnvironment(bool permission); static int compareVersionStrings(QString s1, QString s2); diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp index a9fa5999b..a28a9bb81 100644 --- a/rbutil/rbutilqt/sysinfo.cpp +++ b/rbutil/rbutilqt/sysinfo.cpp @@ -63,9 +63,10 @@ QString Sysinfo::getInfo() info += "" + tr("Filesystem") + "
"; QStringList drives = Autodetection::mountpoints(); for(int i = 0; i < drives.size(); i++) { - info += tr("%1, %2 MiB available") + info += tr("%1, %2 GiB of %3 GiB available") .arg(QDir::toNativeSeparators(drives.at(i))) - .arg(Utils::filesystemFree(drives.at(i)) / (1024*1024)); + .arg((double)Utils::filesystemFree(drives.at(i)) / (1<<30), 0, 'f', 2) + .arg((double)Utils::filesystemTotal(drives.at(i)) / (1<<30), 0, 'f', 2); if(i + 1 < drives.size()) info += "
"; } -- 2.11.4.GIT