2828#include < dae/daeErrorHandler.h>
2929#include < dae/daeMetaElementAttribute.h>
3030
31- #include < limits>
32- #include < iomanip>
3331using namespace std ;
3432
35- #include < zip.h> // for saving compressed files
36- #ifdef _WIN32
37- #include < iowin32.h>
38- #else
39- #include < unistd.h>
40- #endif
41-
4233// Some helper functions for working with libxml
4334namespace {
4435daeInt getCurrentLineNumber (xmlTextReaderPtr reader) {
@@ -49,12 +40,6 @@ daeInt getCurrentLineNumber(xmlTextReaderPtr reader) {
4940#endif
5041}
5142
52- #ifdef _WIN32
53- static const char s_filesep = ' \\ ' ;
54- #else
55- static const char s_filesep = ' /' ;
56- #endif
57-
5843// Return value should be freed by caller with delete[]. Passed in value should not
5944// be null.
6045xmlChar* utf8ToLatin1 (const xmlChar* utf8) {
@@ -84,26 +69,6 @@ xmlChar* latin1ToUtf8(const string& latin1) {
8469 return utf8;
8570}
8671
87- // wrapper that automatically closes the zip file handle
88- class zipFileHandler
89- {
90- public:
91- zipFileHandler () {
92- zf = NULL ;
93- }
94- ~zipFileHandler () {
95- if ( !!zf ) {
96- int errclose = zipClose (zf,NULL );
97- if (errclose != ZIP_OK) {
98- ostringstream msg;
99- msg << " zipClose error" << errclose << " \n " ;
100- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
101- }
102- }
103- }
104- zipFile zf;
105- };
106-
10772class xmlBufferHandler
10873{
10974public:
@@ -381,30 +346,10 @@ daeInt daeLIBXMLPlugin::write(const daeURI& name, daeDocument *document, daeBool
381346 rawRelPath.makeRelativeTo ( &name );
382347 }
383348
384- std::string fileName = cdom::uriToNativePath (name.str ());
385- bool bcompress = fileName.size () >= 4 && fileName[fileName.size ()-4 ] == ' .' && ::tolower (fileName[fileName.size ()-3 ]) == ' z' && ::tolower (fileName[fileName.size ()-2 ]) == ' a' && ::tolower (fileName[fileName.size ()-1 ]) == ' e' ;
386-
387349 int err=0 ;
388- xmlBufferHandler bufhandler;
389-
390- if ( bcompress ) {
391- // taken from http://xmlsoft.org/examples/testWriter.c
392- // Create a new XML buffer, to which the XML document will be written
393- bufhandler.buf = xmlBufferCreate ();
394- if (!bufhandler.buf ) {
395- ostringstream msg;
396- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) testXmlwriterMemory: Error creating the xml buffer\n " ;
397- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
398- return DAE_ERR_BACKEND_IO;
399- }
400350
401- // Create a new XmlWriter for memory, with no compression. Remark: there is no compression for this kind of xmlTextWriter
402- writer = xmlNewTextWriterMemory (bufhandler.buf , 0 );
403- }
404- else {
405- // Open the file we will write to
406- writer = xmlNewTextWriterFilename (cdom::fixUriForLibxml (name.str ()).c_str (), 0 );
407- }
351+ // Open the file we will write to
352+ writer = xmlNewTextWriterFilename (cdom::fixUriForLibxml (name.str ()).c_str (), 0 );
408353
409354 if (!writer) {
410355 ostringstream msg;
@@ -429,107 +374,6 @@ daeInt daeLIBXMLPlugin::write(const daeURI& name, daeDocument *document, daeBool
429374 xmlFreeTextWriter ( writer );
430375 writer = NULL ; // reset pointer
431376
432- if ( bcompress ) {
433- std::string savefilenameinzip;
434- size_t namestart = fileName.find_last_of (s_filesep);
435- if ( namestart == string::npos ) {
436- namestart = 0 ;
437- }
438- else {
439- namestart+=1 ;
440- }
441- if (namestart+4 >=fileName.size ()) {
442- daeErrorHandler::get ()->handleError (" invalid fileName when removing zae extension" );
443- return DAE_ERR_BACKEND_IO;
444- }
445- savefilenameinzip = fileName.substr (namestart,fileName.size ()-namestart-4 );
446- savefilenameinzip += " .dae" ;
447-
448- zipFileHandler zfh;
449- #ifdef _WIN32
450- zlib_filefunc64_def ffunc;
451- fill_win32_filefunc64A (&ffunc);
452- zfh.zf = zipOpen2_64 (fileName.c_str (),APPEND_STATUS_CREATE,NULL ,&ffunc);
453- #else
454- zfh.zf = zipOpen64 (fileName.c_str (),APPEND_STATUS_CREATE);
455- #endif
456- if (!zfh.zf ) {
457- ostringstream msg;
458- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) Error opening zip file for writing\n " ;
459- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
460- return DAE_ERR_BACKEND_IO;
461- }
462-
463- time_t curtime = time (NULL );
464- struct tm * timeofday = localtime (&curtime);
465- zip_fileinfo zi;
466- zi.tmz_date .tm_sec = timeofday->tm_sec ;
467- zi.tmz_date .tm_min = timeofday->tm_min ;
468- zi.tmz_date .tm_hour = timeofday->tm_hour ;
469- zi.tmz_date .tm_mday = timeofday->tm_mday ;
470- zi.tmz_date .tm_mon = timeofday->tm_mon ;
471- zi.tmz_date .tm_year = timeofday->tm_year ;
472- zi.dosDate = 0 ;
473- zi.internal_fa = 0 ;
474- zi.external_fa = 0 ;
475-
476- int zip64 = bufhandler.buf ->use >= 0xffffffff ;
477-
478- char * password=NULL ;
479- unsigned long crcFile=0 ;
480- int opt_compress_level = 9 ;
481- err = zipOpenNewFileInZip3_64 (zfh.zf ,savefilenameinzip.c_str (),&zi,NULL ,0 ,NULL ,0 ," collada file generated by collada-dom" ,Z_DEFLATED, opt_compress_level,0 ,-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,password,crcFile, zip64);
482- if (err != ZIP_OK) {
483- ostringstream msg;
484- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipOpenNewFileInZip3_64 error" << err << " \n " ;
485- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
486- return DAE_ERR_BACKEND_IO;
487- }
488-
489- err = zipWriteInFileInZip (zfh.zf ,bufhandler.buf ->content , bufhandler.buf ->use );
490- if (err<0 ) {
491- ostringstream msg;
492- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipWriteInFileInZip error for dae file " << err << " \n " ;
493- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
494- return DAE_ERR_BACKEND_IO;
495- }
496- err = zipCloseFileInZip (zfh.zf );
497- if (err!=ZIP_OK) {
498- ostringstream msg;
499- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipCloseFileInZip error for dae file " << err << " \n " ;
500- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
501- return DAE_ERR_BACKEND_IO;
502- }
503-
504- // add the manifest
505- string smanifest = " <?xml version=\" 1.0\" encoding=\" utf-8\" ?>\n <dae_root>./" ;
506- smanifest += savefilenameinzip;
507- smanifest += " </dae_root>\n " ;
508- err = zipOpenNewFileInZip3_64 (zfh.zf ," manifest.xml" ,&zi,NULL ,0 ,NULL ,0 ,NULL ,Z_DEFLATED, opt_compress_level,0 ,-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,password,crcFile, zip64);
509- if (err != ZIP_OK) {
510- ostringstream msg;
511- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipOpenNewFileInZip3_64 error for manifest.xml file " << err << " \n " ;
512- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
513- return DAE_ERR_BACKEND_IO;
514- }
515-
516- err = zipWriteInFileInZip (zfh.zf ,&smanifest[0 ],smanifest.size ());
517- if (err != ZIP_OK) {
518- ostringstream msg;
519- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipWriteInFileInZip error for manifest.xml file " << err << " \n " ;
520- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
521- return DAE_ERR_BACKEND_IO;
522- }
523-
524- err = zipCloseFileInZip (zfh.zf );
525- if (err != ZIP_OK) {
526- ostringstream msg;
527- msg << " daeLIBXMLPlugin::write(" << name.str () << " ) zipCloseFileInZip error for manifest.xml file " << err << " \n " ;
528- daeErrorHandler::get ()->handleError (msg.str ().c_str ());
529- return DAE_ERR_BACKEND_IO;
530- }
531- }
532-
533377 if ( saveRawFile && rawFile != NULL )
534378 {
535379 fclose ( rawFile );
0 commit comments