diff --git a/Source/Core/DiscIO/Filesystem.cpp b/Source/Core/DiscIO/Filesystem.cpp index 9e5336db5d..68a7decb3e 100644 --- a/Source/Core/DiscIO/Filesystem.cpp +++ b/Source/Core/DiscIO/Filesystem.cpp @@ -8,6 +8,19 @@ namespace DiscIO { FileInfo::~FileInfo() = default; +u64 FileInfo::GetTotalSize() const +{ + if (!IsDirectory()) + return GetSize(); + + u64 size = 0; + + for (const auto& entry : *this) + size += entry.GetTotalSize(); + + return size; +} + FileSystem::~FileSystem() = default; -} // namespace +} // namespace DiscIO diff --git a/Source/Core/DiscIO/Filesystem.h b/Source/Core/DiscIO/Filesystem.h index 37dc7f9b7e..ad631b078b 100644 --- a/Source/Core/DiscIO/Filesystem.h +++ b/Source/Core/DiscIO/Filesystem.h @@ -86,6 +86,8 @@ public: // The size of a file. // Not guaranteed to return a meaningful value for directories. virtual u32 GetSize() const = 0; + // For a file, returns its size. For a directory, returns the total size of its contents. + u64 GetTotalSize() const; virtual bool IsDirectory() const = 0; // The number of files and directories in a directory, including those in subdirectories. // Not guaranteed to return a meaningful value for files. @@ -124,4 +126,4 @@ public: // because it will check IsValid for you, will automatically pick the right type of filesystem, // and will cache the filesystem in case it's needed again later. -} // namespace +} // namespace DiscIO diff --git a/Source/Core/DolphinQt2/Config/FilesystemWidget.cpp b/Source/Core/DolphinQt2/Config/FilesystemWidget.cpp index bfae5b78df..165ef0fd09 100644 --- a/Source/Core/DolphinQt2/Config/FilesystemWidget.cpp +++ b/Source/Core/DolphinQt2/Config/FilesystemWidget.cpp @@ -25,6 +25,8 @@ #include "DolphinQt2/QtUtils/ActionHelper.h" #include "DolphinQt2/Resources.h" +#include "UICommon/UICommon.h" + constexpr int ENTRY_PARTITION = Qt::UserRole; constexpr int ENTRY_NAME = Qt::UserRole + 1; constexpr int ENTRY_TYPE = Qt::UserRole + 2; @@ -52,11 +54,18 @@ void FilesystemWidget::CreateWidgets() { auto* layout = new QVBoxLayout; - m_tree_model = new QStandardItemModel(0, 1); + m_tree_model = new QStandardItemModel(0, 2); + m_tree_model->setHorizontalHeaderLabels({tr("Name"), tr("Size")}); + m_tree_view = new QTreeView(this); m_tree_view->setModel(m_tree_model); m_tree_view->setContextMenuPolicy(Qt::CustomContextMenu); - m_tree_view->header()->hide(); + + auto* header = m_tree_view->header(); + + header->setSectionResizeMode(0, QHeaderView::Stretch); + header->setSectionResizeMode(1, QHeaderView::ResizeToContents); + header->setStretchLastSection(false); // Windows: Set style to (old) windows, which draws branch lines #ifdef _WIN32 @@ -132,7 +141,14 @@ void FilesystemWidget::PopulateDirectory(int partition_id, QStandardItem* root, item->setData(QString::fromStdString(info.GetPath()), ENTRY_NAME); item->setData(QVariant::fromValue(info.IsDirectory() ? EntryType::Dir : EntryType::File), ENTRY_TYPE); - root->appendRow(item); + + const auto size = info.GetTotalSize(); + + auto* size_item = new QStandardItem(QString::fromStdString(UICommon::FormatSize(size))); + size_item->setTextAlignment(Qt::AlignRight); + size_item->setEditable(false); + + root->appendRow({item, size_item}); } }