mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Optimize logs folder size calculation (#3427)
This commit is contained in:
parent
4f01ea4ab6
commit
34203dfa7c
2 changed files with 15 additions and 20 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "providers/twitch/TwitchCommon.hpp"
|
#include "providers/twitch/TwitchCommon.hpp"
|
||||||
|
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
|
|
|
@ -23,22 +23,17 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
qint64 dirSize(QString dirPath)
|
qint64 dirSize(QString &dirPath)
|
||||||
{
|
{
|
||||||
|
QDirIterator it(dirPath, QDirIterator::Subdirectories);
|
||||||
qint64 size = 0;
|
qint64 size = 0;
|
||||||
QDir dir(dirPath);
|
|
||||||
// calculate total size of current directories' files
|
while (it.hasNext())
|
||||||
QDir::Filters fileFilters = QDir::Files | QDir::System | QDir::Hidden;
|
|
||||||
for (QString filePath : dir.entryList(fileFilters))
|
|
||||||
{
|
{
|
||||||
QFileInfo fi(dir, filePath);
|
size += it.fileInfo().size();
|
||||||
size += fi.size();
|
it.next();
|
||||||
}
|
}
|
||||||
// add size of child directories recursively
|
|
||||||
QDir::Filters dirFilters =
|
|
||||||
QDir::Dirs | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden;
|
|
||||||
for (QString childDirPath : dir.entryList(dirFilters))
|
|
||||||
size += dirSize(dirPath + QDir::separator() + childDirPath);
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,15 +53,14 @@ QString formatSize(qint64 size)
|
||||||
|
|
||||||
QString fetchLogDirectorySize()
|
QString fetchLogDirectorySize()
|
||||||
{
|
{
|
||||||
QString logPathDirectory = getSettings()->logPath.getValue().isEmpty()
|
QString logsDirectoryPath = getSettings()->logPath.getValue().isEmpty()
|
||||||
? getPaths()->messageLogDirectory
|
? getPaths()->messageLogDirectory
|
||||||
: getSettings()->logPath;
|
: getSettings()->logPath;
|
||||||
|
|
||||||
qint64 logsSize = dirSize(logPathDirectory);
|
auto logsSize = dirSize(logsDirectoryPath);
|
||||||
QString logsSizeLabel = "Your logs currently take up ";
|
|
||||||
logsSizeLabel += formatSize(logsSize);
|
return QString("Your logs currently take up %1 of space")
|
||||||
logsSizeLabel += " of space";
|
.arg(formatSize(logsSize));
|
||||||
return logsSizeLabel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ModerationPage::ModerationPage()
|
ModerationPage::ModerationPage()
|
||||||
|
|
Loading…
Reference in a new issue