bool ZipFile::setFilter(const std::string& filterStr) { bool ret = false; do { CC_BREAK_IF(!m_data); CC_BREAK_IF(!m_data->zipFile); std::string filter(filterStr); //str_tolower(filter); // clear existing file list m_data->fileList.clear(); m_data->folderList.clear(); // UNZ_MAXFILENAMEINZIP + 1 - it is done so in unzLocateFile char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; unz_file_info64 fileInfo; // go through all files and store position information about the required files int err = unzGoToFirstFile64(m_data->zipFile, &fileInfo, szCurrentFileName, sizeof(szCurrentFileName) - 1); while (err == UNZ_OK) { unz_file_pos posInfo; int posErr = unzGetFilePos(m_data->zipFile, &posInfo); if (posErr == UNZ_OK) { std::string currentFileName = szCurrentFileName; //str_tolower(currentFileName); // cache info about filtered files only (like 'assets/') if (filter.empty() || currentFileName.substr(0, filter.length()) == filter) { ZipEntryInfo entry; entry.pos = posInfo; entry.uncompressed_size = (uLong)fileInfo.uncompressed_size; m_data->fileList[currentFileName] = entry; size_t pos = currentFileName.rfind('/'); while (pos != std::string::npos) { currentFileName = currentFileName.substr(0, pos); m_data->folderList.insert(currentFileName); pos = currentFileName.rfind('/'); } } } // next file - also get the information about it err = unzGoToNextFile64(m_data->zipFile, &fileInfo, szCurrentFileName, sizeof(szCurrentFileName) - 1); } ret = true; } while(false); return ret; }
KDbool ZipFile::setFilter ( const std::string& sFilter ) { KDbool bRet = KD_FALSE; do { CC_BREAK_IF ( !m_pData ); CC_BREAK_IF ( !m_pData->zipFile ); // clear existing file list m_pData->fileList.clear ( ); // UNZ_MAXFILENAMEINZIP + 1 - it is done so in unzLocateFile KDchar szCurrentFileName [ UNZ_MAXFILENAMEINZIP + 1 ]; unz_file_info64 tFileInfo; // go through all files and store position information about the required files KDint nErr = unzGoToFirstFile64 ( m_pData->zipFile, &tFileInfo, szCurrentFileName, sizeof ( szCurrentFileName ) - 1 ); while ( nErr == UNZ_OK ) { unz_file_pos tPosInfo; KDint nPosErr = unzGetFilePos ( m_pData->zipFile, &tPosInfo ); if ( nPosErr == UNZ_OK ) { std::string sCurrentFileName = szCurrentFileName; // cache info about filtered files only (like 'assets/') if ( sFilter.empty ( ) || sCurrentFileName.substr ( 0, sFilter.length ( ) ) == sFilter ) { ZipEntryInfo tEntry; tEntry.pos = tPosInfo; tEntry.uncompressed_size = (uLong) tFileInfo.uncompressed_size; m_pData->fileList [ szCurrentFileName ] = tEntry; } } // next file - also get the information about it nErr = unzGoToNextFile64 ( m_pData->zipFile, &tFileInfo, szCurrentFileName, sizeof ( szCurrentFileName ) - 1 ); } bRet = KD_TRUE; } while ( 0 ); return bRet; }
bool CCZipFile::genFileList() { bool ret = false; do { CC_BREAK_IF(!m_zipFile); // clear existing file list m_fileList.clear(); // UNZ_MAXFILENAMEINZIP + 1 - it is done so in unzLocateFile char szCurrentFileName[UNZ_MAXFILENAMEINZIP + 1]; unz_file_info64 fileInfo; // go through all files and store position information about the required files int err = unzGoToFirstFile64(m_zipFile, &fileInfo, szCurrentFileName, sizeof(szCurrentFileName) - 1); while (err == UNZ_OK) { unz_file_pos posInfo; int posErr = unzGetFilePos(m_zipFile, &posInfo); if (posErr == UNZ_OK) { std::string currentFileName = szCurrentFileName; { __ZipEntryInfo entry; entry.pos = posInfo; entry.uncompressed_size = (uLong)fileInfo.uncompressed_size; m_fileList[currentFileName] = entry; } } // next file - also get the information about it err = unzGoToNextFile64(m_zipFile, &fileInfo, szCurrentFileName, sizeof(szCurrentFileName) - 1); } ret = true; } while(false); m_hasGenFlist = true; return ret; }