本文整理汇总了C++中ZipEntry::initFromCDE方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::initFromCDE方法的具体用法?C++ ZipEntry::initFromCDE怎么用?C++ ZipEntry::initFromCDE使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::initFromCDE方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readCentralDir
//.........这里部分代码省略.........
/* read the last part of the file into the buffer */
if (fread(buf, 1, readAmount, mZipFp) != (size_t) readAmount) {
LOGD("short file? wanted %ld\n", readAmount);
result = UNKNOWN_ERROR;
goto bail;
}
/* find the end-of-central-dir magic */
for (i = readAmount - 4; i >= 0; i--) {
if (buf[i] == 0x50 &&
ZipEntry::getLongLE(&buf[i]) == EndOfCentralDir::kSignature)
{
LOGV("+++ Found EOCD at buf+%d\n", i);
break;
}
}
if (i < 0) {
LOGD("EOCD not found, not Zip\n");
result = INVALID_OPERATION;
goto bail;
}
/* extract eocd values */
result = mEOCD.readBuf(buf + i, readAmount - i);
if (result != NO_ERROR) {
LOGD("Failure reading %ld bytes of EOCD values", readAmount - i);
goto bail;
}
//mEOCD.dump();
if (mEOCD.mDiskNumber != 0 || mEOCD.mDiskWithCentralDir != 0 ||
mEOCD.mNumEntries != mEOCD.mTotalNumEntries)
{
LOGD("Archive spanning not supported\n");
result = INVALID_OPERATION;
goto bail;
}
/*
* So far so good. "mCentralDirSize" is the size in bytes of the
* central directory, so we can just seek back that far to find it.
* We can also seek forward mCentralDirOffset bytes from the
* start of the file.
*
* We're not guaranteed to have the rest of the central dir in the
* buffer, nor are we guaranteed that the central dir will have any
* sort of convenient size. We need to skip to the start of it and
* read the header, then the other goodies.
*
* The only thing we really need right now is the file comment, which
* we're hoping to preserve.
*/
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
LOGD("Failure seeking to central dir offset %ld\n",
mEOCD.mCentralDirOffset);
result = UNKNOWN_ERROR;
goto bail;
}
/*
* Loop through and read the central dir entries.
*/
LOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
int entry;
for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
ZipEntry* pEntry = new ZipEntry;
result = pEntry->initFromCDE(mZipFp);
if (result != NO_ERROR) {
LOGD("initFromCDE failed\n");
delete pEntry;
goto bail;
}
mEntries.add(pEntry);
}
/*
* If all went well, we should now be back at the EOCD.
*/
{
unsigned char checkBuf[4];
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
LOGD("EOCD check read failed\n");
result = INVALID_OPERATION;
goto bail;
}
if (ZipEntry::getLongLE(checkBuf) != EndOfCentralDir::kSignature) {
LOGD("EOCD read check failed\n");
result = UNKNOWN_ERROR;
goto bail;
}
LOGV("+++ EOCD read check passed\n");
}
bail:
delete[] buf;
return result;
}