本文整理汇总了C++中ZipEntry::getLFHOffset方法的典型用法代码示例。如果您正苦于以下问题:C++ ZipEntry::getLFHOffset方法的具体用法?C++ ZipEntry::getLFHOffset怎么用?C++ ZipEntry::getLFHOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry::getLFHOffset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: crunchArchive
/*
* Crunch deleted files out of an archive by shifting the later files down.
*
* Because we're not using a temp file, we do the operation inside the
* current file.
*/
status_t ZipFile::crunchArchive(void)
{
status_t result = NO_ERROR;
int i, count;
long delCount, adjust;
#if 0
printf("CONTENTS:\n");
for (i = 0; i < (int) mEntries.size(); i++) {
printf(" %d: lfhOff=%ld del=%d\n",
i, mEntries[i]->getLFHOffset(), mEntries[i]->getDeleted());
}
printf(" END is %ld\n", (long) mEOCD.mCentralDirOffset);
#endif
/*
* Roll through the set of files, shifting them as appropriate. We
* could probably get a slight performance improvement by sliding
* multiple files down at once (because we could use larger reads
* when operating on batches of small files), but it's not that useful.
*/
count = mEntries.size();
delCount = adjust = 0;
for (i = 0; i < count; i++) {
ZipEntry* pEntry = mEntries[i];
long span;
if (pEntry->getLFHOffset() != 0) {
long nextOffset;
/* Get the length of this entry by finding the offset
* of the next entry. Directory entries don't have
* file offsets, so we need to find the next non-directory
* entry.
*/
nextOffset = 0;
for (int ii = i+1; nextOffset == 0 && ii < count; ii++)
nextOffset = mEntries[ii]->getLFHOffset();
if (nextOffset == 0)
nextOffset = mEOCD.mCentralDirOffset;
span = nextOffset - pEntry->getLFHOffset();
assert(span >= ZipEntry::LocalFileHeader::kLFHLen);
} else {
/* This is a directory entry. It doesn't have
* any actual file contents, so there's no need to
* move anything.
*/
span = 0;
}
//printf("+++ %d: off=%ld span=%ld del=%d [count=%d]\n",
// i, pEntry->getLFHOffset(), span, pEntry->getDeleted(), count);
if (pEntry->getDeleted()) {
adjust += span;
delCount++;
delete pEntry;
mEntries.removeAt(i);
/* adjust loop control */
count--;
i--;
} else if (span != 0 && adjust > 0) {
/* shuffle this entry back */
//printf("+++ Shuffling '%s' back %ld\n",
// pEntry->getFileName(), adjust);
result = filemove(mZipFp, pEntry->getLFHOffset() - adjust,
pEntry->getLFHOffset(), span);
if (result != NO_ERROR) {
/* this is why you use a temp file */
LOGE("error during crunch - archive is toast\n");
return result;
}
pEntry->setLFHOffset(pEntry->getLFHOffset() - adjust);
}
}
/*
* Fix EOCD info. We have to wait until the end to do some of this
* because we use mCentralDirOffset to determine "span" for the
* last entry.
*/
mEOCD.mCentralDirOffset -= adjust;
mEOCD.mNumEntries -= delCount;
mEOCD.mTotalNumEntries -= delCount;
mEOCD.mCentralDirSize = 0; // mark invalid; set by flush()
assert(mEOCD.mNumEntries == mEOCD.mTotalNumEntries);
assert(mEOCD.mNumEntries == count);
return result;
//.........这里部分代码省略.........