diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-02-09 19:25:45 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-02-09 19:25:45 +0100 |
commit | 678d46a791c4e7a8d31c2693c9abce260177b143 (patch) | |
tree | 431d31c4794d4f97063c821f7e329c5f06e0e494 | |
parent | 5195c84ee9758b29cf1db696e06140e9a9a5284d (diff) |
Sort history by last read time (last updated)
-rw-r--r-- | include/Storage.hpp | 1 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/Storage.cpp | 16 |
3 files changed, 18 insertions, 1 deletions
diff --git a/include/Storage.hpp b/include/Storage.hpp index 4dd8db2..362448f 100644 --- a/include/Storage.hpp +++ b/include/Storage.hpp @@ -23,4 +23,5 @@ namespace QuickMedia { int file_overwrite(const Path &path, const std::string &data); int create_lock_file(const Path &path); void for_files_in_dir(const Path &path, FileIteratorCallback callback); + void for_files_in_dir_sort_last_modified(const Path &path, FileIteratorCallback callback); }
\ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 0c17a52..8e6f04e 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -380,7 +380,7 @@ namespace QuickMedia { exit(1); } // TODO: Make asynchronous - for_files_in_dir(content_storage_dir, [&history_body](const std::filesystem::path &filepath) { + for_files_in_dir_sort_last_modified(content_storage_dir, [&history_body](const std::filesystem::path &filepath) { Path fullpath(filepath.c_str()); Json::Value body; if(!read_file_as_json(fullpath, body)) { diff --git a/src/Storage.cpp b/src/Storage.cpp index ddfdb11..919044e 100644 --- a/src/Storage.cpp +++ b/src/Storage.cpp @@ -131,4 +131,20 @@ namespace QuickMedia { break; } } + + void for_files_in_dir_sort_last_modified(const Path &path, FileIteratorCallback callback) { + std::vector<std::filesystem::directory_entry> paths; + for(auto &p : std::filesystem::directory_iterator(path.data)) { + paths.push_back(p); + } + + std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) { + return path1.last_write_time() > path2.last_write_time(); + }); + + for(auto &p : paths) { + if(!callback(p.path())) + break; + } + } }
\ No newline at end of file |