⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zipcentraldir.h

📁 ZIP压缩代码:基于开源ZipArchive和zlib
💻 H
📖 第 1 页 / 共 2 页
字号:
		\note \e bSporadically set to \c false rebuilds #m_findarray if necessary
	*/
	int FindFile(LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly);


	/**
		\see CZipArchive::GetFindFastIndex
	*/
	int GetFindFastIndex(int iFindFastIndex)const
	{
		if (!IsValidIndex(iFindFastIndex) || !m_bFindFastEnabled)
		{
	// 		ASSERT(FALSE); // 
			return -1;
		}
		
		return m_findarray[iFindFastIndex].m_uIndex;
	}

	/**
		Points to CZipArchive::m_storage.
	*/
	CZipStorage* m_pStorage;
	
	
	/**
		The size of the buffer used in searching for the central dir.
		Set before opening the archive.
		It is usually set with CZipArchive::SetAdvanced
		(specify this value as the third argument).
		\see CZipArchive::SetAdvanced
	*/
	int m_iBufferSize;
	



	/**
		Holds all the files inside archive info.
		\see CZipFileHeader
	*/
	CZipArray<CZipFileHeader*> m_headers;
	
	CZipFileHeader* operator[](int iIndex)
	{
		return m_headers[iIndex];
	}
	const CZipFileHeader* operator[](int iIndex) const
	{
		return m_headers[iIndex];
	}

	
	/**
		- If \c true, the conversion of the filenames takes 
		place after opening the archive (after reading the central directory 
		from the file), and before writing the central directory back to
		the archive.
		- If \c false, the conversion takes place on each call to CZipArchive::GetFileInfo

		Change is value with CZipArchive::SetConvertAfterOpen.

		Set it to \c true when you plan to use CZipArchive::FindFile or get the stored files information. <BR>
		Set it to \c false when you plan mostly to modify the archive.

		\b Default: \c true
		\note Set it before opening the archive.
		\see CZipArchive::SetConvertAfterOpen
		\see ConvertFileName
	*/
	bool m_bConvertAfterOpen;
	

/**
	Convert the filename of the CZipFileHeader depending on the current system
	and the system the zip file was created on (change slash to backslash or
	vice versa, perform ANSI-OEM conversion if necessary).
	\param	bFromZip
		if \c true, convert from archive format
	\param	bAfterOpen
		if \c true, called after opening the archive or before closing
	\param	pHeader		
		the header to have filename converted; if \c NULL convert the currently
		opened file
	\see ZipCompatibility::FileNameUpdate
	\see m_bConvertAfterOpen
*/
	void ConvertFileName(bool bFromZip, bool bAfterOpen, CZipFileHeader* pHeader = NULL) const
	{
		if (bAfterOpen != m_bConvertAfterOpen)
			return;
		if (!pHeader)
		{
			pHeader = m_pOpenedFile;
			ASSERT(pHeader);
		}
		ZipCompatibility::FileNameUpdate(*pHeader, bFromZip);
	}

/**
	Convert all the filenames to the system form.
	Called by CZipArchive::FindFile
	\see CZipArchive::FindFile
*/
	void ConvertAll();

/**
	\param	lpszFileName
		the name of the file to find, must be exactly the same (apart from case)
		as it appears in the archive
	\return	the index in #m_findarray with the appropriate CZipFindFast structure
	or \c -1 if there is no file with the given name
	\see CZipArchive::FindFile
*/
	int FindFileNameIndex(LPCTSTR lpszFileName) const;

	DWORD GetBytesBefore() const {return m_info.m_uBytesBeforeZip;}
	/**
		Get the information about the central directory
	*/
	void GetInfo(Info& info) const {info = m_info;}
	/**
		\return the value of m_bFindFastEnabled
	*/
	bool IsFindFastEnabled(){return m_bFindFastEnabled;}
	/**
		Called by CZipArchive::RenameFile
	*/
	void RenameFile(WORD uIndex, LPCTSTR lpszNewName);
