From 678d46a791c4e7a8d31c2693c9abce260177b143 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 9 Feb 2020 19:25:45 +0100 Subject: Sort history by last read time (last updated) --- src/Storage.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/Storage.cpp') 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 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 -- cgit v1.2.3