| 474 | /// It searches through default installation directories and appends "bin" to the path, where the proj lib is located |
| 475 | #ifdef _WIN32 |
| 476 | static std::string findLatestOSGeo4WInstallationPath(std::set<std::filesystem::path>& searchedPaths) { |
| 477 | // 1. If the environment variable is not set, check default OSGeo4W paths |
| 478 | size_t numPaths = 0; |
| 479 | const char** defaultPaths = getDefaultProgramPaths(numPaths); |
| 480 | |
| 481 | // Checking the standard paths (e.g. "C:\OSGeo4W\bin" or "C:\Program Files\OSGeo4W\bin\") |
| 482 | for (size_t i = 0; i < numPaths; ++i) { |
| 483 | const char* pathCStr = defaultPaths[i]; |
| 484 | if (!pathCStr) continue; |
| 485 | |
| 486 | searchedPaths.insert(std::filesystem::path(pathCStr)); |
| 487 | |
| 488 | for (const auto& programEntry : std::filesystem::directory_iterator(pathCStr)) { |
| 489 | try { |
| 490 | if (std::filesystem::is_directory(programEntry.path())) { |
| 491 | std::string directoryName = programEntry.path().filename().string(); |
| 492 | // Check whether the name is OSGeo4W64 or OSGeo4W |
| 493 | if (directoryName.find("OSGeo4W64") == 0 || directoryName.find("OSGeo4W") == 0) { |
| 494 | searchedPaths.insert(std::filesystem::path(programEntry.path())); |
| 495 | std::filesystem::path path(programEntry.path()); |
| 496 | path /= "bin"; // Append "bin" to the path |
| 497 | if (std::filesystem::exists(path)) { |
| 498 | searchedPaths.insert(path); |
| 499 | LASMessage(LAS_VERY_VERBOSE, "PROJ library used via OSGeo4W installation path: %s", path.string().c_str()); |
| 500 | return path.string(); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | } catch (const std::filesystem::filesystem_error&) { |
| 505 | continue; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | return ""; |
| 510 | } |
| 511 | #endif |
| 512 | |
| 513 | /// Finds the latest PROJ installation path in Conda environments |
no test coverage detected