diff options
Diffstat (limited to 'src/filemanager.cpp')
| -rw-r--r-- | src/filemanager.cpp | 145 |
1 files changed, 10 insertions, 135 deletions
diff --git a/src/filemanager.cpp b/src/filemanager.cpp index e6a9ed95..b3b074a2 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -786,75 +786,6 @@ std::unique_ptr<File> FileStdio::open(PJ_CONTEXT *ctx, const char *filename, // --------------------------------------------------------------------------- -#ifndef REMOVE_LEGACY_SUPPORT - -class FileLegacyAdapter : public File { - PJ_CONTEXT *m_ctx; - PAFile m_fp; - - FileLegacyAdapter(const FileLegacyAdapter &) = delete; - FileLegacyAdapter &operator=(const FileLegacyAdapter &) = delete; - - protected: - FileLegacyAdapter(const std::string &filename, PJ_CONTEXT *ctx, PAFile fp) - : File(filename), m_ctx(ctx), m_fp(fp) {} - - public: - ~FileLegacyAdapter() override; - - size_t read(void *buffer, size_t sizeBytes) override; - size_t write(const void *, size_t) override { return 0; } - bool seek(unsigned long long offset, int whence = SEEK_SET) override; - unsigned long long tell() override; - void reassign_context(PJ_CONTEXT *ctx) override { m_ctx = ctx; } - - // We may lie, but the real use case is only for network files - bool hasChanged() const override { return false; } - - static std::unique_ptr<File> open(PJ_CONTEXT *ctx, const char *filename, - FileAccess access); -}; - -// --------------------------------------------------------------------------- - -FileLegacyAdapter::~FileLegacyAdapter() { pj_ctx_fclose(m_ctx, m_fp); } - -// --------------------------------------------------------------------------- - -size_t FileLegacyAdapter::read(void *buffer, size_t sizeBytes) { - return pj_ctx_fread(m_ctx, buffer, 1, sizeBytes, m_fp); -} - -// --------------------------------------------------------------------------- - -bool FileLegacyAdapter::seek(unsigned long long offset, int whence) { - if (offset != static_cast<unsigned long long>(static_cast<long>(offset))) { - pj_log(m_ctx, PJ_LOG_ERROR, - "Attempt at seeking to a 64 bit offset. Not supported yet"); - return false; - } - return pj_ctx_fseek(m_ctx, m_fp, static_cast<long>(offset), whence) == 0; -} - -// --------------------------------------------------------------------------- - -unsigned long long FileLegacyAdapter::tell() { - return pj_ctx_ftell(m_ctx, m_fp); -} - -// --------------------------------------------------------------------------- - -std::unique_ptr<File> -FileLegacyAdapter::open(PJ_CONTEXT *ctx, const char *filename, FileAccess) { - auto fid = pj_ctx_fopen(ctx, filename, "rb"); - return std::unique_ptr<File>(fid ? new FileLegacyAdapter(filename, ctx, fid) - : nullptr); -} - -#endif // REMOVE_LEGACY_SUPPORT - -// --------------------------------------------------------------------------- - class FileApiAdapter : public File { PJ_CONTEXT *m_ctx; PROJ_FILE_HANDLE *m_fp; @@ -954,12 +885,6 @@ std::unique_ptr<File> FileManager::open(PJ_CONTEXT *ctx, const char *filename, } return pj_network_file_open(ctx, filename); } -#ifndef REMOVE_LEGACY_SUPPORT - // If the user has specified a legacy fileapi, use it - if (ctx->fileapi_legacy != pj_get_default_fileapi()) { - return FileLegacyAdapter::open(ctx, filename, access); - } -#endif if (ctx->fileApi.open_cbk != nullptr) { return FileApiAdapter::open(ctx, filename, access); } @@ -1445,8 +1370,8 @@ static bool dontReadUserWritableDirectory() { } static void * -pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, - void *(*open_file)(projCtx, const char *, const char *), +pj_open_lib_internal(PJ_CONTEXT *ctx, const char *name, const char *mode, + void *(*open_file)(PJ_CONTEXT *, const char *, const char *), char *out_full_filename, size_t out_full_filename_size) { try { std::string fname; @@ -1493,10 +1418,6 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, ctx, name, ctx->file_finder_user_data)) != nullptr) ; - else if (ctx->file_finder_legacy != nullptr && - (sysname = ctx->file_finder_legacy(name)) != nullptr) - ; - /* The user has search paths set */ else if (!ctx->search_paths.empty()) { for (const auto &path : ctx->search_paths) { @@ -1566,7 +1487,7 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode, } if (ctx->last_errno == 0 && errno != 0) - pj_ctx_set_errno(ctx, errno); + proj_context_errno_set(ctx, errno); pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "pj_open_lib(%s): call fopen(%s) - %s", name, sysname, fid == nullptr ? "failed" : "succeeded"); @@ -1617,7 +1538,7 @@ std::vector<std::string> pj_get_default_searchpaths(PJ_CONTEXT *ctx) { /* pj_open_file_with_manager() */ /************************************************************************/ -static void *pj_open_file_with_manager(projCtx ctx, const char *name, +static void *pj_open_file_with_manager(PJ_CONTEXT *ctx, const char *name, const char * /* mode */) { return NS_PROJ::FileManager::open(ctx, name, NS_PROJ::FileAccess::READ_ONLY) .release(); @@ -1639,7 +1560,7 @@ static NS_PROJ::io::DatabaseContextPtr getDBcontext(PJ_CONTEXT *ctx) { /************************************************************************/ std::unique_ptr<NS_PROJ::File> -NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { +NS_PROJ::FileManager::open_resource_file(PJ_CONTEXT *ctx, const char *name) { if (ctx == nullptr) { ctx = pj_get_default_ctx(); @@ -1666,7 +1587,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { pj_open_file_with_manager, nullptr, 0))); if (file) { - pj_ctx_set_errno(ctx, 0); + proj_context_errno_set(ctx, 0); } else { // For final network access attempt, use the new // name. @@ -1696,7 +1617,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { pj_open_file_with_manager, nullptr, 0))); if (file) { - pj_ctx_set_errno(ctx, 0); + proj_context_errno_set(ctx, 0); } } } catch (const std::exception &e) { @@ -1721,7 +1642,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { if (file) { pj_log(ctx, PJ_LOG_DEBUG_MAJOR, "Using %s", remote_file.c_str()); - pj_ctx_set_errno(ctx, 0); + proj_context_errno_set(ctx, 0); } } } @@ -1729,26 +1650,6 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { } /************************************************************************/ -/* pj_open_lib() */ -/************************************************************************/ - -#ifndef REMOVE_LEGACY_SUPPORT - -// Used by following legacy function -static void *pj_ctx_fopen_adapter(projCtx ctx, const char *name, - const char *mode) { - return pj_ctx_fopen(ctx, name, mode); -} - -// Legacy function -PAFile pj_open_lib(projCtx ctx, const char *name, const char *mode) { - return (PAFile)pj_open_lib_internal(ctx, name, mode, pj_ctx_fopen_adapter, - nullptr, 0); -} - -#endif // REMOVE_LEGACY_SUPPORT - -/************************************************************************/ /* pj_find_file() */ /************************************************************************/ @@ -1764,7 +1665,7 @@ PAFile pj_open_lib(projCtx ctx, const char *name, const char *mode) { * @param out_full_filename_size size of out_full_filename. * @return 1 if the file was found, 0 otherwise. */ -int pj_find_file(projCtx ctx, const char *short_filename, +int pj_find_file(PJ_CONTEXT *ctx, const char *short_filename, char *out_full_filename, size_t out_full_filename_size) { auto file = std::unique_ptr<NS_PROJ::File>( reinterpret_cast<NS_PROJ::File *>(pj_open_lib_internal( @@ -1812,7 +1713,7 @@ static std::string trim(const std::string &s) { /* pj_load_ini() */ /************************************************************************/ -void pj_load_ini(projCtx ctx) { +void pj_load_ini(PJ_CONTEXT *ctx) { if (ctx->iniFileLoaded) return; @@ -1891,19 +1792,6 @@ void pj_load_ini(projCtx ctx) { //! @endcond /************************************************************************/ -/* pj_set_finder() */ -/************************************************************************/ - -void pj_set_finder(const char *(*new_finder)(const char *)) - -{ - auto ctx = pj_get_default_ctx(); - if (ctx) { - ctx->file_finder_legacy = new_finder; - } -} - -/************************************************************************/ /* proj_context_set_file_finder() */ /************************************************************************/ @@ -1974,19 +1862,6 @@ void proj_context_set_search_paths(PJ_CONTEXT *ctx, int count_paths, } /************************************************************************/ -/* pj_set_searchpath() */ -/* */ -/* Path control for callers that can't practically provide */ -/* pj_set_finder() style callbacks. Call with (0,NULL) as args */ -/* to clear the searchpath set. */ -/************************************************************************/ - -void pj_set_searchpath(int count, const char **path) { - proj_context_set_search_paths(nullptr, count, - const_cast<const char *const *>(path)); -} - -/************************************************************************/ /* proj_context_set_ca_bundle_path() */ /************************************************************************/ |
