diff --git a/data/File.h b/data/File.h new file mode 100644 index 0000000..0f6d48f --- /dev/null +++ b/data/File.h @@ -0,0 +1,115 @@ +#ifndef FS_FILE_H +#define FS_FILE_H + +#include +#include + + + + +#if __cplusplus > 201103L + + // use new cross-platform std::experimental stuff + #include + +namespace FS { + + class File { + + std::experimental::filesystem::path path; + + public: + + File(const std::string& fileOrFolder) : path(fileOrFolder) { + + } + + bool exists() const { + return std::experimental::filesystem::exists(path); + } + + std::vector listFiles() const { + std::vector res; + for (std::experimental::filesystem::directory_entry entry : std::experimental::filesystem::directory_iterator(path)) { + const std::string abs = entry.path().string(); + res.push_back(File(abs)); + } + return res; + } + + std::string getPath() const { + return path.string(); + } + + std::string getFilename() const { + return path.filename().string(); + } + + }; + +} + +#else + + // use linux-only fallback + + #include + #include + +namespace FS { + + class File { + + std::string path; + + public: + + File(const std::string& fileOrFolder) : path(fileOrFolder) { + + } + + bool exists() const { + struct stat st; + int res = stat(path.c_str(), &st ); + return res == 0; + } + + /** list of all files/folders within the current folder */ + std::vector listFiles() const { + + std::vector res; + + DIR* dir; + + dir = opendir(path.c_str()); + if (!dir) {throw Exception("failed to open folder " + path);} + + // fetch all entries + while(true) { + dirent* entry = readdir(dir); + if (!entry) {break;} + const std::string abs = path + "/" + entry->d_name; + res.push_back(File(abs)); + } + + return res; + + } + + const std::string& getPath() const { + return path; + } + + const std::string getFilename() const { + const size_t lastSlash = path.find_last_of("/"); + if (std::string::npos == lastSlash) {return path;} + std::string name = path.substr(lastSlash+1); + return name; + } + + }; + +} +#endif + +#endif // FS_FILE_H diff --git a/wifi/estimate/ray3/OBJPool.h b/wifi/estimate/ray3/OBJPool.h index a10c2d7..037dd5b 100644 --- a/wifi/estimate/ray3/OBJPool.h +++ b/wifi/estimate/ray3/OBJPool.h @@ -11,7 +11,8 @@ // LINUX ONLY //#include //#include -#include +#include "../../../data/File.h" + #include "../../../misc/Debug.h" @@ -83,17 +84,17 @@ namespace Ray3D { /** scan the given folder for all *.obj files */ void scanFolder(const std::string& folder) { - std::experimental::filesystem::path d(folder); - if (!std::experimental::filesystem::exists(d)) { + FS::File d(folder); + if (!d.exists()) { throw Exception("OBJPool: folder not found: " + folder); } - for (std::experimental::filesystem::directory_entry entry : std::experimental::filesystem::directory_iterator(d)) { - const std::string absFile = entry.path().string(); - if (endsWith(absFile, ".obj")) { - std::string name = entry.path().filename().string(); + for (const FS::File& f : d.listFiles()) { + std::string name = f.getFilename(); + if (endsWith(name, ".obj")) { + //std::string name = entry.path().filename().string(); name = name.substr(0, name.length() - 4); // without extension - load(absFile, name); + load(f.getPath(), name); } }