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

bool CZipArchive::ExtractFile ( WORD  uIndex,
LPCTSTR  lpszPath,
bool  bFullPath = true,
LPCTSTR  lpszNewName = NULL,
DWORD  nBufSize = 65536 
)

Extract the file from the archive. You can set the callback functor with SetCallback. The argument lpszNewName may point to the full path and is influenced by bFullPath argument (if lpszNewName contains drive specification then it is removed)

Parameters:
uIndex the index of the file to extract
lpszPath 
		The PATH only to extract the file to. May not be NULL. If you wish to
		use UNC path you need to replace \\\\ at the beginning of UNC path with \\\\?\UNC\ .
	
bFullPath 
  • if true, then extract with the full path - in this case the resulting file path is lpszPath plus the path stored in the archive or plus lpszNewName if lpszNewName is not NULL.
  • if false, the destination file path is lpszPath + the filename only extracted from the path stored in the archive or from lpszNewName if lpszNewName is specified;
    if m_szRootPath is set previously with SetRootPath then to lpszPath is added the path stored in the archive (or lpszNewName if lpszNewName is specified) that has removed the beginning that equals m_szRootPath (if there is no common beginning then is behaves like m_szRootPath was empty)
lpszNewName The new name of the file after extraction. If NULL the original filename stored in the archive is used. May point to the full path but, if bFullPath is false, only the filename is extracted from this argument,
nBufSize the size of the buffer used while file operations
Returns:
true if successful
Note:
  • To extract files which filenames match a specified pattern, use FindMatches function
  • Throws exceptions.
See also:
SetCallback

ExtractFile(WORD, CZipMemFile&, DWORD)

FindMatches

Definition at line 681 of file ziparchive.cpp.

References CZipException::abortedAction, CZipException::abortedSafely, CZipActionCallback::CallbackEnd(), cbExtract, CloseFile(), ZipPlatform::ForceDirectory(), GetCallback(), GetFileInfo(), CZipFileHeader::GetFileName(), CZipPathComponent::GetFilePath(), CZipAutoBuffer::GetSize(), CZipFileHeader::GetSystemAttr(), CZipActionCallback::Init(), CZipFileHeader::IsDirectory(), CZipFileHeader::m_uUncomprSize, OpenFile(), PredictExtractedFileName(), ReadFile(), CZipActionCallback::SetTotal(), and CZipException::Throw().

{

      if (!nBufSize && !lpszPath)
            return false;

      CZipFileHeader header;
      GetFileInfo(header, uIndex); // to ensure that slash and oem conversions take place
      CZipString szFileNameInZip = (LPCTSTR)header.GetFileName();
      CZipString szFile = PredictExtractedFileName(szFileNameInZip, lpszPath, bFullPath, lpszNewName);
      CZipActionCallback* pCallback = GetCallback(cbExtract);
      if (pCallback)
            pCallback->Init(szFileNameInZip, szFile);


      if (header.IsDirectory())
      {
            if (pCallback)
                  pCallback->SetTotal(0); // in case of calling LeftToDo afterwards

            ZipPlatform::ForceDirectory(szFile);
            ZipPlatform::SetFileAttr(szFile, header.GetSystemAttr());

            if (pCallback)
                  pCallback->CallbackEnd();
            return true;
      }
      else
      {
            if (pCallback)
                  pCallback->SetTotal(header.m_uUncomprSize);

            if (!OpenFile(uIndex))
                  return false;

            CZipPathComponent zpc(szFile);
            ZipPlatform::ForceDirectory(zpc.GetFilePath());
            CZipFile f(szFile, CZipFile::modeWrite |
                  CZipFile::modeCreate | CZipFile::shareDenyWrite);
            DWORD iRead;
            CZipAutoBuffer buf(nBufSize);
            int iAborted = 0;
            do
            {
                  iRead = ReadFile(buf, buf.GetSize());
                  if (iRead)
                  {
                        f.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(f) == 1;
            if (!bRet && iAborted == CZipException::abortedSafely)
                  iAborted = CZipException::abortedAction; // sorry, finished, but not successfull

            if (pCallback)
                  pCallback->CallbackEnd();

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

      }
}


Generated by  Doxygen 1.6.0   Back to index