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

void CZipArchive::MakeSpaceForReplace ( int  iReplaceIndex,
DWORD  uTotal,
LPCTSTR  lpszFileName 
) [protected]

Parameters:
iReplaceIndex index of file to be replaced
uTotal the size of the new file to replace existing
lpszFileName the filename for callback initialization

Definition at line 3145 of file ziparchive.cpp.

References CZipActionCallback::CallbackEnd(), cbReplace, GetArchivePath(), CZipCentralDir::GetBytesBefore(), GetCallback(), GetCount(), CZipActionCallback::Init(), m_centralDir, CZipCentralDir::m_headers, CZipStorage::m_pFile, m_storage, MovePackedFiles(), and CZipActionCallback::SetTotal().

Referenced by GetFromArchive(), and OpenNewFile().

{

      ASSERT(iReplaceIndex < GetCount() - 1);
      DWORD uReplaceStart = m_storage.m_pFile->GetPosition() - m_centralDir.GetBytesBefore();
      DWORD uReplaceEnd = m_centralDir.m_headers[iReplaceIndex + 1]->m_uOffset;
      DWORD uReplaceTotal = uReplaceEnd - uReplaceStart;
      int iDelta = uTotal - uReplaceTotal;

      if (iDelta != 0)
      {

            //    m_info.Init(); don't - the calling functions will
            CZipActionCallback* pCallback = GetCallback(CZipArchive::cbReplace);
            DWORD uFileLen = m_storage.m_pFile->GetLength();
            DWORD uUpperLimit = uFileLen - m_centralDir.GetBytesBefore(); // will be added in MovePackedFiles
            if (pCallback)
            {
                  pCallback->Init(lpszFileName, GetArchivePath());
                  pCallback->SetTotal(uUpperLimit - uReplaceEnd);
            }

            bool bForward = iDelta > 0;
            if (bForward)
                  m_storage.m_pFile->SetLength(uFileLen + iDelta); // ensure the seek is correct

            MovePackedFiles(uReplaceEnd, uUpperLimit, abs(iDelta), pCallback, bForward);

            if (!bForward)
                  m_storage.m_pFile->SetLength(uFileLen + iDelta); // delta < 0; shrink the file

            m_storage.m_pFile->Seek(uReplaceStart, CZipAbstractFile::begin);
            int iSize = m_centralDir.m_headers.GetSize();
            for (int i = iReplaceIndex + 1; i < iSize; i++)
                  m_centralDir.m_headers[i]->m_uOffset += iDelta;
            if (pCallback)
                  pCallback->CallbackEnd();
      }
}


Generated by  Doxygen 1.6.0   Back to index