diff --git a/src/libzippp.cpp b/src/libzippp.cpp index 3bdbbaf..6fc9dfd 100644 --- a/src/libzippp.cpp +++ b/src/libzippp.cpp @@ -442,9 +442,9 @@ int ZipArchive::renameEntry(const ZipEntry& entry, const string& newName) const if (newName==entry.getName()) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } if (entry.isFile()) { - if (ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name + if (LIBZIPPP_ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name - int lastSlash = newName.rfind(ENTRY_PATH_SEPARATOR); + int lastSlash = newName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR); if (lastSlash!=1) { bool dadded = addEntry(newName.substr(0, lastSlash+1)); if (!dadded) { return LIBZIPPP_ERROR_UNKNOWN; } //the hierarchy hasn't been created @@ -454,9 +454,9 @@ int ZipArchive::renameEntry(const ZipEntry& entry, const string& newName) const if (result==0) { return 1; } return LIBZIPPP_ERROR_UNKNOWN; //renaming was not possible (entry already exists ?) } else { - if (!ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name + if (!LIBZIPPP_ENTRY_IS_DIRECTORY(newName)) { return LIBZIPPP_ERROR_INVALID_PARAMETER; } //invalid new name - int parentSlash = newName.rfind(ENTRY_PATH_SEPARATOR, newName.length()-2); + int parentSlash = newName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR, newName.length()-2); if (parentSlash!=-1) { //updates the dir hierarchy string parent = newName.substr(0, parentSlash+1); bool dadded = addEntry(parent); @@ -511,9 +511,9 @@ int ZipArchive::renameEntry(const string& e, const string& newName) const { bool ZipArchive::addFile(const string& entryName, const string& file) const { if (!isOpen()) { return false; } if (mode==READ_ONLY) { return false; } //adding not allowed - if (ENTRY_IS_DIRECTORY(entryName)) { return false; } + if (LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; } - int lastSlash = entryName.rfind(ENTRY_PATH_SEPARATOR); + int lastSlash = entryName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR); if (lastSlash!=-1) { //creates the needed parent directories string dirEntry = entryName.substr(0, lastSlash+1); bool dadded = addEntry(dirEntry); @@ -541,9 +541,9 @@ bool ZipArchive::addFile(const string& entryName, const string& file) const { bool ZipArchive::addData(const string& entryName, const void* data, libzippp_uint64 length, bool freeData) const { if (!isOpen()) { return false; } if (mode==READ_ONLY) { return false; } //adding not allowed - if (ENTRY_IS_DIRECTORY(entryName)) { return false; } + if (LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; } - int lastSlash = entryName.rfind(ENTRY_PATH_SEPARATOR); + int lastSlash = entryName.rfind(LIBZIPPP_ENTRY_PATH_SEPARATOR); if (lastSlash!=-1) { //creates the needed parent directories string dirEntry = entryName.substr(0, lastSlash+1); bool dadded = addEntry(dirEntry); @@ -564,16 +564,16 @@ bool ZipArchive::addData(const string& entryName, const void* data, libzippp_uin bool ZipArchive::addEntry(const string& entryName) const { if (!isOpen()) { return false; } if (mode==READ_ONLY) { return false; } //adding not allowed - if (!ENTRY_IS_DIRECTORY(entryName)) { return false; } + if (!LIBZIPPP_ENTRY_IS_DIRECTORY(entryName)) { return false; } - int nextSlash = entryName.find(ENTRY_PATH_SEPARATOR); + int nextSlash = entryName.find(LIBZIPPP_ENTRY_PATH_SEPARATOR); while (nextSlash!=-1) { string pathToCreate = entryName.substr(0, nextSlash+1); if (!hasEntry(pathToCreate)) { libzippp_int64 result = zip_dir_add(zipHandle, pathToCreate.c_str(), ZIP_FL_ENC_GUESS); if (result==-1) { return false; } } - nextSlash = entryName.find(ENTRY_PATH_SEPARATOR, nextSlash+1); + nextSlash = entryName.find(LIBZIPPP_ENTRY_PATH_SEPARATOR, nextSlash+1); } return true; @@ -589,7 +589,7 @@ int ZipArchive::readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, Stat struct zip_file* zipFile = zip_fopen_index(zipHandle, zipEntry.getIndex(), flag); if (zipFile) { libzippp_uint64 maxSize = zipEntry.getSize(); - if (!chunksize) { chunksize = DEFAULT_CHUNK_SIZE; } // use the default chunk size (512K) if not specified by the user + if (!chunksize) { chunksize = LIBZIPPP_DEFAULT_CHUNK_SIZE; } // use the default chunk size (512K) if not specified by the user if (maxSize0 && (str)[(str).length()-1]==ENTRY_PATH_SEPARATOR) -#define DEFAULT_CHUNK_SIZE 524288 +#define LIBZIPPP_ENTRY_PATH_SEPARATOR '/' +#define LIBZIPPP_ENTRY_IS_DIRECTORY(str) ((str).length()>0 && (str)[(str).length()-1]==LIBZIPPP_ENTRY_PATH_SEPARATOR) +#define LIBZIPPP_DEFAULT_CHUNK_SIZE 524288 //libzip documentation //- http://www.nih.at/libzip/libzip.html @@ -303,10 +303,10 @@ namespace libzippp { * a memory allocation has failed, LIBZIPPP_ERROR_FREAD_FAILURE if zip_fread() didn't succeed to read data, * LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE if the last ofstream operation has failed, LIBZIPPP_ERROR_OWRITE_FAILURE if fread() didn't * return the exact amount of requested bytes and -9 if the amount of extracted bytes didn't match the size of the file (unknown error). - * If the provided chunk size is zero, it will be defaulted to DEFAULT_CHUNK_SIZE (512KB). + * If the provided chunk size is zero, it will be defaulted to LIBZIPPP_DEFAULT_CHUNK_SIZE (512KB). * The method doesn't close the ofstream after the extraction. */ - int readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, State state=CURRENT, libzippp_uint64 chunksize=DEFAULT_CHUNK_SIZE) const; + int readEntry(const ZipEntry& zipEntry, std::ostream& ofOutput, State state=CURRENT, libzippp_uint64 chunksize=LIBZIPPP_DEFAULT_CHUNK_SIZE) const; /** * Deletes the specified entry from the zip file. If the entry is a folder, all its @@ -462,7 +462,7 @@ namespace libzippp { /** * Returns true if the entry is a directory. */ - inline bool isDirectory(void) const { return ENTRY_IS_DIRECTORY(name); } + inline bool isDirectory(void) const { return LIBZIPPP_ENTRY_IS_DIRECTORY(name); } /** * Returns true if the entry is a file. @@ -517,10 +517,10 @@ namespace libzippp { * a memory allocation has failed, LIBZIPPP_ERROR_FREAD_FAILURE if zip_fread() didn't succeed to read data, * LIBZIPPP_ERROR_OWRITE_INDEX_FAILURE if the last ofstream operation has failed, LIBZIPPP_ERROR_OWRITE_FAILURE if fread() didn't * return the exact amount of requested bytes and -9 if the amount of extracted bytes didn't match the size of the file (unknown error). - * If the provided chunk size is zero, it will be defaulted to DEFAULT_CHUNK_SIZE (512KB). + * If the provided chunk size is zero, it will be defaulted to LIBZIPPP_DEFAULT_CHUNK_SIZE (512KB). * The method doesn't close the ofstream after the extraction. */ - int readContent(std::ostream& ofOutput, ZipArchive::State state=ZipArchive::CURRENT, libzippp_uint64 chunksize=DEFAULT_CHUNK_SIZE) const; + int readContent(std::ostream& ofOutput, ZipArchive::State state=ZipArchive::CURRENT, libzippp_uint64 chunksize=LIBZIPPP_DEFAULT_CHUNK_SIZE) const; private: const ZipArchive* zipFile;