diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/base/utils.cpp | 14 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/utils.h | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/configure.cpp | 7 |
3 files changed, 16 insertions, 6 deletions
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index 3ab8aa6906..f2d3f04887 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -1046,3 +1046,17 @@ bool Utils::ejectDevice(QString device) return false; } + +qint64 Utils::recursiveFolderSize(QString path) +{ + qint64 size = 0; + QList<QFileInfo> items = QDir(path).entryInfoList(QDir::Files | QDir::NoDotAndDotDot); + for (auto item: items) { + size += item.size(); + } + QList<QString> folders = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for (auto folder: folders) { + size += recursiveFolderSize(path + "/" + folder); + } + return size; +} diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index f46f713525..7f27c7d321 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -57,6 +57,7 @@ public: static QMap<QString, QList<int> > findRunningProcess(QStringList names); static QList<int> suspendProcess(QList<int> pidlist, bool suspend); static bool ejectDevice(QString device); + static qint64 recursiveFolderSize(QString path); }; #endif diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp index c2ab61b36d..507d0bec41 100644 --- a/rbutil/rbutilqt/configure.cpp +++ b/rbutil/rbutilqt/configure.cpp @@ -306,12 +306,7 @@ void Config::setUserSettings() void Config::updateCacheInfo(QString path) { - QList<QFileInfo> fs; - fs = QDir(path + "/rbutil-cache/").entryInfoList(QDir::Files | QDir::NoDotAndDotDot); - qint64 sz = 0; - for(int i = 0; i < fs.size(); i++) { - sz += fs.at(i).size(); - } + qint64 sz = Utils::recursiveFolderSize(path + "/rbutil-cache"); ui.cacheSize->setText(tr("Current cache size is %L1 kiB.") .arg(sz/1024)); } |