📄 stafzipfilecommon.cpp
字号:
STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP5") + " lastModifiedTimeDate [" + lfh->lastModifiedTimeDate + "]"); } // get CRC32 if (rc == kSTAFOk) { rc = util->getLong(zf, &lfh->crc); if (rc == kSTAFOk && lfh->crc == 0 && (*i)->crc != 0) { lfh->crc = (*i)->crc; } STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP6") + " crc [" + lfh->crc + "]"); } // get compressed size if (rc == kSTAFOk) { rc = util->getLong(zf, &lfh->compressedSize); if (rc == kSTAFOk && lfh->compressedSize == 0 && (*i)->compressedSize != 0) { lfh->compressedSize = (*i)->compressedSize; } STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP7") + " compressedSize [" + lfh->compressedSize + "]"); } // get uncompressed size if (rc == kSTAFOk) { rc = util->getLong(zf, &lfh->uncompressedSize); if (rc == kSTAFOk && lfh->uncompressedSize == 0 && (*i)->uncompressedSize != 0) { lfh->uncompressedSize = (*i)->uncompressedSize; } STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP8") + " uncompressedSize [" + lfh->uncompressedSize + "]"); } // get file name length if (rc == kSTAFOk) { uLong iL; rc = util->getShort(zf, &iL); lfh->fileNameLength = (unsigned short)iL; lfh->size += lfh->fileNameLength; STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP9") + " fileNameLength [" + lfh->fileNameLength + "] " + "size [" + lfh->size + "]"); } // get extra field length if (rc == kSTAFOk) { uLong iL; rc = util->getShort(zf, &iL); lfh->extraFieldLength = (unsigned short)iL; lfh->size += lfh->extraFieldLength; STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::readInData_CP10") + " extraFieldLength [" + lfh->extraFieldLength + "] " + "size [" + lfh->size + "]"); } // get file name unsigned char* buf; if (rc == kSTAFOk && lfh->fileNameLength > 0) { buf = (unsigned char*)calloc(lfh->fileNameLength + 1, 1); if (buf == NULL) { *result = STAFString("STAFZipFile::readInData: ") + "Error allocating memory for file name length [" + (lfh->fileNameLength + 1) + "].\n"; return kZIPNotEnoughMemory; } if (fread(buf, (uInt)lfh->fileNameLength, 1, zf) !=1 ) { *result = STAFString("STAFZipFile::readInData: ") + "Error reading filename.\n"; rc = kZIPGeneralZipError; } lfh->fileName = (char*)buf; STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::readInData_CP11") + " fileName [" + lfh->fileName + "]"); } // get extra field if (rc == kSTAFOk && lfh->extraFieldLength > 0) { buf = (unsigned char*)calloc(lfh->extraFieldLength, 1); if(buf == NULL) { *result = STAFString("STAFZipFile::readInData: ") + "Error allocating memory for extra field length [" + lfh->extraFieldLength + "].\n"; return kZIPNotEnoughMemory; } STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipCentralDir::readInData_CP12") + " extraField offset [" + ftell(zf) + "]"); if (fread(buf, (uInt)lfh->extraFieldLength, 1, zf) !=1 ) { *result = STAFString("STAFZipFile::readInData: ") + "Error reading extra field.\n"; rc = kZIPGeneralZipError; } lfh->extraField = (void*)buf; } if (rc != kSTAFOk) { if ((*result).length() != 0) { *result = STAFString("STAFZipFile::readInData: ") + "Error reading local file header data.\n"; } break; } lfh->size = 30 + lfh->fileNameLength + lfh->extraFieldLength + lfh->compressedSize; localFileHeaderListCurrent.push_back(lfh); localFileHeaderListCurrentSorted[STAFString(lfh->fileName)] = lfh; } if (fseek(zf, curPos, SEEK_SET) != 0) { *result = STAFString("STAFZipFile::readInData: ") + STAFString("Error in fseek to original position"); return kZIPGeneralZipError; } return rc;}// find a file name in local file header listSTAFZipLocalFileHeader* STAFZipFile::find(const char *fileName){ STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::find_CP1") + " fileName [" + fileName + "]"); std::map<STAFString, STAFZipLocalFileHeader*>::iterator i; i = localFileHeaderListCurrentSorted.find( STAFString(fileName).replace(kUTF8_BSLASH, kUTF8_SLASH)); if (i != localFileHeaderListCurrentSorted.end()) return i->second; else return NULL;}// find all matching file names in local file header liststd::vector<STAFString> STAFZipFile::findAll(const char *fileName){ STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::findAll_CP1") + " fileName [" + fileName + "]"); std::vector<STAFString> nameList; std::vector<STAFZipLocalFileHeader*>::iterator i; for (i = localFileHeaderListCurrent.begin(); i != localFileHeaderListCurrent.end(); i++) { STAFString fileNameInZip = STAFString((*i)->fileName); if (fileNameInZip.find(STAFString(fileName)) >= 0) nameList.push_back(fileNameInZip); } return nameList; }// find dir name in local file header liststd::vector<STAFString> STAFZipFile::findDir(const char *dirName){ STAFTrace::trace(kSTAFTraceServiceResult, STAFString("STAFZipFile::findDir_CP1") + " dirName [" + dirName + "]"); std::vector<STAFString> nameList; std::vector<STAFZipLocalFileHeader*>::iterator i; STAFString theDirName = STAFString(dirName).replace(kUTF8_BSLASH, kUTF8_SLASH); if (theDirName.findLastOf(STAFString(kUTF8_SLASH)) != theDirName.length()-1) { theDirName += STAFString(kUTF8_SLASH); } for (i = localFileHeaderListCurrent.begin(); i != localFileHeaderListCurrent.end(); i++) { STAFString fileNameInZip = STAFString((*i)->fileName); if (fileNameInZip.find(theDirName) == 0) nameList.push_back(fileNameInZip); } return nameList; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -