Skip to content

Commit

Permalink
Considered Windows case when searching the mesh path.
Browse files Browse the repository at this point in the history
  • Loading branch information
S-Dafarra committed Jan 8, 2021
1 parent b359c4b commit 30c39bc
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,44 @@

int main()
{
bool isWindows = false;
#ifdef _WIN32
isWindows = true;
#endif

const char * env_var_value = std::getenv("GAZEBO_MODEL_PATH");

std::stringstream env_var_string(env_var_value);

std::string individualPath;
std::vector<std::string> pathList;

while(std::getline(env_var_string, individualPath, ':'))
while(std::getline(env_var_string, individualPath, isWindows ? ';' : ':'))
{
pathList.push_back(individualPath);
}

auto isFileExisting = [](const std::string& filename)->bool
auto cleanPathSeparator = [isWindows](const std::string& filename)->std::string
{
std::string output = filename;
char pathSeparator = isWindows ? '\\' : '/';
char wrongPathSeparator = isWindows ? '/' : '\\';

for (size_t i = 0; i < output.size(); ++i)
{
if (output[i] == wrongPathSeparator)
{
output[i] = pathSeparator;
}
}

return filename;

};

auto isFileExisting = [cleanPathSeparator](const std::string& filename)->bool
{
if (FILE *file = fopen(filename.c_str(), "r")) {
if (FILE *file = fopen(cleanPathSeparator(filename).c_str(), "r")) {
fclose(file);
return true;
} else {
Expand Down

0 comments on commit 30c39bc

Please sign in to comment.