switched from linux-dir-api to c++17 dir-api

This commit is contained in:
k-a-z-u
2018-03-27 12:39:48 +02:00
parent f3b6155157
commit 705763f03c
2 changed files with 18 additions and 10 deletions

View File

@@ -9,8 +9,9 @@
#include "Obstacle3.h" #include "Obstacle3.h"
// LINUX ONLY // LINUX ONLY
#include <dirent.h> //#include <dirent.h>
#include <stdio.h> //#include <stdio.h>
#include <experimental/filesystem>
namespace Ray3D { namespace Ray3D {
@@ -42,19 +43,26 @@ namespace Ray3D {
initDone = true; initDone = true;
// LINUX ONLY! // LINUX ONLY!
DIR* d = opendir(folder.c_str()); //DIR* d = opendir(folder.c_str());
if (!d) {throw Exception("OBJPool: folder not found: " + folder);} //if (!d) {throw Exception("OBJPool: folder not found: " + folder);}
std::experimental::filesystem::path d(folder);
if (!std::experimental::filesystem::exists(d)) {
throw Exception("OBJPool: folder not found: " + folder);
}
struct dirent *dir; //struct dirent *dir;
while ((dir = readdir(d)) != NULL) { //while ((dir = readdir(d)) != NULL) {
const std::string absFile = folder + "/" + dir->d_name; for (std::experimental::filesystem::directory_entry entry : std::experimental::filesystem::directory_iterator(d)) {
//const std::string absFile = folder + "/" + dir->d_name;
const std::string absFile = entry.path().native();
if (endsWith(absFile, ".obj")) { if (endsWith(absFile, ".obj")) {
std::string name = std::string(dir->d_name); //std::string name = std::string(dir->d_name);
std::string name = entry.path().filename();
name = name.substr(0, name.length() - 4); // without extension name = name.substr(0, name.length() - 4); // without extension
load(absFile, name); load(absFile, name);
} }
} }
closedir(d); //closedir(d);
} }

View File

@@ -160,7 +160,7 @@ private:
} }
// sanity check // sanity check
if (numVertices != 3) {throw "this face is not a triangle!";} // if (numVertices != 3) {throw "this face is not a triangle!";}
} }