diff --git a/libs/os/filesize.h b/libs/os/filesize.h new file mode 100644 index 0000000000..44174b50d9 --- /dev/null +++ b/libs/os/filesize.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace os +{ + +// Formats the given number in bytes/kB/MB/GB +inline std::string getFormattedFileSize(std::size_t size) +{ + if (size > 1024 * 1024 * 1024) + { + return fmt::format("{0:0.2f} GB", (static_cast(size) / (1024 * 1024 * 1024))); + } + else if (size > 1024 * 1024) + { + return fmt::format("{0:0.1f} MB", (static_cast(size) / (1024 * 1024))); + } + else if (size > 1024) + { + return fmt::format("{0:0.0f} kB", (static_cast(size) / 1024)); + } + else + { + return fmt::format("{0:d} bytes", size); + } +} + +} diff --git a/libs/wxutil/fsview/FileSystemView.cpp b/libs/wxutil/fsview/FileSystemView.cpp index 956f82e6c0..28d92a7d20 100644 --- a/libs/wxutil/fsview/FileSystemView.cpp +++ b/libs/wxutil/fsview/FileSystemView.cpp @@ -50,6 +50,9 @@ FileSystemView::FileSystemView(wxWindow* parent, const TreeModel::Ptr& model, lo AppendIconTextColumn(_("File"), Columns().filename.getColumnIndex(), wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE); + AppendTextColumn(_("Size"), Columns().size.getColumnIndex(), + wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_RIGHT, wxDATAVIEW_COL_SORTABLE); + // Get selection and connect the changed callback Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, &FileSystemView::OnSelectionChanged, this); Bind(EV_TREEMODEL_POPULATION_FINISHED, &FileSystemView::OnTreeStorePopulationFinished, this); diff --git a/libs/wxutil/fsview/Populator.cpp b/libs/wxutil/fsview/Populator.cpp index 526d9b19e7..3c9edc2477 100644 --- a/libs/wxutil/fsview/Populator.cpp +++ b/libs/wxutil/fsview/Populator.cpp @@ -1,7 +1,9 @@ #include "Populator.h" #include "iuimanager.h" +#include "iarchive.h" #include "os/path.h" +#include "os/filesize.h" #include @@ -123,6 +125,10 @@ void Populator::visit(wxutil::TreeModel& /* store */, wxutil::TreeModel::Row& ro isExplicit ? _fileIcon : _folderIcon)); row[_columns.vfspath] = _basePath + path; row[_columns.isFolder] = !isExplicit; + + // Get the file size if possible + auto file = GlobalFileSystem().openFile(_basePath + path); + row[_columns.size] = os::getFormattedFileSize(file ? file->size() : -1); } } diff --git a/libs/wxutil/fsview/Populator.h b/libs/wxutil/fsview/Populator.h index 72e4009c05..355ced2875 100644 --- a/libs/wxutil/fsview/Populator.h +++ b/libs/wxutil/fsview/Populator.h @@ -15,14 +15,16 @@ struct TreeColumns : public TreeModel::ColumnRecord { TreeColumns() : - filename(add(wxutil::TreeModel::Column::IconText)), - vfspath(add(wxutil::TreeModel::Column::String)), - isFolder(add(wxutil::TreeModel::Column::Boolean)) + filename(add(TreeModel::Column::IconText)), + vfspath(add(TreeModel::Column::String)), + isFolder(add(TreeModel::Column::Boolean)), + size(add(TreeModel::Column::String)) {} - wxutil::TreeModel::Column filename; // e.g. "chair1.pfb" - wxutil::TreeModel::Column vfspath; // e.g. "prefabs/chair1.pfb" - wxutil::TreeModel::Column isFolder; // whether this is a folder + TreeModel::Column filename; // e.g. "chair1.pfb" + TreeModel::Column vfspath; // e.g. "prefabs/chair1.pfb" + TreeModel::Column isFolder; // whether this is a folder + TreeModel::Column size; // file size string }; class Populator : diff --git a/tools/msvc/libs.vcxproj b/tools/msvc/libs.vcxproj index cf03ca6fe2..e6240ee6cc 100644 --- a/tools/msvc/libs.vcxproj +++ b/tools/msvc/libs.vcxproj @@ -174,6 +174,7 @@ + diff --git a/tools/msvc/libs.vcxproj.filters b/tools/msvc/libs.vcxproj.filters index 02f16eebd2..ab1086396f 100644 --- a/tools/msvc/libs.vcxproj.filters +++ b/tools/msvc/libs.vcxproj.filters @@ -265,6 +265,9 @@ stream + + os +