Logo Search packages:      
Sourcecode: harbour version File versions  Download package

bool CZipArchive::ExtractFile ( WORD  uIndex,
CZipMemFile mf,
DWORD  nBufSize = 65536 
)

The same as ExtractFile(WORD , LPCTSTR , bool , LPCTSTR , DWORD ) but instead to a physical file, this function decompress the data into CZipMemFile object

Note:
  • if you pass CZipMemFile object already with data, its contents are NOT overwirtten, but the decompressed data is appended at the end
  • if you try to extract a directory, the function will return false

Definition at line 760 of file ziparchive.cpp.

References CZipException::abortedAction, CZipException::abortedSafely, CZipActionCallback::CallbackEnd(), cbExtract, CloseFile(), GetCallback(), GetFileInfo(), CZipFileHeader::GetFileName(), CZipAutoBuffer::GetSize(), CZipActionCallback::Init(), CZipFileHeader::IsDirectory(), CZipFileHeader::m_uUncomprSize, OpenFile(), ReadFile(), CZipActionCallback::SetTotal(), CZipException::Throw(), and CZipMemFile::Write().

{
      if (!nBufSize)
            return false;

      CZipFileHeader header;
      GetFileInfo(header, uIndex); // to ensure that slash and oem conversions take place
      CZipActionCallback* pCallback = GetCallback(cbExtract);
      if (pCallback)
      {
            pCallback->Init(header.GetFileName());
            pCallback->SetTotal(header.m_uUncomprSize);
      }

      if (header.IsDirectory() || !OpenFile(uIndex))
            return false;




      CZipAutoBuffer buf(nBufSize);
      mf.SeekToEnd();
      DWORD iRead;
      int iAborted = 0;
      do
      {
            iRead = ReadFile(buf, buf.GetSize());
            if (iRead)
            {
                  mf.Write(buf, iRead);
                  if (pCallback)
                        if (!(*pCallback)(iRead))
                        {
                              if (iRead == buf.GetSize() && ReadFile(buf, 1) != 0) // test one byte if there is something left
                                    iAborted = CZipException::abortedAction;
                              else
                                    iAborted = CZipException::abortedSafely; // we did it!
                              break;
                        }
            }
      }
      while (iRead == buf.GetSize());
      bool bRet = CloseFile() == 1;
      if (!bRet && iAborted == CZipException::abortedSafely)
            iAborted = CZipException::abortedAction; // sorry, finished, but not successfull

      if (pCallback)
            pCallback->CallbackEnd();

      if (iAborted)
            CZipException::Throw(iAborted); // throw to distuingiush from other return codes
      return bRet;
}


Generated by  Doxygen 1.6.0   Back to index