diff options
Diffstat (limited to 'StarsEx/DataSource.cpp')
-rw-r--r-- | StarsEx/DataSource.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/StarsEx/DataSource.cpp b/StarsEx/DataSource.cpp index b587971..f352e05 100644 --- a/StarsEx/DataSource.cpp +++ b/StarsEx/DataSource.cpp @@ -13,6 +13,7 @@ #include "Archive.h" #include "List.h" #include "Text.h" +#include "Utils.h" DataSource::DataSource() : @@ -120,19 +121,27 @@ FileSystemDataSource::ListFiles(Text filter, List<Text>& items, bool recurse) co std::filesystem::path full_path {m_path}; full_path.append(m_prefix.data()); filter = filter.replace("*", ""); - const auto check = [&items, &filter](const std::filesystem::directory_entry& entry){ - const auto filename = entry.path().filename().string(); + const auto prefix = full_path.string().length(); + const auto check = [&](const std::filesystem::directory_entry& entry){ + const auto filename = entry.path().filename().string(); // more of a reason to switch to string soon const auto index = filename.find(filter.data()); - if (index != decltype(filename)::npos) - items.append(new Text(entry.path().string().c_str())); + if (index != decltype(filename)::npos) { + Text path = entry.path().string().c_str(); + items.append(new Text(path.substring(prefix, path.length()))); + } }; - if (recurse) { - for (const auto& entry : std::filesystem::recursive_directory_iterator(full_path)) - check(entry); + try { + if (recurse) { + for (const auto& entry : std::filesystem::recursive_directory_iterator(full_path)) + check(entry); + } + else { + for (const auto& entry : std::filesystem::directory_iterator(full_path)) + check(entry); + } } - else { - for (const auto& entry : std::filesystem::directory_iterator(full_path)) - check(entry); + catch (const std::filesystem::filesystem_error& err) { + Print("FS::ListFiles: %s\n", err.what()); } return items.size(); } |