Skip to content

Commit

Permalink
Try to find data files if wrong case for non-Windows platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
IntelOrca committed Jan 24, 2018
1 parent 11bbf64 commit f0a6f99
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/openloco/envionment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ namespace openloco::environment
return _path_install.get();
}

#ifndef _WIN32
/**
* Performs a case-insensitive search on the containing directory of
* the given file and returns the first match.
*/
static fs::path find_similar_file(const fs::path &path)
{
auto expectedFilename = path.filename().generic_string();
auto directory = path.parent_path();
for (auto &item : fs::directory_iterator(directory))
{
auto &p = item.path();
if (utility::iequals(p.filename().generic_string(), expectedFilename))
{
return p;
}
}
return fs::path();
}
#endif // _WIN32

// 0x004416B5
fs::path get_path(path_id id)
{
Expand All @@ -110,8 +131,16 @@ namespace openloco::environment
auto result = basePath / subPath;
if (!fs::exists(result))
{
std::cerr << "File not found: " << result << std::endl;
}
#ifndef _WIN32
result = find_similar_file(result);
if (result.empty())
{
#endif
std::cerr << "File not found: " << result << std::endl;
#ifndef _WIN32
}
#endif
}
return result;
}

Expand Down

0 comments on commit f0a6f99

Please sign in to comment.