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

bool CZipArchive::CloseNewFile ( bool  bAfterException = false  ) 

Close the new file in the archive.

Returns:
false if there is no new file opened
Parameters:
bAfterException it will close the new file without writing anything (call it also with this parameter set to true after an exception other than CZipException::abortedSafely was thrown from one of AddNewFile functions)
Note:
Throws exceptions.
See also:
OpenNewFile

Definition at line 883 of file ziparchive.cpp.

References CheckForError(), CZipCentralDir::CloseNewFile(), compress, CryptEncodeBuffer(), CurrentFile(), EmptyPtrList(), Flush(), CZipAutoBuffer::GetSize(), m_bAutoFlush, m_centralDir, m_iFileOpened, m_info, CZipArchive::CZipInternalInfo::m_pBuffer, CZipCentralDir::m_pOpenedFile, m_storage, CZipArchive::CZipInternalInfo::m_stream, CZipArchive::CZipInternalInfo::m_uComprLeft, CZipFileHeader::m_uComprSize, CZipFileHeader::m_uUncomprSize, nothing, CZipArchive::CZipInternalInfo::ReleaseBuf(), and CZipStorage::Write().

Referenced by AddNewFile(), and Close().

{
      if (m_iFileOpened != compress)
      {
            TRACE(_T("%s(%i) : A new file must be opened.\n"),__FILE__,__LINE__);
            return false;
      }

    m_info.m_stream.avail_in = 0;
    if (!bAfterException)
      {
            int err = Z_OK;
            if (CurrentFile()->m_uMethod == Z_DEFLATED)
                  while (err == Z_OK)
                  {
                        if (m_info.m_stream.avail_out == 0)
                        {
                              CryptEncodeBuffer();
                              m_storage.Write(m_info.m_pBuffer, m_info.m_uComprLeft, false);
                              m_info.m_uComprLeft = 0;
                              m_info.m_stream.avail_out = m_info.m_pBuffer.GetSize();
                              m_info.m_stream.next_out = (Bytef*)(char*)m_info.m_pBuffer;
                        }
                        DWORD uTotal = m_info.m_stream.total_out;
                        err = deflate(&m_info.m_stream,  Z_FINISH);
                        m_info.m_uComprLeft += m_info.m_stream.total_out - uTotal;
                  }

            if (err == Z_STREAM_END)
                  err = Z_OK;
            CheckForError(err);

            if (m_info.m_uComprLeft > 0)
            {
                  CryptEncodeBuffer();
                  m_storage.Write(m_info.m_pBuffer, m_info.m_uComprLeft, false);
            }

            if (CurrentFile()->m_uMethod == Z_DEFLATED)
            {
                  err = deflateEnd(&m_info.m_stream);
                  CheckForError(err);
            }


            // it may be increased by the encrypted header size
            CurrentFile()->m_uComprSize += m_info.m_stream.total_out;
            CurrentFile()->m_uUncomprSize = m_info.m_stream.total_in;

            m_centralDir.CloseNewFile();
      }
      else
            m_centralDir.m_pOpenedFile = NULL;

      m_iFileOpened = nothing;
      m_info.ReleaseBuf();
      EmptyPtrList();

      if (m_bAutoFlush && !bAfterException)
            Flush();

      return true;
}


Generated by  Doxygen 1.6.0   Back to index