00001 /* 00002 * Copyright 2008 Netallied Systems GmbH. 00003 * 00004 * Licensed under the MIT Open Source License, for details please see license.txt or the website 00005 * http://www.opensource.org/licenses/mit-license.php 00006 * 00007 */ 00008 00009 #ifndef __DAE_ZAE_UNCOMPRESS_HANDLER_H__ 00010 #define __DAE_ZAE_UNCOMPRESS_HANDLER_H__ 00011 00012 #include <unzip.h> 00013 #include <libxml/xmlreader.h> 00014 #include <dae/daeURI.h> 00015 00024 class DLLSPEC daeZAEUncompressHandler 00025 { 00026 private: 00027 // zip file this object operates on. 00028 unzFile mZipFile; 00029 00030 // URI th zip file this object operates on. 00031 const daeURI& mZipFileURI; 00032 00033 // indicates if the passed URI is a valid zip file. 00034 bool mValidZipFile; 00035 00036 // path to root file in archive this object handles. 00037 std::string mRootFilePath; 00038 00039 // tmp dir where this archive is extracted. 00040 std::string mTmpDir; 00041 00042 // disable copy c-tor and assignment operator. 00043 daeZAEUncompressHandler(const daeZAEUncompressHandler& copy); 00044 daeZAEUncompressHandler& operator=(const daeZAEUncompressHandler& copy); 00045 00046 public: 00047 // Name of manifest file inside ZAE. 00048 static const std::string MANIFEST_FILE_NAME; 00049 // Root xml element inside manifest file. 00050 static const std::string MANIFEST_FILE_ROOT_ELEMENT_NAME; 00051 // Case insensitivity constant from minizip. 00052 static const int CASE_INSENSITIVE; 00053 // Buffer size for extracting files from zip archive. 00054 static const int BUFFER_SIZE; 00055 // Empty string to be returned in case of error. 00056 static const std::string EMPTY_STRING; 00057 00062 daeZAEUncompressHandler(const daeURI& zaeFile); 00063 00067 virtual ~daeZAEUncompressHandler(); 00068 00073 bool isZipFile() {return mValidZipFile;} 00074 00078 const std::string& obtainRootFilePath(); 00079 00084 const std::string& getRootFilePath() {return mRootFilePath;} 00085 00089 const std::string& getTmpDir() {return mTmpDir;} 00090 00091 private: 00096 bool retrieveRootURIFromManifest(const std::string& tmpDir); 00097 00101 bool extractArchive(unzFile zipFile, const std::string& destDir); 00102 00106 bool extractFile(unzFile zipFile, const std::string& destDir); 00107 00111 bool findManifestRootElement(xmlTextReaderPtr xmlReader); 00112 00116 bool checkAndExtractInternalArchive(const std::string& filePath); 00117 }; 00118 00119 #endif //__DAE_ZAE_UNCOMPRESS_HANDLER_H__