47 lines
1 KiB
C++
47 lines
1 KiB
C++
|
#include <iostream>
|
||
|
|
||
|
#include <dirent.h>
|
||
|
|
||
|
#include <paths.hpp>
|
||
|
|
||
|
#include <modellist.hpp>
|
||
|
|
||
|
// get models from a given directory and add them to a given vector
|
||
|
void getModelsFromDir(std::string path, std::vector<std::string>* vector) {
|
||
|
DIR* dir;
|
||
|
struct dirent* ent;
|
||
|
|
||
|
if ((dir = opendir(path.c_str())) != NULL) {
|
||
|
while ((ent = readdir(dir)) != NULL) {
|
||
|
std::string filename = ent->d_name;
|
||
|
size_t fmaPos = filename.find(".fma"); // position of ".fma" in filename
|
||
|
|
||
|
if (fmaPos == std::string::npos) {
|
||
|
// filename does not have ".fma" in it
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
filename.erase(fmaPos);
|
||
|
|
||
|
vector->push_back(filename);
|
||
|
}
|
||
|
closedir(dir);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
std::vector<std::string> listModels() {
|
||
|
std::vector<std::string> modelList;
|
||
|
|
||
|
getModelsFromDir(prefixCustom + "models", &modelList);
|
||
|
getModelsFromDir(prefixDefault + "models", &modelList);
|
||
|
getModelsFromDir("models", &modelList);
|
||
|
|
||
|
/*
|
||
|
for (int i = 0; i < modelList.size(); i++) {
|
||
|
std::cout << "Detected model: " << modelList.at(i) << std::endl;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
return modelList;
|
||
|
}
|