Skip to content

Commit c1e13e0

Browse files
EPC filename is now supposed to be given in UTF8 encoding
EpcDocument (actually the zip file on hard disk) is now automatically opened and closed.
1 parent 273ef60 commit c1e13e0

13 files changed

Lines changed: 122 additions & 127 deletions

File tree

cmake/FesapiJavaExample.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public class FesapiJavaExample {
100100
*/
101101
static {
102102
try {
103-
System.loadLibrary("${CPP_LIBRARY_NAME}-${Fesapi_VERSION_MAJOR}.${Fesapi_VERSION_MINOR}");
103+
System.loadLibrary("${ASSEMBLY_NAME}");
104104
}
105105
catch (UnsatisfiedLinkError e) {
106106
System.out.println("UnsatisfiedLinkError : " + e.toString());
@@ -673,20 +673,18 @@ private static void serialize()
673673
serializeGraphicalInformationSet(repo, hdfProxy);
674674
${COMMENT_END}
675675

676-
try (EpcDocument pck = new EpcDocument(storageDirectory + File.separator + epcName + ".epc")) {
677-
pck.serializeFrom(repo);
678-
}
676+
EpcDocument pck = new EpcDocument(storageDirectory + File.separator + epcName + ".epc");
677+
pck.serializeFrom(repo);
679678
}
680679
}
681680

682681
private static void deserialize()
683682
{
684683
try (DataObjectRepository repo = new DataObjectRepository()) {
685-
try (EpcDocument pck = new EpcDocument(storageDirectory + File.separator + epcName + ".epc")) {
686-
String status = pck.deserializeInto(repo);
687-
if (!status.isEmpty()) {
688-
System.out.println("Status : " + status);
689-
}
684+
EpcDocument pck = new EpcDocument(storageDirectory + File.separator + epcName + ".epc");
685+
String status = pck.deserializeInto(repo);
686+
if (!status.isEmpty()) {
687+
System.out.println("Status : " + status);
690688
}
691689

692690
LongStream.range(0, repo.getLocal3dCrsCount()).forEach(index -> System.out.println("CRS title is " + repo.getLocal3dCrs(index).getTitle()));

cmake/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,6 @@ private static void serialize()
253253
dummyPoints.setitem(2, 3.0);
254254
repo.createPointSetRepresentation("", "").pushBackXyzGeometryPatch(1, dummyPoints.cast());
255255
dummyPoints.Dispose();
256-
// **************************************
257-
// **************************************
258-
259-
epc_file.close();
260256
}
261257
}
262258

example/example.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ void serializeBoundaries(COMMON_NS::DataObjectRepository * repo, EML2_NS::Abstra
618618
//**************
619619
// Horizon Representations
620620
//**************
621-
RESQML2_NS::PolylineRepresentation* h1i1SinglePolylineRep = repo->createPolylineRepresentation(horizon1Interp1, "", "Horizon1 Interp1 SinglePolylineRep");
621+
RESQML2_NS::PolylineRepresentation* h1i1SinglePolylineRep = repo->createPolylineRepresentation(horizon1Interp1, "47f86668-27c4-4b28-a19e-bd0355321ecc", "Horizon1 Interp1 SinglePolylineRep");
622622
double h1i1SinglePolylineRepPoints[12] = { 0, 100, 300, 150, 110, 300, 450, 130, 350, 600, 140, 350 };
623623
h1i1SinglePolylineRep->setGeometry(h1i1SinglePolylineRepPoints, 4, hdfProxy);
624624
double seismicLineAbscissa[4] = { 0.0, 1.0, 3.0, 4.0 };
@@ -5108,7 +5108,6 @@ void deserialize(const string & inputFile)
51085108
cerr << resqmlResult << endl;
51095109
repo.clearWarnings();
51105110
}
5111-
epcDoc.close();
51125111

51135112
const unsigned int hdfProxyCount = repo.getHdfProxyCount();
51145113
cout << "There are " << hdfProxyCount << " hdf files associated to this epc document." << endl;
@@ -5679,20 +5678,20 @@ void appendAContinuousProp(const string& filePath)
56795678
}
56805679

56815680
// filepath is defined in a macro to better check memory leak
5682-
#define filePath "../../testingPackageCpp.epc"
5681+
#define filePath u8"../../testingPackageCpp.epc"
56835682
int main()
56845683
{
5685-
//try {
5684+
try {
56865685
if (serialize(filePath)) {
56875686
appendAContinuousProp(filePath);
56885687
deserialize(filePath);
56895688
}
5690-
/*}
5689+
}
56915690
catch (const std::invalid_argument & Exp)
56925691
{
56935692
std::cerr << "Error : " << Exp.what() << ".\n";
56945693
return 1;
5695-
}*/
5694+
}
56965695

56975696
#ifdef _WIN32
56985697
_CrtDumpMemoryLeaks();

example/exampleMPI.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void deserialize(const std::string filename) {
9797
std::cerr << resqmlResult << std::endl;
9898
repo.clearWarnings();
9999
}
100-
pck.close();
101100

102101
auto* unstructuredGrid_4cells = repo.getUnstructuredGridRepresentation(0);
103102
RESQML2_NS::ContinuousProperty* prop = dynamic_cast<RESQML2_NS::ContinuousProperty*>(unstructuredGrid_4cells->getValuesProperty(0));

java/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ file (REMOVE_RECURSE ${FESAPI_ROOT_DIR}/java/src/com/f2i_consulting/fesapi/prodm
3232
# The name of the library is different on Windows because it includes the version
3333
if (WIN32)
3434
if (SWIG_LINKED_TO_RELEASE)
35-
set (ASSEMBLY_NAME ${CPP_LIBRARY_NAME}${CMAKE_RELEASE_POSTFIX}.${Fesapi_VERSION})
35+
set (ASSEMBLY_NAME ${CPP_LIBRARY_NAME}${CMAKE_RELEASE_POSTFIX}-${Fesapi_VERSION_MAJOR}.${Fesapi_VERSION_MINOR})
3636
else (SWIG_LINKED_TO_RELEASE)
37-
set (ASSEMBLY_NAME ${CPP_LIBRARY_NAME}${CMAKE_DEBUG_POSTFIX}.${Fesapi_VERSION})
37+
set (ASSEMBLY_NAME ${CPP_LIBRARY_NAME}${CMAKE_DEBUG_POSTFIX}-${Fesapi_VERSION_MAJOR}.${Fesapi_VERSION_MINOR})
3838
endif (SWIG_LINKED_TO_RELEASE)
3939
else (WIN32)
4040
if (SWIG_LINKED_TO_RELEASE)

python/example/example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def serialize(file_name: str):
6262
serialize_grid(repo)
6363

6464
epc_file.serializeFrom(repo)
65-
epc_file.close()
6665

6766
def show_all_metadata(data_object: fesapi.AbstractObject):
6867
"""
@@ -151,7 +150,6 @@ def deserialize(file_name: str):
151150
if not warnings:
152151
print(warnings)
153152
repo.clearWarnings()
154-
epc_file.close()
155153

156154
hdf_proxy_count = repo.getHdfProxyCount()
157155
print("There is/are " + str(hdf_proxy_count) + " hdf file(s) associated to this epc document.")

src/common/EpcDocument.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ using namespace std;
4848
using namespace gsoap_resqml2_0_1;
4949
using namespace COMMON_NS;
5050

51-
void EpcDocument::open(const std::string & fileName)
52-
{
53-
if (fileName.empty()) {
54-
throw invalid_argument("The epc document name cannot be empty.");
55-
}
56-
if (package != nullptr) {
57-
throw invalid_argument("The epc document must be closed before to be opened again.");
58-
}
59-
60-
setFilePath(fileName);
61-
62-
package.reset(new epc::Package());
63-
}
64-
6551
void EpcDocument::setFilePath(const std::string & fp)
6652
{
6753
filePath = fp;
@@ -249,11 +235,11 @@ namespace {
249235
}
250236
}
251237

252-
void EpcDocument::serializeFrom(DataObjectRepository& repo, bool useZip64)
238+
void EpcDocument::serializeFrom(DataObjectRepository& repo)
253239
{
254240
addFakePropertyToEmptyPropertySet(repo);
255241

256-
package->openForWriting(filePath, APPEND_STATUS_CREATE, useZip64);
242+
package->openForWriting(filePath, APPEND_STATUS_CREATE);
257243

258244
for (auto const& uuidDataobjectPair : repo.getDataObjects()) {
259245
for (auto const& dataobject : uuidDataobjectPair.second) {
@@ -359,6 +345,8 @@ string EpcDocument::deserializeInto(DataObjectRepository & repo, DataObjectRepos
359345
hdfProxy->setOpeningMode(hdfPermissionAccess); // Must repeat this setter in case of RESQML2.2 which is not an obj_EpcExternalPartReference
360346
}
361347

348+
package->close();
349+
362350
return result;
363351
}
364352

@@ -440,6 +428,8 @@ std::string EpcDocument::deserializePartiallyInto(DataObjectRepository & repo, D
440428
hdfProxy->setOpeningMode(hdfPermissionAccess); // Must repeat this setter in case of RESQML2.2 which is not an obj_EpcExternalPartReference
441429
}
442430

431+
package->close();
432+
443433
return result;
444434
}
445435

@@ -508,13 +498,12 @@ uint64_t EpcDocument::getExtendedCorePropertyCount() const
508498
return package->getExtendedCoreProperty().size();
509499
}
510500

511-
std::string EpcDocument::getExtendedCoreProperty(const std::string & key)
501+
std::string EpcDocument::getExtendedCoreProperty(const std::string & key) const
512502
{
513-
if (package->getExtendedCoreProperty().find(key) != package->getExtendedCoreProperty().end()) {
514-
return (package->getExtendedCoreProperty())[key];
515-
}
516-
517-
return "";
503+
auto entry = package->getExtendedCoreProperty().find(key);
504+
return entry != package->getExtendedCoreProperty().end()
505+
? entry->second
506+
: "";
518507
}
519508

520509
std::string EpcDocument::resolvePartial(AbstractObject const * partialObj) const
@@ -527,9 +516,12 @@ std::string EpcDocument::resolvePartial(AbstractObject const * partialObj) const
527516
for (auto it : package->getFileContentType().getAllContentType()) {
528517
if (it.first.find(partialObj->getUuid()) != std::string::npos)
529518
{
530-
return package->extractFile(it.second.getExtensionOrPartName().substr(1));
519+
std::string result = package->extractFile(it.second.getExtensionOrPartName().substr(1));
520+
package->close();
521+
return result;
531522
}
532523
}
533524

525+
package->close();
534526
return "";
535527
}

src/common/EpcDocument.h

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,30 @@ namespace COMMON_NS
4242
/**
4343
* Constructor
4444
*
45-
* @param fileName Full pathname of the EPC document.
45+
* @param fileName Full pathname of the EPC document in UTF-8 encoding.
4646
*/
47-
DLL_IMPORT_OR_EXPORT EpcDocument(const std::string & fileName) { open(fileName); }
47+
DLL_IMPORT_OR_EXPORT EpcDocument(const std::string& fileName) { open(fileName); }
4848

4949
/** The destructor frees all allocated ressources. */
50-
DLL_IMPORT_OR_EXPORT ~EpcDocument() { close(); }
50+
DLL_IMPORT_OR_EXPORT ~EpcDocument() = default;
5151

5252
/**
53-
* Opens an EPC document. If one is already opened, it must be closed before to open a new one.
54-
* Don't forget to call {@link close()} before to destroy this object.
53+
* Opens an EPC document.
5554
*
56-
* @exception std::invalid_argument if the name of the EPC document is empty or if there is
57-
* already an opened EPC document.
58-
*
59-
* @param fileName Full pathname of the EPC document.
55+
* @param fileName Full pathname of the EPC document in UTF-8 encoding.
6056
*/
61-
DLL_IMPORT_OR_EXPORT void open(const std::string & fileName);
62-
63-
/** Free all ressources contained in this package. */
64-
DLL_IMPORT_OR_EXPORT void close() {
65-
package.reset();
66-
filePath = "";
57+
DLL_IMPORT_OR_EXPORT void open(const std::string& fileName)
58+
{
59+
setFilePath(fileName);
60+
package.reset(new epc::Package());
6761
}
6862

69-
/**
70-
* Sets the EPC document file path which will be used for future serialization and
71-
* deserialization. This method will add the standard @c .epc extension if it is not already
72-
* present.
73-
*
74-
* @exception std::invalid_argument if the HDF5 file error handling cannot be disabled.
75-
*
76-
* @param fp Full pathname of the EPC document.
77-
*/
78-
DLL_IMPORT_OR_EXPORT void setFilePath(const std::string & fp);
79-
8063
/**
8164
* Serializes the content of a data object repository into this EPC document.
8265
*
8366
* @param repo A data object repository (not const because we may create a Fake Property for solivng a RESQML2.0.1 empty PropertySet issue)
84-
* @param useZip64 (Optional) True to zip the EPC document using Zip64 format, else (default) simply use Zip format.
8567
*/
86-
DLL_IMPORT_OR_EXPORT void serializeFrom(DataObjectRepository& repo, bool useZip64 = false);
68+
DLL_IMPORT_OR_EXPORT void serializeFrom(DataObjectRepository& repo);
8769

8870
/**
8971
* Deserializes this package (data objects and relationships) into a data object repository
@@ -118,42 +100,56 @@ namespace COMMON_NS
118100

119101
/**
120102
* Gets the extended core properties of this package
103+
* The EpcDocument must have been deserialized at least once to get the extended core proeprties information.
121104
*
122105
* @returns A map which associates keys and values of the extended core properties.
123106
*/
124-
DLL_IMPORT_OR_EXPORT std::unordered_map< std::string, std::string > & getExtendedCoreProperty();
107+
DLL_IMPORT_OR_EXPORT std::unordered_map< std::string, std::string >& getExtendedCoreProperty();
125108

126109
/**
127110
* Sets or adds an extended core property
128111
*
129112
* @param key The key of the property.
130113
* @param value The value of the property.
131114
*/
132-
DLL_IMPORT_OR_EXPORT void setExtendedCoreProperty(const std::string & key, const std::string & value);
115+
DLL_IMPORT_OR_EXPORT void setExtendedCoreProperty(const std::string& key, const std::string& value);
133116

134117
/**
135118
* Gets extended core property count.
119+
* The EpcDocument must have been deserialized at least once to get the extended core proeprties information.
136120
*
137121
* @returns The count of extended core properties in this EPC document
138122
*/
139123
DLL_IMPORT_OR_EXPORT uint64_t getExtendedCorePropertyCount() const;
140124

141125
/**
142126
* Gets an extended core property value according to its key.
127+
* The EpcDocument must have been deserialized at least once to get the extended core proeprties information.
143128
*
144129
* @param key The key of the property.
145130
*
146131
* @returns An empty string if the extended core property does not exist. Or the extended core
147132
* property value if it exists.
148133
*/
149-
DLL_IMPORT_OR_EXPORT std::string getExtendedCoreProperty(const std::string & key);
134+
DLL_IMPORT_OR_EXPORT std::string getExtendedCoreProperty(const std::string& key) const;
150135

151-
DLL_IMPORT_OR_EXPORT std::string resolvePartial(AbstractObject const * partialObj) const;
136+
DLL_IMPORT_OR_EXPORT std::string resolvePartial(AbstractObject const* partialObj) const;
152137

153138
private :
154-
static constexpr char const* DOCUMENT_EXTENSION = ".epc";
139+
/**
140+
* Sets the EPC document file path which will be used for future serialization and
141+
* deserialization. This method will add the standard @c .epc extension if it is not already
142+
* present.
143+
*
144+
* @exception std::invalid_argument if the HDF5 file error handling cannot be disabled.
145+
*
146+
* @param fp Full pathname of the EPC document.
147+
*/
148+
void setFilePath(const std::string& fp);
155149

156-
void deserializeRelFiles(DataObjectRepository & repo);
150+
void deserializeRelFiles(DataObjectRepository& repo);
151+
152+
static constexpr char const* DOCUMENT_EXTENSION = ".epc";
157153

158154
/** The package */
159155
std::unique_ptr<epc::Package> package;

src/epc/Package.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ under the License.
3636

3737
#include <zip.h>
3838
#include <unzip.h>
39+
#ifdef _WIN32
40+
#include <iowin32.h>
41+
#endif
3942

4043
#include "FilePart.h"
4144

@@ -100,7 +103,7 @@ Package::~Package()
100103
delete d_ptr;
101104
}
102105

103-
void Package::openForWriting(const std::string & pkgPathName, int append, bool useZip64)
106+
void Package::openForWriting(const std::string & pkgPathName, int append)
104107
{
105108
d_ptr->allFileParts.clear();
106109
d_ptr->fileContentType.clear();
@@ -118,8 +121,21 @@ void Package::openForWriting(const std::string & pkgPathName, int append, bool u
118121

119122
addRelationship(Relationship("docProps/core.xml", CORE_PROP_REL_TYPE, "CoreProperties"));
120123

121-
d_ptr->isZip64 = useZip64;
122-
d_ptr->zf = useZip64 ? zipOpen64(d_ptr->pathName.c_str(), append) : zipOpen(d_ptr->pathName.c_str(), append);
124+
d_ptr->isZip64 = true;
125+
#ifdef WIN32
126+
zlib_filefunc64_def ffunc;
127+
fill_win32_filefunc64W(&ffunc);
128+
129+
// Convert path from UTF-8 to Unicode
130+
const int count = MultiByteToWideChar(CP_UTF8, 0, d_ptr->pathName.c_str(), static_cast<int>(d_ptr->pathName.size()), NULL, 0);
131+
std::wstring unicodePath(count, 0);
132+
MultiByteToWideChar(CP_UTF8, 0, d_ptr->pathName.c_str(), static_cast<int>(d_ptr->pathName.size()), &unicodePath[0], count);
133+
134+
d_ptr->zf = zipOpen2_64(unicodePath.c_str(), append, NULL, &ffunc);
135+
#else
136+
// Unix systems handles path in the UTF-8 by default
137+
d_ptr->zf = zipOpen64(d_ptr->pathName.c_str(), append);
138+
#endif
123139

124140
if (d_ptr->zf == nullptr) {
125141
throw invalid_argument("The file " + pkgPathName + " could not be opened");
@@ -136,7 +152,20 @@ std::vector<std::string> Package::openForReading(const std::string & pkgPathName
136152
std::vector<std::string> result;
137153
d_ptr->pathName.assign(pkgPathName);
138154

155+
#ifdef WIN32
156+
zlib_filefunc64_def ffunc;
157+
fill_win32_filefunc64W(&ffunc);
158+
159+
// Convert path from UTF-8 to Unicode
160+
const int count = MultiByteToWideChar(CP_UTF8, 0, d_ptr->pathName.c_str(), static_cast<int>(d_ptr->pathName.size()), NULL, 0);
161+
std::wstring unicodePath(count, 0);
162+
MultiByteToWideChar(CP_UTF8, 0, d_ptr->pathName.c_str(), static_cast<int>(d_ptr->pathName.size()), &unicodePath[0], count);
163+
164+
d_ptr->unzipped = unzOpen2_64(unicodePath.c_str(), &ffunc);
165+
#else
166+
// Unix systems handles path in the UTF-8 by default
139167
d_ptr->unzipped = unzOpen64(d_ptr->pathName.c_str());
168+
#endif
140169

141170
if (d_ptr->unzipped == nullptr) {
142171
throw invalid_argument("Cannot unzip " + pkgPathName + ". Please verify the path of the file and if you can open it with a third party archiver.");

0 commit comments

Comments
 (0)