diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-04-19 16:53:26 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-04-19 16:53:26 +0200 |
commit | 447a5474ddf8b1eb66f3bfd510cf8108e1cb8fcb (patch) | |
tree | eb05cee2e344b15cc7f114eb63cae9eb611ab5d9 /plugins/webbox | |
parent | 69b0974cbb6ada27d5bbdf0930e3a225acbaf8fb (diff) |
Webbox: Sort dirs, files
Diffstat (limited to 'plugins/webbox')
-rw-r--r-- | plugins/webbox/webbox.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
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 <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> +#include <algorithm> #include <chrono> #include <cstdio> #include <cstdlib> @@ -18,6 +19,7 @@ #include <string> #include <sstream> #include <unordered_map> +#include <vector> using namespace std::string_literals; namespace fs = std::filesystem; @@ -269,14 +271,29 @@ protected: } fs::directory_iterator dir(m_path); + std::vector<std::string> files; + std::vector<std::string> 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("<xmlattr>.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<std::string>& v, std::string type){ + for (const auto& f: v) { + entry.put_value(f); + entry.put("<xmlattr>.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; |