The \a base path argument can be either a relative or absolute path. If the path is relative, then it is joined with search paths one after another until a matching file is located or all search paths are exhausted. If the \a base is absolute, only that path is tested and if invalid false is returned. \param base A path to the file that is to be found. \param targetType Currently ignored. In the
| 64 | //! are a valid path. |
| 65 | //! \retval false No match could be made. \a result has been left unmodified. |
| 66 | bool PathSearcher::search(const std::string &base, target_type_t targetType, bool searchCwd, std::string &result) |
| 67 | { |
| 68 | (void)targetType; |
| 69 | FILE *tempFile; |
| 70 | bool absolute = isAbsolute(base); |
| 71 | |
| 72 | // Try cwd first if requested. Same process applies to absolute paths. |
| 73 | if (absolute || searchCwd) |
| 74 | { |
| 75 | tempFile = fopen(base.c_str(), "r"); |
| 76 | if (tempFile) |
| 77 | { |
| 78 | fclose(tempFile); |
| 79 | result = base; |
| 80 | return true; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // If the base path is absolute and the previous test failed, then we don't go any further. |
| 85 | if (absolute) |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // Set temporary path to list of paths if path is not empty string. |
| 91 | if (m_tempPath != "") |
| 92 | { |
| 93 | m_paths.push_front(m_tempPath); |
| 94 | } |
| 95 | |
| 96 | bool foundFile = false; |
| 97 | // Iterate over all search paths. |
| 98 | string_list_t::const_iterator it = m_paths.begin(); |
| 99 | for (; it != m_paths.end(); ++it) |
| 100 | { |
| 101 | std::string searchPath = joinPaths(*it, base); |
| 102 | |
| 103 | tempFile = fopen(searchPath.c_str(), "r"); |
| 104 | if (tempFile) |
| 105 | { |
| 106 | fclose(tempFile); |
| 107 | result = searchPath; |
| 108 | foundFile = true; |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // Remove temporary path from list of paths if path is not empty. |
| 114 | if (m_tempPath != "") |
| 115 | { |
| 116 | m_paths.pop_front(); |
| 117 | } |
| 118 | |
| 119 | return foundFile; |
| 120 | } |
| 121 | |
| 122 | bool PathSearcher::isAbsolute(const std::string &path) |
| 123 | { |