Search for the PROJ library within the standard installation directories.
| 235 | |
| 236 | /// Search for the PROJ library within the standard installation directories. |
| 237 | static std::string findProjLibInStandartPaths(std::set<std::filesystem::path>& searchedPaths) { |
| 238 | const char* homeDir = nullptr; |
| 239 | std::vector<std::filesystem::path> pathsToCheck; |
| 240 | std::string latestVersionPath; |
| 241 | std::string latestVersionName; |
| 242 | |
| 243 | #ifdef _WIN32 |
| 244 | // Windows-Standardpfade |
| 245 | pathsToCheck.push_back("C:\\Program Files\\"); |
| 246 | pathsToCheck.push_back("C:\\Program Files (x86)\\"); |
| 247 | |
| 248 | const char* userProfile = getenv("USERPROFILE"); |
| 249 | if (userProfile) { |
| 250 | pathsToCheck.push_back(std::filesystem::path(userProfile) / "AppData/Local/Programs"); |
| 251 | } |
| 252 | #else |
| 253 | // Linux/macOS-Standardpfade |
| 254 | const std::string systemLibPaths[] = { |
| 255 | "/usr/lib/x86_64-linux-gnu/", |
| 256 | "/usr/lib/", |
| 257 | "/usr/bin/", |
| 258 | "/usr/local/lib/", |
| 259 | "/usr/local/bin/", |
| 260 | "/opt/", |
| 261 | "/usr/share/", |
| 262 | "/lib/x86_64-linux-gnu/"}; |
| 263 | homeDir = getHomeDirectory(); |
| 264 | |
| 265 | for (const auto& p : systemLibPaths) pathsToCheck.push_back(p); |
| 266 | if (homeDir) pathsToCheck.push_back(std::filesystem::path(homeDir) / ".local/lib"); |
| 267 | #endif |
| 268 | |
| 269 | // 1. Check only top-level dirs |
| 270 | for (const auto& basePath : pathsToCheck) { |
| 271 | try { |
| 272 | if (std::filesystem::exists(basePath) && std::filesystem::is_directory(basePath)) { |
| 273 | searchedPaths.insert(basePath); |
| 274 | const std::string resultPath = findLatestProjLibraryPath(basePath.string()); |
| 275 | |
| 276 | if (!resultPath.empty()) { |
| 277 | std::filesystem::path projPath(resultPath); |
| 278 | std::string fileName = projPath.filename().string(); |
| 279 | |
| 280 | if (latestVersionName.empty() || compareVersions(fileName, latestVersionName)) { |
| 281 | latestVersionName = fileName; |
| 282 | latestVersionPath = projPath.string(); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } catch (const std::filesystem::filesystem_error&) { |
| 287 | continue; |
| 288 | } |
| 289 | } |
| 290 | if (!latestVersionPath.empty()) { |
| 291 | LASMessage(LAS_VERY_VERBOSE, "PROJ library found in path: %s", latestVersionPath.c_str()); |
| 292 | return latestVersionPath; |
| 293 | } |
| 294 | return ""; |
no test coverage detected