summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/DataSource.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-10 22:27:26 +0200
committerAki <please@ignore.pl>2022-04-10 22:53:38 +0200
commit94ca59386cb94877ea15856a3c17c116c756a16d (patch)
tree30ece23c33d93624287a4c43fbc433942e245080 /StarsEx/DataSource.cpp
parenta9401f2b085bbb576021ed844e941beb9bf14c0f (diff)
downloadstarshatter-94ca59386cb94877ea15856a3c17c116c756a16d.zip
starshatter-94ca59386cb94877ea15856a3c17c116c756a16d.tar.gz
starshatter-94ca59386cb94877ea15856a3c17c116c756a16d.tar.bz2
Switched to use FileSystemDataSource in DataLoader
Diffstat (limited to 'StarsEx/DataSource.cpp')
-rw-r--r--StarsEx/DataSource.cpp29
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();
}