diff options
Diffstat (limited to 'plugins/webbox/webbox.cpp')
-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; |