| 105 | } |
| 106 | |
| 107 | std::filesystem::path resolvePath( |
| 108 | const std::vector<std::filesystem::path>& searchPaths, |
| 109 | const std::filesystem::path& currentWorkingDirectory, |
| 110 | const std::string& filePath, |
| 111 | FileChecker fileChecker |
| 112 | ) |
| 113 | { |
| 114 | FALCOR_ASSERT(currentWorkingDirectory.is_absolute()); |
| 115 | |
| 116 | if (filePath.empty()) |
| 117 | return std::filesystem::path(); |
| 118 | |
| 119 | std::filesystem::path path(filePath); |
| 120 | if (path.is_absolute()) |
| 121 | { |
| 122 | if (fileChecker(path)) |
| 123 | return std::filesystem::weakly_canonical(path); |
| 124 | return std::filesystem::path(); |
| 125 | } |
| 126 | |
| 127 | // This is the relative case |
| 128 | if (filePath[0] == '.') |
| 129 | { |
| 130 | std::filesystem::path result = currentWorkingDirectory / path; |
| 131 | if (fileChecker(result)) |
| 132 | return std::filesystem::weakly_canonical(result); |
| 133 | return std::filesystem::path(); |
| 134 | } |
| 135 | |
| 136 | // This is the searchpath case |
| 137 | for (const auto& searchpath : searchPaths) |
| 138 | { |
| 139 | std::filesystem::path result = searchpath / path; |
| 140 | if (fileChecker(result)) |
| 141 | return std::filesystem::weakly_canonical(result); |
| 142 | } |
| 143 | return std::filesystem::path(); |
| 144 | } |
| 145 | |
| 146 | } // namespace Falcor |