diff --git a/shell/shared/fileLoader/win/FileLoaderWin.cpp b/shell/shared/fileLoader/win/FileLoaderWin.cpp index 139caac70c..81ffbdcd9d 100644 --- a/shell/shared/fileLoader/win/FileLoaderWin.cpp +++ b/shell/shared/fileLoader/win/FileLoaderWin.cpp @@ -49,13 +49,38 @@ std::string FileLoaderWin::fullPath(const std::string& fileName) const { return fileName; } - auto absolutePath = std::filesystem::path(basePath_) / fileName; - if (std::filesystem::exists(absolutePath)) { - return absolutePath.string(); + auto fullPath = std::filesystem::path(basePath_) / fileName; + if (std::filesystem::exists(fullPath)) { + return fullPath.string(); } - // passthrough, since there are no bundles on Windows - return fileName; + fullPath = std::filesystem::path("shell/resources/images") / fileName; + if (std::filesystem::exists(fullPath)) { + 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(); + } + + dir = std::filesystem::current_path(); + subdir = "images/"; + fullPath = (dir / subdir / fileName); + if (std::filesystem::exists(fullPath)) { + return fullPath.string(); + } + + IGL_ASSERT_NOT_REACHED(); + return ""; } } // namespace igl::shell diff --git a/shell/shared/imageLoader/win/ImageLoaderWin.cpp b/shell/shared/imageLoader/win/ImageLoaderWin.cpp index 17993eecac..b67769ba6c 100644 --- a/shell/shared/imageLoader/win/ImageLoaderWin.cpp +++ b/shell/shared/imageLoader/win/ImageLoaderWin.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -29,33 +30,7 @@ ImageLoaderWin::ImageLoaderWin(FileLoader& fileLoader) : ImageLoader(fileLoader) } ImageData ImageLoaderWin::loadImageData(std::string imageName) noexcept { - std::string fullName = imageName; - - if (!std::filesystem::exists(fullName)) { - fullName = "shell/resources/images/" + imageName; - } - - if (!std::filesystem::exists(fullName)) { - using namespace std::filesystem; - path dir = current_path(); - // find `shell/resources/images/` somewhere above our current directory - const path subdir("shell/resources/images/"); - while (dir != current_path().root_path() && !exists(dir / subdir)) { - dir = dir.parent_path(); - } - fullName = (dir / subdir / imageName).string(); - } - - if (!std::filesystem::exists(fullName)) { - using namespace std::filesystem; - path dir = current_path(); - const path subdir("images/"); - fullName = (dir / subdir / imageName).string(); - } - - if (!std::filesystem::exists(fullName)) { - fullName = (std::filesystem::path(executablePath_) / imageName).string(); - } + std::string fullName = fileLoader().fullPath(imageName); // Load image from file in RGBA format auto ret = ImageData();