Пример #1
0
nglIZip* nglZipFS::GetStream(const nglZipPath& rPath)
{
  Node* pNode = mRoot.Find(rPath);
  if (!pNode)
    return NULL;
  if (!pNode->mIsLeaf)
    return NULL;

  unz_file_pos file_pos;
  file_pos.num_of_file = pNode->mNumOfFile;
  file_pos.pos_in_zip_directory = pNode->mPosInZipDirectory;

  if (unzGoToFilePos(mpPrivate->mZip, &file_pos) != UNZ_OK)
    return NULL;

  if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK)
    return NULL;

  void* pUnzip = unzGetCurrentFile(mpPrivate->mZip);

  if (!pUnzip)
    return NULL;

  return new nglIZip(this, pUnzip, pNode->mSize, pNode->mNumOfFile, pNode->mPosInZipDirectory);
}
Пример #2
0
nglIStream* nglZipFS::OpenRead(const nglPath& rPath)
{
  nglString p(rPath.GetVolumeLessPath());
  p.TrimLeft(_T('/'));
  //wprintf(_T("trimed path '%s'\n"), p.GetChars());
  nglPath path(p);
  Node* pNode = mRoot.Find(path);
  if (!pNode)
    return NULL;
  if (!pNode->mIsLeaf)
    return NULL;

  unz_file_pos file_pos;
  file_pos.num_of_file = pNode->mNumOfFile;
  file_pos.pos_in_zip_directory = pNode->mPosInZipDirectory;

  if (unzGoToFilePos(mpPrivate->mZip, &file_pos) != UNZ_OK)
    return NULL;

  if (unzOpenCurrentFile(mpPrivate->mZip) != UNZ_OK)
    return NULL;

  void* pUnzip = unzGetCurrentFile(mpPrivate->mZip);

  if (!pUnzip)
    return NULL;

  return new nglIZip(this, pUnzip, pNode->mSize, pNode->mNumOfFile, pNode->mPosInZipDirectory);
}
Пример #3
0
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);
}