| 90 | } |
| 91 | |
| 92 | std::string resolveResourcePath(const std::string &relativePath) { |
| 93 | if (relativePath.empty()) { |
| 94 | return relativePath; |
| 95 | } |
| 96 | |
| 97 | const std::string normalizedRelative = normalizePath(relativePath); |
| 98 | std::vector<std::string> roots; |
| 99 | |
| 100 | const char *envRoot = std::getenv("ENGINE_RESOURCE_ROOT"); |
| 101 | if (envRoot && envRoot[0] != '\0') { |
| 102 | roots.push_back(envRoot); |
| 103 | } |
| 104 | |
| 105 | char *basePath = SDL_GetBasePath(); |
| 106 | if (basePath) { |
| 107 | roots.push_back(std::string(basePath) + "resources"); |
| 108 | roots.push_back(basePath); |
| 109 | SDL_free(basePath); |
| 110 | } |
| 111 | |
| 112 | roots.push_back("resources"); |
| 113 | roots.push_back("."); |
| 114 | |
| 115 | for (const std::string &root : roots) { |
| 116 | const std::string candidate = buildCandidate(root, normalizedRelative); |
| 117 | if (fileExists(candidate)) { |
| 118 | return candidate; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return normalizedRelative; |
| 123 | } |
| 124 | |
| 125 | std::string resolveResourcePath(const char *relativePath) { |
| 126 | return resolveResourcePath(std::string(relativePath ? relativePath : "")); |
no test coverage detected