//----------------------------------------------------------------------- DataStreamPtr ZipArchive::open(const String& filename) const { // Format not used here (always binary) ZZIP_FILE* zzipFile = zzip_file_open(mZzipDir, filename.c_str(), ZZIP_ONLYZIP | ZZIP_CASELESS); if (!zzipFile) { int zerr = zzip_error(mZzipDir); String zzDesc = getZzipErrorDescription((zzip_error_t)zerr); LogManager::getSingleton().logMessage( mName + " - Unable to open file " + filename + ", error was '" + zzDesc + "'"); // return null pointer return DataStreamPtr(); } // Get uncompressed size too ZZIP_STAT zstat; zzip_dir_stat(mZzipDir, filename.c_str(), &zstat, ZZIP_CASEINSENSITIVE); // Construct & return stream return DataStreamPtr(new ZipDataStream(filename, zzipFile, static_cast<size_t>(zstat.st_size))); }
//----------------------------------------------------------------------- void ZipArchive::checkZzipError(int zzipError, const String& operation) const { if (zzipError != ZZIP_NO_ERROR) { String errorMsg = getZzipErrorDescription(static_cast<zzip_error_t>(zzipError)); OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, mName + " - error whilst " + operation + ": " + errorMsg, "ZipArchive::checkZzipError"); } }
//----------------------------------------------------------------------- DataStreamPtr ZipArchive::open(const String& filename, bool readOnly) const { // zziplib is not threadsafe OGRE_LOCK_AUTO_MUTEX; String lookUpFileName = filename; #if OGRE_RESOURCEMANAGER_STRICT const int flags = 0; #else const int flags = ZZIP_CASELESS; #endif // Format not used here (always binary) ZZIP_FILE* zzipFile = zzip_file_open(mZzipDir, lookUpFileName.c_str(), ZZIP_ONLYZIP | flags); #if !OGRE_RESOURCEMANAGER_STRICT if (!zzipFile) // Try if we find the file { String basename, path; StringUtil::splitFilename(lookUpFileName, basename, path); const FileInfoListPtr fileNfo = findFileInfo(basename, true); if (fileNfo->size() == 1) // If there are more files with the same do not open anyone { Ogre::FileInfo info = fileNfo->at(0); lookUpFileName = info.path + info.basename; zzipFile = zzip_file_open(mZzipDir, lookUpFileName.c_str(), ZZIP_ONLYZIP | flags); // When an error happens here we will catch it below } } #endif if (!zzipFile) { int zerr = zzip_error(mZzipDir); String zzDesc = getZzipErrorDescription((zzip_error_t)zerr); OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, mName+ " Cannot open file: " + lookUpFileName + " - "+zzDesc, "ZipArchive::open"); } // Get uncompressed size too ZZIP_STAT zstat; zzip_dir_stat(mZzipDir, lookUpFileName.c_str(), &zstat, flags); // Construct & return stream return DataStreamPtr(OGRE_NEW ZipDataStream(lookUpFileName, zzipFile, static_cast<size_t>(zstat.st_size))); }
//----------------------------------------------------------------------- DataStreamPtr ZipArchive::open(const String& filename, bool readOnly) { // zziplib is not threadsafe OGRE_LOCK_AUTO_MUTEX; String lookUpFileName = filename; // Format not used here (always binary) ZZIP_FILE* zzipFile = zzip_file_open(mZzipDir, lookUpFileName.c_str(), ZZIP_ONLYZIP | ZZIP_CASELESS); if (!zzipFile) // Try if we find the file { const Ogre::FileInfoListPtr fileNfo = findFileInfo(lookUpFileName, true); if (fileNfo->size() == 1) // If there are more files with the same do not open anyone { Ogre::FileInfo info = fileNfo->at(0); lookUpFileName = info.path + info.basename; zzipFile = zzip_file_open(mZzipDir, lookUpFileName.c_str(), ZZIP_ONLYZIP | ZZIP_CASELESS); // When an error happens here we will catch it below } } if (!zzipFile) { int zerr = zzip_error(mZzipDir); String zzDesc = getZzipErrorDescription((zzip_error_t)zerr); LogManager::getSingleton().logMessage( mName + " - Unable to open file " + lookUpFileName + ", error was '" + zzDesc + "'", LML_CRITICAL); // return null pointer return DataStreamPtr(); } // Get uncompressed size too ZZIP_STAT zstat; zzip_dir_stat(mZzipDir, lookUpFileName.c_str(), &zstat, ZZIP_CASEINSENSITIVE); // Construct & return stream return DataStreamPtr(OGRE_NEW ZipDataStream(lookUpFileName, zzipFile, static_cast<size_t>(zstat.st_size))); }