Resolve a model's texture reference (e.g. "data\foo.pac") to a file on disk: try the reference relative to each root, then a recursive match on its basename. ` ` / `#default#` placeholders resolve to nothing.
| 32 | // try the reference relative to each root, then a recursive match on its basename. |
| 33 | // `<default>` / `#default#` placeholders resolve to nothing. |
| 34 | static std::filesystem::path resolveTexture(const std::string& texName, const std::filesystem::path& texRoot, |
| 35 | const std::filesystem::path& modelDir) |
| 36 | { |
| 37 | namespace fs = std::filesystem; |
| 38 | if (texName.empty() || texName.front() == '<' || texName.front() == '#') |
| 39 | return {}; |
| 40 | |
| 41 | std::string norm = texName; |
| 42 | std::replace(norm.begin(), norm.end(), '\\', '/'); |
| 43 | fs::path rel(norm); |
| 44 | fs::path base = rel.filename(); |
| 45 | |
| 46 | std::vector<fs::path> roots; |
| 47 | if (!texRoot.empty()) |
| 48 | roots.push_back(texRoot); |
| 49 | if (!modelDir.empty()) |
| 50 | roots.push_back(modelDir); |
| 51 | |
| 52 | for (const auto& root : roots) |
| 53 | { |
| 54 | std::error_code ec; |
| 55 | fs::path direct = root / rel; |
| 56 | if (fs::exists(direct, ec)) |
| 57 | return direct; |
| 58 | for (fs::recursive_directory_iterator it(root, fs::directory_options::skip_permission_denied, ec), end; |
| 59 | it != end; it.increment(ec)) |
| 60 | { |
| 61 | if (ec) |
| 62 | break; |
| 63 | if (it->is_regular_file(ec) && it->path().filename() == base) |
| 64 | return it->path(); |
| 65 | } |
| 66 | } |
| 67 | if (fs::exists(norm)) |
| 68 | return fs::path(norm); |
| 69 | return {}; |
| 70 | } |
| 71 | |
| 72 | static void setupModelInspect(CLI::App& model) |
| 73 | { |
no test coverage detected