From 447a5474ddf8b1eb66f3bfd510cf8108e1cb8fcb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 19 Apr 2020 16:53:26 +0200 Subject: Webbox: Sort dirs, files --- plugins/webbox/webbox.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'plugins/webbox/webbox.cpp') diff --git a/plugins/webbox/webbox.cpp b/plugins/webbox/webbox.cpp index 599c36a..3cfd616 100644 --- a/plugins/webbox/webbox.cpp +++ b/plugins/webbox/webbox.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include using namespace std::string_literals; namespace fs = std::filesystem; @@ -269,14 +271,29 @@ protected: } fs::directory_iterator dir(m_path); + std::vector files; + std::vector dirs; for (auto& dir_entry: dir) { - if (dir_entry.is_regular_file() || dir_entry.is_directory()) { - entry.put_value(dir_entry.path().filename().string()); - entry.put(".type", dir_entry.is_directory() ? "dir" : "file"); + if (dir_entry.is_regular_file()) + files.push_back(dir_entry.path().filename().string()); + else if (dir_entry.is_directory()) + dirs.push_back(dir_entry.path().filename().string()); + } + + std::sort(files.begin(), files.end()); + std::sort(dirs.begin(), dirs.end()); + + auto add = [&](std::vector& v, std::string type){ + for (const auto& f: v) { + entry.put_value(f); + entry.put(".type", type); list.push_back(pt::ptree::value_type("listentry", entry)); } - } + }; + add(dirs, "dir"); + add(files, "file"); + tree.push_back(pt::ptree::value_type("list", list)); std::ostringstream ss; -- cgit v1.2.3