Fixed folder size
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
f828ea8929
commit
4d93f4adb1
@ -206,8 +206,8 @@ int64_t calculateWorldSize(const QFileInfo& file)
|
|||||||
QDirIterator it(file.absoluteFilePath(), QDir::Files, QDirIterator::Subdirectories);
|
QDirIterator it(file.absoluteFilePath(), QDir::Files, QDirIterator::Subdirectories);
|
||||||
int64_t total = 0;
|
int64_t total = 0;
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
total += it.fileInfo().size();
|
|
||||||
it.next();
|
it.next();
|
||||||
|
total += it.fileInfo().size();
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ QVariant ModFolderModel::data(const QModelIndex& index, int role) const
|
|||||||
return provider.value();
|
return provider.value();
|
||||||
}
|
}
|
||||||
case SizeColumn:
|
case SizeColumn:
|
||||||
return StringUtils::humanReadableFileSize(m_resources[row]->fileinfo().size(), true);
|
return StringUtils::humanReadableFileSize(m_resources[row]->size(), true);
|
||||||
default:
|
default:
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
|
|
||||||
|
#include <QDirIterator>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@ -18,6 +19,20 @@ void Resource::setFile(QFileInfo file_info)
|
|||||||
parseFile();
|
parseFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 calculateFileSize(const QFileInfo& file)
|
||||||
|
{
|
||||||
|
if (file.isDir()) {
|
||||||
|
QDirIterator it(file.absoluteFilePath(), QDir::Files);
|
||||||
|
qint64 total = 0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
total += it.fileInfo().size();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
return file.size();
|
||||||
|
}
|
||||||
|
|
||||||
void Resource::parseFile()
|
void Resource::parseFile()
|
||||||
{
|
{
|
||||||
QString file_name{ m_file_info.fileName() };
|
QString file_name{ m_file_info.fileName() };
|
||||||
@ -26,6 +41,7 @@ void Resource::parseFile()
|
|||||||
|
|
||||||
m_internal_id = file_name;
|
m_internal_id = file_name;
|
||||||
|
|
||||||
|
m_size = calculateFileSize(m_file_info);
|
||||||
if (m_file_info.isDir()) {
|
if (m_file_info.isDir()) {
|
||||||
m_type = ResourceType::FOLDER;
|
m_type = ResourceType::FOLDER;
|
||||||
m_name = file_name;
|
m_name = file_name;
|
||||||
@ -90,9 +106,9 @@ std::pair<int, bool> Resource::compare(const Resource& other, SortType type) con
|
|||||||
return { -1, type == SortType::DATE };
|
return { -1, type == SortType::DATE };
|
||||||
break;
|
break;
|
||||||
case SortType::SIZE: {
|
case SortType::SIZE: {
|
||||||
if (fileinfo().size() > other.fileinfo().size())
|
if (size() > other.size())
|
||||||
return { 1, type == SortType::SIZE };
|
return { 1, type == SortType::SIZE };
|
||||||
if (fileinfo().size() < other.fileinfo().size())
|
if (size() < other.size())
|
||||||
return { -1, type == SortType::SIZE };
|
return { -1, type == SortType::SIZE };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ class Resource : public QObject {
|
|||||||
[[nodiscard]] auto internal_id() const -> QString { return m_internal_id; }
|
[[nodiscard]] auto internal_id() const -> QString { return m_internal_id; }
|
||||||
[[nodiscard]] auto type() const -> ResourceType { return m_type; }
|
[[nodiscard]] auto type() const -> ResourceType { return m_type; }
|
||||||
[[nodiscard]] bool enabled() const { return m_enabled; }
|
[[nodiscard]] bool enabled() const { return m_enabled; }
|
||||||
|
[[nodiscard]] qint64 size() const { return m_size; }
|
||||||
|
|
||||||
[[nodiscard]] virtual auto name() const -> QString { return m_name; }
|
[[nodiscard]] virtual auto name() const -> QString { return m_name; }
|
||||||
[[nodiscard]] virtual bool valid() const { return m_type != ResourceType::UNKNOWN; }
|
[[nodiscard]] virtual bool valid() const { return m_type != ResourceType::UNKNOWN; }
|
||||||
@ -117,4 +118,5 @@ class Resource : public QObject {
|
|||||||
bool m_is_resolving = false;
|
bool m_is_resolving = false;
|
||||||
bool m_is_resolved = false;
|
bool m_is_resolved = false;
|
||||||
int m_resolution_ticket = 0;
|
int m_resolution_ticket = 0;
|
||||||
|
qint64 m_size = 0;
|
||||||
};
|
};
|
||||||
|
@ -416,7 +416,7 @@ QVariant ResourceFolderModel::data(const QModelIndex& index, int role) const
|
|||||||
case DateColumn:
|
case DateColumn:
|
||||||
return m_resources[row]->dateTimeChanged();
|
return m_resources[row]->dateTimeChanged();
|
||||||
case SizeColumn:
|
case SizeColumn:
|
||||||
return StringUtils::humanReadableFileSize(m_resources[row]->fileinfo().size(), true);
|
return StringUtils::humanReadableFileSize(m_resources[row]->size(), true);
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
|
|||||||
case DateColumn:
|
case DateColumn:
|
||||||
return m_resources[row]->dateTimeChanged();
|
return m_resources[row]->dateTimeChanged();
|
||||||
case SizeColumn:
|
case SizeColumn:
|
||||||
return StringUtils::humanReadableFileSize(m_resources[row]->fileinfo().size(), true);
|
return StringUtils::humanReadableFileSize(m_resources[row]->size(), true);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
|
@ -79,7 +79,7 @@ QVariant TexturePackFolderModel::data(const QModelIndex& index, int role) const
|
|||||||
case DateColumn:
|
case DateColumn:
|
||||||
return m_resources[row]->dateTimeChanged();
|
return m_resources[row]->dateTimeChanged();
|
||||||
case SizeColumn:
|
case SizeColumn:
|
||||||
return StringUtils::humanReadableFileSize(m_resources[row]->fileinfo().size(), true);
|
return StringUtils::humanReadableFileSize(m_resources[row]->size(), true);
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user