diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 369ad3936..4e98d1520 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -110,7 +110,7 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const return provider.value(); } case SizeColumn: - return StringUtils::humanReadableFileSize(m_resources[row]->size(), true); + return m_resources[row]->sizeStr(); default: return QVariant(); } diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 72652cefb..d8727db0a 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -5,6 +5,7 @@ #include #include "FileSystem.h" +#include "StringUtils.h" Resource::Resource(QObject* parent) : QObject(parent) {} @@ -19,18 +20,18 @@ void Resource::setFile(QFileInfo file_info) parseFile(); } -qint64 calculateFileSize(const QFileInfo& file) +QString calculateFileSize(const QFileInfo& file) { if (file.isDir()) { - QDirIterator it(file.absoluteFilePath(), QDir::Files, QDirIterator::Subdirectories); - qint64 total = 0; - while (it.hasNext()) { - it.next(); - total += it.fileInfo().size(); - } - return total; + auto dir = QDir(file.absoluteFilePath()); + dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); + auto count = dir.count(); + auto str = QObject::tr("item"); + if (count != 1) + str = QObject::tr("items"); + return QString("%1 %2").arg(QString::number(count), str); } - return file.size(); + return StringUtils::humanReadableFileSize(file.size(), true); } void Resource::parseFile() @@ -41,7 +42,7 @@ void Resource::parseFile() m_internal_id = file_name; - m_size = calculateFileSize(m_file_info); + m_size_str = calculateFileSize(m_file_info); if (m_file_info.isDir()) { m_type = ResourceType::FOLDER; m_name = file_name; @@ -106,9 +107,9 @@ std::pair Resource::compare(const Resource& other, SortType type) con return { -1, type == SortType::DATE }; break; case SortType::SIZE: { - if (size() > other.size()) + if (fileinfo().size() > other.fileinfo().size()) return { 1, type == SortType::SIZE }; - if (size() < other.size()) + if (fileinfo().size() < other.fileinfo().size()) return { -1, type == SortType::SIZE }; break; } diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h index 61949f917..029afbd5b 100644 --- a/launcher/minecraft/mod/Resource.h +++ b/launcher/minecraft/mod/Resource.h @@ -45,7 +45,7 @@ class Resource : public QObject { [[nodiscard]] auto internal_id() const -> QString { return m_internal_id; } [[nodiscard]] auto type() const -> ResourceType { return m_type; } [[nodiscard]] bool enabled() const { return m_enabled; } - [[nodiscard]] qint64 size() const { return m_size; } + [[nodiscard]] QString sizeStr() const { return m_size_str; } [[nodiscard]] virtual auto name() const -> QString { return m_name; } [[nodiscard]] virtual bool valid() const { return m_type != ResourceType::UNKNOWN; } @@ -118,5 +118,5 @@ class Resource : public QObject { bool m_is_resolving = false; bool m_is_resolved = false; int m_resolution_ticket = 0; - qint64 m_size = 0; + QString m_size_str; }; diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index 6a9c5b7dd..8e14f4e80 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -417,7 +417,7 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const case DateColumn: return m_resources[row]->dateTimeChanged(); case SizeColumn: - return StringUtils::humanReadableFileSize(m_resources[row]->size(), true); + return m_resources[row]->sizeStr(); default: return {}; } diff --git a/launcher/minecraft/mod/ResourcePackFolderModel.cpp b/launcher/minecraft/mod/ResourcePackFolderModel.cpp index 7a6138833..7ad7b3038 100644 --- a/launcher/minecraft/mod/ResourcePackFolderModel.cpp +++ b/launcher/minecraft/mod/ResourcePackFolderModel.cpp @@ -88,7 +88,7 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const case DateColumn: return m_resources[row]->dateTimeChanged(); case SizeColumn: - return StringUtils::humanReadableFileSize(m_resources[row]->size(), true); + return m_resources[row]->sizeStr(); default: return {}; diff --git a/launcher/minecraft/mod/TexturePackFolderModel.cpp b/launcher/minecraft/mod/TexturePackFolderModel.cpp index 38db9d8ff..a042c9113 100644 --- a/launcher/minecraft/mod/TexturePackFolderModel.cpp +++ b/launcher/minecraft/mod/TexturePackFolderModel.cpp @@ -79,7 +79,7 @@ QVariant TexturePackFolderModel::data(const QModelIndex& index, int role) const case DateColumn: return m_resources[row]->dateTimeChanged(); case SizeColumn: - return StringUtils::humanReadableFileSize(m_resources[row]->size(), true); + return m_resources[row]->sizeStr(); default: return {}; }