summaryrefslogtreecommitdiffstats
path: root/rbutil
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/base/utils.cpp31
-rw-r--r--rbutil/rbutilqt/base/utils.h4
-rw-r--r--rbutil/rbutilqt/base/zipinstaller.cpp3
-rw-r--r--rbutil/rbutilqt/base/ziputil.cpp21
-rw-r--r--rbutil/rbutilqt/base/ziputil.h2
5 files changed, 51 insertions, 10 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index 1fdf627378..ca3a6d2256 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -187,13 +187,25 @@ QString Utils::filesystemName(QString path)
//! @return size in bytes
qulonglong Utils::filesystemFree(QString path)
{
- return filesystemSize(path, FilesystemFree);
+ qulonglong size = filesystemSize(path, FilesystemFree);
+ qDebug() << "[Utils] free disk space for" << path << size;
+ return size;
}
qulonglong Utils::filesystemTotal(QString path)
{
- return filesystemSize(path, FilesystemTotal);
+ qulonglong size = filesystemSize(path, FilesystemTotal);
+ qDebug() << "[Utils] total disk space for" << path << size;
+ return size;
+}
+
+
+qulonglong Utils::filesystemClusterSize(QString path)
+{
+ qulonglong size = filesystemSize(path, FilesystemClusterSize);
+ qDebug() << "[Utils] cluster size for" << path << size;
+ return size;
}
@@ -214,6 +226,9 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
if(type == FilesystemTotal) {
size = (qulonglong)fs.f_frsize * (qulonglong)fs.f_blocks;
}
+ if(type == FilesystemClusterSize) {
+ size = (qulonglong)fs.f_frsize;
+ }
}
#endif
#if defined(Q_OS_WIN32)
@@ -230,9 +245,19 @@ qulonglong Utils::filesystemSize(QString path, enum Utils::Size type)
if(type == FilesystemTotal) {
size = totalNumberBytes.QuadPart;
}
+ if(type == FilesystemClusterSize) {
+ DWORD sectorsPerCluster;
+ DWORD bytesPerSector;
+ DWORD freeClusters;
+ DWORD totalClusters;
+ ret = GetDiskFreeSpaceW((LPCTSTR)path.utf16(), &sectorsPerCluster,
+ &bytesPerSector, &freeClusters, &totalClusters);
+ if(ret) {
+ size = bytesPerSector * sectorsPerCluster;
+ }
+ }
}
#endif
- qDebug() << "[Utils] Filesystem:" << path << size;
return size;
}
diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h
index 659bbc4ed4..b4477699fd 100644
--- a/rbutil/rbutilqt/base/utils.h
+++ b/rbutil/rbutilqt/base/utils.h
@@ -33,13 +33,15 @@ class Utils : public QObject
public:
enum Size {
FilesystemTotal,
- FilesystemFree
+ FilesystemFree,
+ FilesystemClusterSize,
};
static bool recursiveRmdir(const QString &dirName);
static QString resolvePathCase(QString path);
static qulonglong filesystemFree(QString path);
static qulonglong filesystemTotal(QString path);
+ static qulonglong filesystemClusterSize(QString path);
static qulonglong filesystemSize(QString path, enum Size type);
static QString findExecutable(QString name);
static QString checkEnvironment(bool permission);
diff --git a/rbutil/rbutilqt/base/zipinstaller.cpp b/rbutil/rbutilqt/base/zipinstaller.cpp
index 76f673ff81..c450f3015f 100644
--- a/rbutil/rbutilqt/base/zipinstaller.cpp
+++ b/rbutil/rbutilqt/base/zipinstaller.cpp
@@ -140,7 +140,8 @@ void ZipInstaller::downloadDone(bool error)
// some room for operating (also includes calculation mistakes due to
// cluster sizes on the player).
if((qint64)Utils::filesystemFree(m_mountpoint)
- < (zip.totalUncompressedSize() + 1000000)) {
+ < (zip.totalUncompressedSize(Utils::filesystemClusterSize(m_mountpoint))
+ + 1000000)) {
emit logItem(tr("Not enough disk space! Aborting."), LOGERROR);
emit logProgress(1, 1);
emit done(true);
diff --git a/rbutil/rbutilqt/base/ziputil.cpp b/rbutil/rbutilqt/base/ziputil.cpp
index ed8f17eefe..4396fa5e87 100644
--- a/rbutil/rbutilqt/base/ziputil.cpp
+++ b/rbutil/rbutilqt/base/ziputil.cpp
@@ -205,7 +205,7 @@ bool ZipUtil::appendFileToArchive(QString& file, QString& basedir)
//! @brief calculate total size of extracted files
-qint64 ZipUtil::totalUncompressedSize(void)
+qint64 ZipUtil::totalUncompressedSize(unsigned int clustersize)
{
qint64 uncompressed = 0;
@@ -214,10 +214,23 @@ qint64 ZipUtil::totalUncompressedSize(void)
return -1;
}
int max = items.size();
- for(int i = 0; i < max; ++i) {
- uncompressed += items.at(i).uncompressedSize;
+ if(clustersize > 0) {
+ for(int i = 0; i < max; ++i) {
+ qint64 item = items.at(i).uncompressedSize;
+ uncompressed += (item + clustersize - (item % clustersize));
+ }
+ }
+ else {
+ for(int i = 0; i < max; ++i) {
+ uncompressed += items.at(i).uncompressedSize;
+ }
+ }
+ if(clustersize > 0) {
+ qDebug() << "[ZipUtil] calculation rounded to cluster size for each file:"
+ << clustersize;
}
- qDebug() << "[ZipUtil] size of archive files uncompressed:" << uncompressed;
+ qDebug() << "[ZipUtil] size of archive files uncompressed:"
+ << uncompressed;
return uncompressed;
}
diff --git a/rbutil/rbutilqt/base/ziputil.h b/rbutil/rbutilqt/base/ziputil.h
index cfafb96566..dc1b986c29 100644
--- a/rbutil/rbutilqt/base/ziputil.h
+++ b/rbutil/rbutilqt/base/ziputil.h
@@ -37,7 +37,7 @@ class ZipUtil : public QObject
bool extractArchive(QString& dest);
bool appendDirToArchive(QString& source, QString& basedir);
bool appendFileToArchive(QString& file, QString& basedir);
- qint64 totalUncompressedSize(void);
+ qint64 totalUncompressedSize(unsigned int clustersize = 0);
QStringList files(void);
signals: