Skip to content

Commit e80cf53

Browse files
committed
Vicar: embed vicar.json if EMBED_RESOURCE_FILES
1 parent a9469df commit e80cf53

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

frmts/pds/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ add_gdal_driver(
1414
NO_SHARED_SYMBOL_WITH_CORE
1515
)
1616

17-
set(GDAL_DATA_FILES
18-
${CMAKE_CURRENT_SOURCE_DIR}/data/vicar.json
19-
)
17+
2018
if (NOT USE_ONLY_EMBEDDED_RESOURCE_FILES)
21-
list(APPEND GDAL_DATA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/pds4_template.xml)
19+
set(GDAL_DATA_FILES
20+
${CMAKE_CURRENT_SOURCE_DIR}/data/vicar.json
21+
${CMAKE_CURRENT_SOURCE_DIR}/data/pds4_template.xml
22+
)
2223
endif()
2324

2425
set_property(

frmts/pds/embedded_resources.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ const char *PDS4GetEmbeddedTemplate()
1111
{
1212
return szPDS4Template;
1313
}
14+
15+
static const char szVICARJson[] = {
16+
#embed "data/vicar.json"
17+
, 0};
18+
19+
const char *VICARGetEmbeddedConf(void)
20+
{
21+
return szVICARJson;
22+
}

frmts/pds/embedded_resources.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
CPL_C_START
77

88
const char *PDS4GetEmbeddedTemplate(void);
9+
const char *VICARGetEmbeddedConf(void);
910

1011
CPL_C_END

frmts/pds/vicardataset.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ constexpr double VICAR_NULL3 = -32768.0;
4040
#include <limits>
4141
#include <string>
4242

43+
#ifdef EMBED_RESOURCE_FILES
44+
#include "embedded_resources.h"
45+
#endif
46+
4347
#if defined(HAVE_TIFF) && defined(HAVE_GEOTIFF)
4448
/* GeoTIFF 1.0 geokeys */
4549

@@ -2645,7 +2649,20 @@ GDALDataset *VICARDataset::Open(GDALOpenInfo *poOpenInfo)
26452649
if (nNBB != 0)
26462650
{
26472651
const char *pszBLType = poDS->GetKeyword("BLTYPE", nullptr);
2652+
#ifdef USE_ONLY_EMBEDDED_RESOURCE_FILES
2653+
const char *pszVicarConf = nullptr;
2654+
#else
26482655
const char *pszVicarConf = CPLFindFile("gdal", "vicar.json");
2656+
#endif
2657+
CPLJSONDocument oDoc;
2658+
if (!pszVicarConf || EQUAL(pszVicarConf, "vicar.json"))
2659+
{
2660+
#ifdef EMBED_RESOURCE_FILES
2661+
oDoc.LoadMemory(VICARGetEmbeddedConf());
2662+
pszVicarConf = "__embedded__";
2663+
#endif
2664+
}
2665+
26492666
if (pszBLType && pszVicarConf && poDS->m_nRecordSize > 0)
26502667
{
26512668

@@ -2687,8 +2704,7 @@ GDALDataset *VICARDataset::Open(GDALOpenInfo *poOpenInfo)
26872704
"BREALFMT=%s layout not supported.", value);
26882705
}
26892706

2690-
CPLJSONDocument oDoc;
2691-
if (oDoc.Load(pszVicarConf))
2707+
if (EQUAL(pszVicarConf, "__embedded__") || oDoc.Load(pszVicarConf))
26922708
{
26932709
const auto oRoot = oDoc.GetRoot();
26942710
if (oRoot.GetType() == CPLJSONObject::Type::Object)

0 commit comments

Comments
 (0)