aboutsummaryrefslogtreecommitdiff
path: root/src/Storage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Storage.cpp')
-rw-r--r--src/Storage.cpp32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/Storage.cpp b/src/Storage.cpp
index dc6b6a2..7bb3be6 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -249,7 +249,7 @@ namespace QuickMedia {
for(auto &p : std::filesystem::directory_iterator(path.data)) {
std::error_code ec;
const FileType file_type = p.is_directory(ec) ? FileType::DIRECTORY : FileType::REGULAR;
- if(!callback(p.path().string(), file_type))
+ if(!callback(p.path().string(), file_type, 0))
break;
}
} catch(const std::filesystem::filesystem_error &err) {
@@ -258,19 +258,13 @@ namespace QuickMedia {
}
}
- static std::filesystem::file_time_type file_get_filetime_or(const std::filesystem::directory_entry &path, std::filesystem::file_time_type default_value) {
- try {
- return path.last_write_time();
- } catch(const std::filesystem::filesystem_error &err) {
- return default_value;
- }
- }
-
void for_files_in_dir_sort_last_modified(const Path &path, FileIteratorCallback callback, FileSortDirection sort_dir) {
- std::vector<std::filesystem::directory_entry> paths;
+ std::vector<std::pair<std::filesystem::directory_entry, time_t>> paths_with_last_modified;
try {
for(auto &p : std::filesystem::directory_iterator(path.data)) {
- paths.push_back(p);
+ time_t last_modified = 0;
+ file_get_last_modified_time_seconds(p.path().c_str(), &last_modified);
+ paths_with_last_modified.push_back(std::make_pair(p, last_modified));
}
} 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());
@@ -278,19 +272,19 @@ namespace QuickMedia {
}
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());
+ std::sort(paths_with_last_modified.begin(), paths_with_last_modified.end(), [](const auto &path1, const auto &path2) {
+ return path1.second > path2.second;
});
} 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());
+ std::sort(paths_with_last_modified.begin(), paths_with_last_modified.end(), [](const auto &path1, const auto &path2) {
+ return path1.second < path2.second;
});
}
- for(auto &p : paths) {
+ for(auto &p : paths_with_last_modified) {
std::error_code ec;
- const FileType file_type = p.is_directory(ec) ? FileType::DIRECTORY : FileType::REGULAR;
- if(!callback(p.path().string(), file_type))
+ const FileType file_type = p.first.is_directory(ec) ? FileType::DIRECTORY : FileType::REGULAR;
+ if(!callback(p.first.path().string(), file_type, p.second))
break;
}
}
@@ -319,7 +313,7 @@ namespace QuickMedia {
for(auto &p : paths) {
std::error_code ec;
const FileType file_type = p.is_directory(ec) ? FileType::DIRECTORY : FileType::REGULAR;
- if(!callback(p.path().string(), file_type))
+ if(!callback(p.path().string(), file_type, 0))
break;
}
}