diff --git a/shell/shared/fileLoader/win/FileLoaderWin.cpp b/shell/shared/fileLoader/win/FileLoaderWin.cpp index 016870c688..65c4f24c4d 100644 --- a/shell/shared/fileLoader/win/FileLoaderWin.cpp +++ b/shell/shared/fileLoader/win/FileLoaderWin.cpp @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -17,6 +18,33 @@ #include #endif +namespace { + +std::string findSubdir(const char* subdir, const std::string& fileName) { + std::filesystem::path dir = std::filesystem::current_path(); + // find `subdir` somewhere above our current directory + while (dir != std::filesystem::current_path().root_path() && + !std::filesystem::exists(dir / subdir)) { + dir = dir.parent_path(); + } + + std::filesystem::path fullPath = (dir / subdir / fileName); + if (std::filesystem::exists(fullPath)) { + return fullPath.string(); + } + + dir = std::filesystem::current_path(); + + fullPath = (dir / "images/" / fileName); + if (std::filesystem::exists(fullPath)) { + return fullPath.string(); + } + + return std::string(); +} + +} // namespace + namespace igl::shell { FileLoaderWin::FileLoaderWin() { @@ -59,24 +87,16 @@ std::string FileLoaderWin::fullPath(const std::string& fileName) const { return fullPath.string(); } - std::filesystem::path dir = std::filesystem::current_path(); - // find `shell/resources/images/` somewhere above our current directory - std::filesystem::path subdir("shell/resources/images/"); - while (dir != std::filesystem::current_path().root_path() && - !std::filesystem::exists(dir / subdir)) { - dir = dir.parent_path(); - } - - fullPath = (dir / subdir / fileName); - if (std::filesystem::exists(fullPath)) { - return fullPath.string(); - } + constexpr std::array folders = {"shell/resources/images/", + "samples/resources/images/", + "samples/resources/models/", + "samples/resources/fonts/"}; - dir = std::filesystem::current_path(); - subdir = "images/"; - fullPath = (dir / subdir / fileName); - if (std::filesystem::exists(fullPath)) { - return fullPath.string(); + // find folders somewhere above our current directory + for (const char* folder : folders) { + if (std::string p = findSubdir(folder, fileName); !p.empty()) { + return p; + } } IGL_ASSERT_NOT_REACHED();