aboutsummaryrefslogtreecommitdiff
path: root/src/Storage.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-11 00:42:21 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-11 00:42:21 +0100
commit1f74222bf4cfadead768b095c6b3f8d422ebf84c (patch)
tree39035288edb79852cef6237f0d7ab8ea146cf218 /src/Storage.cpp
parent404ac476a213164a041f0f53be30855df815aa6a (diff)
Add local-manga plugin to read local manga
Diffstat (limited to 'src/Storage.cpp')
-rw-r--r--src/Storage.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/Storage.cpp b/src/Storage.cpp
index 2754bc8..a0f20e4 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -256,7 +256,7 @@ namespace QuickMedia {
}
}
- void for_files_in_dir_sort_last_modified(const Path &path, FileIteratorCallback callback) {
+ void for_files_in_dir_sort_last_modified(const Path &path, FileIteratorCallback callback, FileSortDirection sort_dir) {
std::vector<std::filesystem::directory_entry> paths;
try {
for(auto &p : std::filesystem::directory_iterator(path.data)) {
@@ -267,9 +267,42 @@ namespace QuickMedia {
return;
}
- std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) {
- return file_get_filetime_or(path1, std::filesystem::file_time_type::min()) > file_get_filetime_or(path2, std::filesystem::file_time_type::min());
- });
+ if(sort_dir == FileSortDirection::ASC) {
+ std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) {
+ return file_get_filetime_or(path1, std::filesystem::file_time_type::min()) > file_get_filetime_or(path2, std::filesystem::file_time_type::min());
+ });
+ } else {
+ std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) {
+ return file_get_filetime_or(path1, std::filesystem::file_time_type::min()) < file_get_filetime_or(path2, std::filesystem::file_time_type::min());
+ });
+ }
+
+ for(auto &p : paths) {
+ if(!callback(p.path().string()))
+ break;
+ }
+ }
+
+ void for_files_in_dir_sort_name(const Path &path, FileIteratorCallback callback, FileSortDirection sort_dir) {
+ std::vector<std::filesystem::directory_entry> paths;
+ try {
+ for(auto &p : std::filesystem::directory_iterator(path.data)) {
+ paths.push_back(p);
+ }
+ } catch(const std::filesystem::filesystem_error &err) {
+ fprintf(stderr, "Failed to list files in directory %s, error: %s\n", path.data.c_str(), err.what());
+ return;
+ }
+
+ if(sort_dir == FileSortDirection::ASC) {
+ std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) {
+ return path1.path().filename() < path2.path().filename();
+ });
+ } else {
+ std::sort(paths.begin(), paths.end(), [](const std::filesystem::directory_entry &path1, std::filesystem::directory_entry &path2) {
+ return path1.path().filename() > path2.path().filename();
+ });
+ }
for(auto &p : paths) {
if(!callback(p.path().string()))