protected:
	/**
		Sort the files inside the archive headers by the order in the archive.
	*/
	void SortHeaders();
	static int CompareHeaders(const void *pArg1, const void *pArg2)
	{
		CZipFileHeader* pw1 = *(CZipFileHeader**)pArg1;
		CZipFileHeader* pw2 = *(CZipFileHeader**)pArg2;
		if ((pw1->m_uOffset < pw2->m_uOffset && pw1->m_uDiskStart == pw2->m_uDiskStart)
			|| (pw1->m_uDiskStart < pw2->m_uDiskStart))
			return -1;
		else if ((pw1->m_uOffset > pw2->m_uOffset && pw1->m_uDiskStart == pw2->m_uDiskStart)
			|| (pw1->m_uDiskStart > pw2->m_uDiskStart))
			return 1;
		else
		{
			ASSERT(FALSE);
			// two files with the same offsets on the same disk???
			CZipException::Throw(CZipException::badZipFile);
			return 0; // just for the compiler comfort
		}
	}


/**
	Build #m_findarray.
*/
	void BuildFindFastArray( bool bCaseSensitive );

	/**
		Used in fast finding files by the filename.
		\see CZipFindFast
		\see m_bFindFastEnabled
		\see CZipArchive::FindFile
	*/
	CZipArray<CZipFindFast> m_findarray;

	/**
		If \c true, the there is an additional array build, to speed up the 
		finding process
		CZipArchive::FindFile uses this array to perform a 
		binary search.
		\b Default: \c false
		\see CZipArchive::EnableFindFast
		\see CZipArchive::FindFile
		\see CZipCentralDir::m_findarray
	*/
	bool m_bFindFastEnabled;



/**
	The \e lpszFileName and \e bCaseSensitive arguments 
	are the same as in the #FindFileNameIndex. The function get CZipFindFast
	structure pointed by \e uIndex and compares the filename of CZipFileHeader
	class stored in this structure with \e lpszFileName.
	\param	lpszFileName
	\param	uIndex
		the index from #m_findarray
	\return 
	- 0 if the filenames are the same
	- < 0 if the filename stored in the array is less than \e lpszFileName
	- > 0 if the filename stored in the array is greater than \e lpszFileName
*/
	int CompareElement(LPCTSTR lpszFileName, WORD uIndex) const
	{
		return (m_findarray[uIndex].m_pHeader->GetFileName().*m_pCompare)(lpszFileName);
	}
/**
	Insert a new CZipFindFast element to the #m_findarray.
	Initialize CZipFindFast object with \e pHeader and \e uIndex values.
*/
	void InsertFindFastElement(CZipFileHeader* pHeader, WORD uIndex);

	 
	
	/**
	A compare function (Collate or CollateNoCase) set once so as not
	to check every time which one to use<BR>
	ZIPSTRINGCOMPARE is defined in CZipString.h as: <BR>
	<B><CODE> typedef int (CZipString::*ZIPSTRINGCOMPARE)( LPCTSTR ) const; </CODE></B>
	*/
	ZIPSTRINGCOMPARE m_pCompare;

	/**
		The way the m_findarray is sorted
	*/
	bool m_bCaseSensitive;

	/**
		\see Info
	*/
	Info m_info;

	/**
		\return the location of the beginning of the central dir end record in the archive
		\note Throws exceptions.
	*/
	DWORD Locate();	
	/**
		Read the file headers from the file.
		\note Throws exceptions.
	*/
	void ReadHeaders();

	/**
		Free the memory allocated for the CZipFileHeader structures.
	*/
	void RemoveHeaders();
/**
	Remove data descriptors from the write buffer in the disk spanning volume
	that turned out to be one-disk only.
	We do not remove them from password encrypted files.

	\param	bFromBuffer
		if \c true, remove from the buffer in memory otherwise from the file on a disk
	\return	\c false if the file mapping to memory was not successful
	Can happen only when \e bFormBuffer is \c false.
	\note Throws exceptions.
*/
	bool RemoveDataDescr(bool bFromBuffer);
/**
	Write the file headers to the archive.
	\note Throws exceptions.
*/
	void WriteHeaders(CZipActionCallback* pCallback, bool bOneDisk);
/**
	Write the central directory end record.
	\return	the size of the record
	\note Throws exceptions.
*/
	DWORD WriteCentralEnd();

/**
	Throw an exception with the given code.
	\param	err
	\see CZipException::Throw
*/
	void ThrowError(int err) const;
	
	
};


#endif // !defined(AFX_CENTRALDIR_H__859029E8_8927_4717_9D4B_E26E5DA12BAE__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -