From 2595f0187a68b34810fdfd354ada03b0b6082b88 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 29 May 2016 20:27:49 +0200 Subject: [PATCH] Changed: Added getDirectorySize() function --- .../client/ryzom_installer/src/utils.cpp | 27 +++++++++++++++++++ .../tools/client/ryzom_installer/src/utils.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index 4cc50f7f0..b07db1e43 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -34,6 +34,33 @@ QString qBytesToHumanReadable(qint64 bytes) return QString::fromUtf8(NLMISC::bytesToHumanReadable(bytes).c_str()); } +qint64 getDirectorySize(const QString &directory) +{ + qint64 size = 0; + QDir dir(directory); + + if (dir.exists()) + { + QFileInfoList list = dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); + + for (int i = 0; i < list.size(); ++i) + { + QFileInfo fileInfo = list.at(i); + + if (fileInfo.isDir()) + { + size += getDirectorySize(fileInfo.absoluteFilePath()); + } + else + { + size += fileInfo.size(); + } + } + } + + return size; +} + QString qFromUtf8(const std::string &str) { return QString::fromUtf8(str.c_str()); diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index a20c93260..8e760b400 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -30,6 +30,8 @@ QString qBytesToHumanReadable(qint64 bytes); +qint64 getDirectorySize(const QString &directory); + // Convert a UTF-8 string to QString QString qFromUtf8(const std::string &str);