-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.cpp
38 lines (32 loc) · 847 Bytes
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "common.h"
std::string locateFile(const std::string& input, const std::vector<std::string> & directories)
{
std::string file;
const int MAX_DEPTH{10};
bool found{false};
for(auto &dir : directories)
{
file = dir + input;
for(int i = 0; i < MAX_DEPTH && !found; i++)
{
std::ifstream checkFile(file);
found = checkFile.is_open();
if(found) break;
file = "../" + file;
}
if(found) break;
file.clear();
}
assert(!file.empty() && "Could not find a file due to it not existing in the data directory.");
return file;
}
bool fileExists(const std::string fileName)
{
FILE* file = fopen(fileName.c_str(), "r");
if(file != nullptr)
{
fclose(file);
return true;
}
return false;
}