| 1784 | /************************************************************************/ |
| 1785 | |
| 1786 | std::unique_ptr<NS_PROJ::File> |
| 1787 | NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name, |
| 1788 | char *out_full_filename, |
| 1789 | size_t out_full_filename_size) { |
| 1790 | |
| 1791 | if (ctx == nullptr) { |
| 1792 | ctx = pj_get_default_ctx(); |
| 1793 | } |
| 1794 | |
| 1795 | auto file = |
| 1796 | std::unique_ptr<NS_PROJ::File>(reinterpret_cast<NS_PROJ::File *>( |
| 1797 | pj_open_lib_internal(ctx, name, "rb", pj_open_file_with_manager, |
| 1798 | out_full_filename, out_full_filename_size))); |
| 1799 | |
| 1800 | // Retry with the new proj grid name if the file name doesn't end with .tif |
| 1801 | std::string tmpString; // keep it in this upper scope ! |
| 1802 | if (file == nullptr && !is_tilde_slash(name) && |
| 1803 | !is_rel_or_absolute_filename(name) && !starts_with(name, "http://") && |
| 1804 | !starts_with(name, "https://") && strcmp(name, "proj.db") != 0 && |
| 1805 | strstr(name, ".tif") == nullptr) { |
| 1806 | |
| 1807 | auto dbContext = getDBcontext(ctx); |
| 1808 | if (dbContext) { |
| 1809 | try { |
| 1810 | auto filename = dbContext->getProjGridName(name); |
| 1811 | if (!filename.empty()) { |
| 1812 | file.reset(reinterpret_cast<NS_PROJ::File *>( |
| 1813 | pj_open_lib_internal(ctx, filename.c_str(), "rb", |
| 1814 | pj_open_file_with_manager, |
| 1815 | out_full_filename, |
| 1816 | out_full_filename_size))); |
| 1817 | if (file) { |
| 1818 | proj_context_errno_set(ctx, 0); |
| 1819 | } else { |
| 1820 | // For final network access attempt, use the new |
| 1821 | // name. |
| 1822 | tmpString = std::move(filename); |
| 1823 | name = tmpString.c_str(); |
| 1824 | } |
| 1825 | } |
| 1826 | } catch (const std::exception &e) { |
| 1827 | pj_log(ctx, PJ_LOG_DEBUG, "%s", e.what()); |
| 1828 | return nullptr; |
| 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | // Retry with the old proj grid name if the file name ends with .tif |
| 1833 | else if (file == nullptr && !is_tilde_slash(name) && |
| 1834 | !is_rel_or_absolute_filename(name) && |
| 1835 | !starts_with(name, "http://") && !starts_with(name, "https://") && |
| 1836 | strstr(name, ".tif") != nullptr) { |
| 1837 | |
| 1838 | auto dbContext = getDBcontext(ctx); |
| 1839 | if (dbContext) { |
| 1840 | try { |
| 1841 | const auto filename = dbContext->getOldProjGridName(name); |
| 1842 | if (!filename.empty()) { |
| 1843 | file.reset(reinterpret_cast<NS_PROJ::File *>( |
nothing calls this directly
no test coverage detected