summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/utils.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-12-13 20:09:31 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-12-13 20:09:31 +0000
commitbc7917daeb494de9c17d2daf779c7cd612329e35 (patch)
tree659bc54c9779050750db51e3d6b32d0b4db4475a /rbutil/rbutilqt/base/utils.cpp
parentb42f379fa3f354ccc94266604bd30ac4f7ad70de (diff)
downloadrockbox-bc7917daeb494de9c17d2daf779c7cd612329e35.tar.gz
rockbox-bc7917daeb494de9c17d2daf779c7cd612329e35.zip
Make Rockbox Utility error out if the zip file its going to install requires more space than left on the device. Calculation adds a safety space of 1MB so you need at least 1MB more free space than the extracted archive. This also catches differences due to the size calculation not taking cluster losses into account. Free disk space is also displayed in the sysinfo dialog. Fixes FS#9417.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19428 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/utils.cpp')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index a6a80c6eef..64fc18e449 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -32,6 +32,9 @@
#include <tchar.h>
#include <winioctl.h>
#endif
+#if defined(Q_OS_LINUX)
+#include <sys/statvfs.h>
+#endif
// recursive function to delete a dir with files
bool recRmdir( const QString &dirName )
@@ -78,7 +81,7 @@ QString resolvePathCase(QString path)
for(int i = start; i < elems.size(); i++) {
QStringList direlems
- = QDir(realpath).entryList(QDir::AllEntries|QDir::Hidden|QDir::System);
+ = QDir(realpath).entryList(QDir::AllEntries|QDir::Hidden|QDir::System);
if(direlems.contains(elems.at(i), Qt::CaseInsensitive)) {
// need to filter using QRegExp as QStringList::filter(QString)
// matches any substring
@@ -99,3 +102,40 @@ QString resolvePathCase(QString path)
return realpath;
}
+
+//! @brief figure the free disk space on a filesystem
+//! @param path path on the filesystem to check
+//! @return size in bytes
+qulonglong filesystemFree(QString path)
+{
+ qlonglong size = 0;
+#if defined(Q_OS_LINUX)
+ // the usage of statfs() is deprecated by the LSB so use statvfs().
+ struct statvfs fs;
+ int ret;
+
+ ret = statvfs(qPrintable(path), &fs);
+
+ if(ret == 0)
+ size = fs.f_bsize * fs.f_bavail;
+#endif
+#if defined(Q_OS_MACX)
+ struct statfs fs;
+ int ret;
+
+ ret = statfs(qPrintable(path), &fs);
+
+ if(ret == 0)
+ size = fs.f_bsize * fs.f_bavail;
+#endif
+#if defined(Q_OS_WIN32)
+ BOOL ret;
+ ULARGE_INTEGER freeAvailBytes;
+
+ ret = GetDiskFreeSpaceExW((LPCTSTR)path.utf16(), &freeAvailBytes, NULL, NULL);
+ if(ret)
+ size = freeAvailBytes.QuadPart;
+#endif
+ return size;
+}
+