summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r--rbutil/rbutilqt/base/rbunzip.cpp18
-rw-r--r--rbutil/rbutilqt/base/rbunzip.h9
-rw-r--r--rbutil/rbutilqt/base/utils.cpp42
-rw-r--r--rbutil/rbutilqt/base/utils.h1
4 files changed, 65 insertions, 5 deletions
diff --git a/rbutil/rbutilqt/base/rbunzip.cpp b/rbutil/rbutilqt/base/rbunzip.cpp
index 49d12156ea..fb964b52db 100644
--- a/rbutil/rbutilqt/base/rbunzip.cpp
+++ b/rbutil/rbutilqt/base/rbunzip.cpp
@@ -21,6 +21,7 @@
#include <QtCore>
+//! @brief extract archive to destination
UnZip::ErrorCode RbUnZip::extractArchive(const QString& dest)
{
QStringList files = this->fileList();
@@ -41,8 +42,25 @@ UnZip::ErrorCode RbUnZip::extractArchive(const QString& dest)
return error;
}
+
+//! @brief abort an extractArchive() operation.
void RbUnZip::abortUnzip(void)
{
m_abortunzip = true;
}
+
+//! @brief return total size of extracted files in archive.
+qulonglong RbUnZip::totalSize(void)
+{
+ QList<ZipEntry> l = this->entryList();
+ qulonglong total = 0;
+
+ int i = l.size();
+ while(i--)
+ total += l.at(i).uncompressedSize;
+
+ return total;
+
+}
+
diff --git a/rbutil/rbutilqt/base/rbunzip.h b/rbutil/rbutilqt/base/rbunzip.h
index 133437a4e2..c0b7215b6a 100644
--- a/rbutil/rbutilqt/base/rbunzip.h
+++ b/rbutil/rbutilqt/base/rbunzip.h
@@ -28,12 +28,13 @@
class RbUnZip : public QObject, public UnZip
{
- Q_OBJECT
- public:
+ Q_OBJECT
+ public:
UnZip::ErrorCode extractArchive(const QString&);
+ qulonglong totalSize(void);
- signals:
- void unzipProgress(int, int);
+ signals:
+ void unzipProgress(int, int);
public slots:
void abortUnzip(void);
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;
+}
+
diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h
index 19cdca92c9..0a9135485a 100644
--- a/rbutil/rbutilqt/base/utils.h
+++ b/rbutil/rbutilqt/base/utils.h
@@ -28,6 +28,7 @@
bool recRmdir( const QString &dirName );
QString resolvePathCase(QString path);
+qulonglong filesystemFree(QString path);
#endif