// Direct File Operations: bool nglZipFS::Close(void* pUnzip) { if (pUnzip == NULL) return false; unzSetCurrentFile(mpPrivate->mZip, pUnzip); return UNZ_CRCERROR != unzCloseCurrentFile(mpPrivate->mZip); }
nglStreamState nglZipFS::GetState(void* pUnzip) const { if (pUnzip == NULL) return eStreamError; unzSetCurrentFile(mpPrivate->mZip, pUnzip); if (unzeof(mpPrivate->mZip)) return eStreamEnd; return eStreamReady; }
nglSize nglZipFS::Read (void* pUnzip, void* pData, nglSize WordCount, uint WordSize, nglEndian nglEndian) { if (unzSetCurrentFile(mpPrivate->mZip, pUnzip) != UNZ_OK) return 0; nglSize done = unzReadCurrentFile(mpPrivate->mZip, pData, WordCount * WordSize); done /= WordSize; if ((done > 0) && (nglEndian != eEndianNative)) { switch (WordSize) { case 2: bswap_16_s ((uint16*)pData, done); break; case 4: bswap_32_s ((uint32*)pData, done); break; case 8: bswap_64_s ((uint64*)pData, done); break; } } return done; }
nglFileOffset nglZipFS::SetPos (void* pUnzip, nglFileOffset Where, nglIZip* pFile) { unzSetCurrentFile(mpPrivate->mZip, pUnzip); char dummy[1024]; nglFileOffset Pos = GetPos(pUnzip); if (Where < Pos) { unzCloseCurrentFile(mpPrivate->mZip); unz_file_pos file_pos; file_pos.num_of_file = pFile->mNumOfFile; file_pos.pos_in_zip_directory = pFile->mPosInZipDirectory; unzGoToFilePos(mpPrivate->mZip, &file_pos); if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK) return 0; pUnzip = unzGetCurrentFile(mpPrivate->mZip); if (!pUnzip) return 0; pFile->SetRef(pUnzip); Pos = 0; } Where -= Pos; while (Where > 0) { nglFileOffset size = MIN(Where, 1024); nglSize res = Read(pUnzip, dummy, (long)size, 1, eEndianNative); if (res <= 0) // An Error occured return GetPos(pUnzip); Where -= res; } return GetPos(pUnzip); }
nglFileOffset nglZipFS::GetPos(void* pUnzip) const { unzSetCurrentFile(mpPrivate->mZip, pUnzip); return unztell(mpPrivate->mZip); }