MCPcopy Create free account
hub / github.com/Kitware/VTK / open_resource_file

Method open_resource_file

ThirdParty/libproj/vtklibproj/src/filemanager.cpp:1640–1727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1638/************************************************************************/
1639
1640std::unique_ptr<NS_PROJ::File>
1641NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name) {
1642
1643 if (ctx == nullptr) {
1644 ctx = pj_get_default_ctx();
1645 }
1646
1647 auto file = std::unique_ptr<NS_PROJ::File>(
1648 reinterpret_cast<NS_PROJ::File *>(pj_open_lib_internal(
1649 ctx, name, "rb", pj_open_file_with_manager, nullptr, 0)));
1650
1651 // Retry with the new proj grid name if the file name doesn't end with .tif
1652 std::string tmpString; // keep it in this upper scope !
1653 if (file == nullptr && !is_tilde_slash(name) &&
1654 !is_rel_or_absolute_filename(name) && !starts_with(name, "http://") &&
1655 !starts_with(name, "https://") && strcmp(name, "proj.db") != 0 &&
1656 strstr(name, ".tif") == nullptr) {
1657
1658 auto dbContext = getDBcontext(ctx);
1659 if (dbContext) {
1660 try {
1661 auto filename = dbContext->getProjGridName(name);
1662 if (!filename.empty()) {
1663 file.reset(reinterpret_cast<NS_PROJ::File *>(
1664 pj_open_lib_internal(ctx, filename.c_str(), "rb",
1665 pj_open_file_with_manager, nullptr,
1666 0)));
1667 if (file) {
1668 proj_context_errno_set(ctx, 0);
1669 } else {
1670 // For final network access attempt, use the new
1671 // name.
1672 tmpString = filename;
1673 name = tmpString.c_str();
1674 }
1675 }
1676 } catch (const std::exception &e) {
1677 pj_log(ctx, PJ_LOG_DEBUG, "%s", e.what());
1678 return nullptr;
1679 }
1680 }
1681 }
1682 // Retry with the old proj grid name if the file name ends with .tif
1683 else if (file == nullptr && !is_tilde_slash(name) &&
1684 !is_rel_or_absolute_filename(name) &&
1685 !starts_with(name, "http://") && !starts_with(name, "https://") &&
1686 strstr(name, ".tif") != nullptr) {
1687
1688 auto dbContext = getDBcontext(ctx);
1689 if (dbContext) {
1690 try {
1691 auto filename = dbContext->getOldProjGridName(name);
1692 if (!filename.empty()) {
1693 file.reset(reinterpret_cast<NS_PROJ::File *>(
1694 pj_open_lib_internal(ctx, filename.c_str(), "rb",
1695 pj_open_file_with_manager, nullptr,
1696 0)));
1697 if (file) {

Callers

nothing calls this directly

Calls 15

pj_get_default_ctxFunction · 0.85
pj_open_lib_internalFunction · 0.85
getDBcontextFunction · 0.85
proj_context_errno_setFunction · 0.85
pj_logFunction · 0.85
getProjGridNameMethod · 0.80
getOldProjGridNameMethod · 0.80
backMethod · 0.80
is_tilde_slashFunction · 0.70

Tested by

no test coverage detected