From 316ca96fc9e6317247ef30e2926b47ec5544eb98 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2020 21:52:32 +0100 Subject: network: handle opening remote grids whose local name has no extension --- src/open_lib.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/open_lib.cpp') diff --git a/src/open_lib.cpp b/src/open_lib.cpp index 23ee79a0..222dd757 100644 --- a/src/open_lib.cpp +++ b/src/open_lib.cpp @@ -381,6 +381,23 @@ std::unique_ptr NS_PROJ::FileManager::open_resource_file( "Using %s", remote_file.c_str() ); pj_ctx_set_errno( ctx, 0 ); } + } else { + // For example for resource files like 'alaska' + auto remote_file_tif = remote_file + ".tif"; + file = open(ctx, remote_file_tif.c_str()); + if( file ) { + pj_log( ctx, PJ_LOG_DEBUG_MAJOR, + "Using %s", remote_file_tif.c_str() ); + pj_ctx_set_errno( ctx, 0 ); + } else { + // Init files + file = open(ctx, remote_file.c_str()); + if( file ) { + pj_log( ctx, PJ_LOG_DEBUG_MAJOR, + "Using %s", remote_file.c_str() ); + pj_ctx_set_errno( ctx, 0 ); + } + } } } } -- cgit v1.2.3 From 9263e1d36eec53ee3c4e4d04da93a032c0596eec Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 8 Jan 2020 22:32:54 +0100 Subject: Add capability to read resource files from the user writable directory --- src/open_lib.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/open_lib.cpp') diff --git a/src/open_lib.cpp b/src/open_lib.cpp index 222dd757..ae387281 100644 --- a/src/open_lib.cpp +++ b/src/open_lib.cpp @@ -224,6 +224,16 @@ static bool is_rel_or_absolute_filename(const char *name) || (name[0] != '\0' && name[1] == ':' && strchr(dir_chars,name[2])); } +static bool ignoreUserWritableDirectory() +{ + // Env var mostly for testing purposes and being independent from + // an existing installation + const char* envVarIgnoreUserWritableDirectory = + getenv("PROJ_IGNORE_USER_WRITABLE_DIRECTORY"); + return envVarIgnoreUserWritableDirectory != nullptr && + envVarIgnoreUserWritableDirectory[0] != '\0'; +} + static void* pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, void* (*open_file)(projCtx, const char*, const char*), @@ -279,6 +289,17 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, break; } } + + else if( !ignoreUserWritableDirectory() && + (fid = open_file(ctx, + (pj_context_get_user_writable_directory(ctx, false) + + DIR_CHAR + name).c_str(), mode)) != nullptr ) { + fname = pj_context_get_user_writable_directory(ctx, false); + fname += DIR_CHAR; + fname += name; + sysname = fname.c_str(); + } + /* if is environment PROJ_LIB defined */ else if ((sysname = getenv("PROJ_LIB")) != nullptr) { auto paths = NS_PROJ::internal::split(std::string(sysname), dirSeparator); -- cgit v1.2.3