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

📄 ziparchive.h

📁 允许创建
💻 H
📖 第 1 页 / 共 2 页
字号:
// Argument         : WORD uIndex
//		the index of the file
// Argument         : LPCTSTR lpszPath
//		PATH only to extract the file to
// Argument			: bool bFullPath = true
//		extract the file with full path (if there is a path stored with the filename)
//		or just with the filename alone
//		(it means that the resulting file path is lpszPath + one of the above)	
// Argument			: LPCTSTR lpszNewName = NULL
//			if NULL the default file name is taken (from the archive)
// 	Argument         : ZIPCALLBACKFUN pCallback = NULL
//		See the description at AddNewFile
// 	Argument         : void* pUserData = NULL
// Argument         : DWORD nBufSize = 65535
//		the size of the buffer used during extraction
	bool ExtractFile(WORD uIndex, LPCTSTR lpszPath, bool bFullPath = true, LPCTSTR lpszNewName = NULL, ZIPCALLBACKFUN pCallback = NULL, void* pUserData = NULL, DWORD nBufSize = 65535);

// Function name	: OpenFile
// Description	    : open the file with the given index in the archive for extracting
// Argument         : WORD uIndex
// Return type		: bool 
	bool OpenFile(WORD uIndex);

// Function name	: ReadFile
// Description	    : decompress currently opened file to the bufor
// Return type		: DWORD 
//		number of bytes read			
// Argument         : void *pBuf
//		buffer to receive data
// Argument         : DWORD iSize
//		the size of the buffer
	DWORD ReadFile(void *pBuf, DWORD iSize);

// Function name	: GetLocalExtraField
// Description	    : get the local extra filed of the currently opened 
//					  for extraction file in the archive
// Return type		: int 
//		if pBuf == NULL return the size of the local extra field
// Argument         : char* pBuf
//		the buffer to receive the data
// Argument         : int iSize
//		the size of the buffer
	int GetLocalExtraField(char* pBuf, int iSize);

// Function name	: CloseFile
// Description	    : close current file  and update
//		date and attribute information of CFile, closes CFile
// Return type		: int
//		see below
// Argument         : CFile & file
//		OPENED CFile structure of the extracted file
	int CloseFile(CFile &file);


/**
	Close the file opened for extraction in the archive and copy its date and 
	attributes to the file pointed by \e lpszFilePath
	\param	lpszFilePath 
		Points to the path of the file to have the date and attributes information updated.
	\param bAfterException
		Set to \c true to close the file inside archive after an exception has been 
		thrown, to allow futher operations on the archive.
	\warning Close the file pointed by \e lpszFilePath before using this method, 
		because the system may not be able to retrieve information from it.
	\return		
	-  "1" = ok
	-  "-1" = some bytes left to uncompress - probably due to a bad password
	-  "-2" = setting extracted file date and attributes was not successful	
	\note Throws exceptions.
*/	
	int CloseFile(LPCTSTR lpszFilePath = NULL, bool bAfterException = false);

// Function name	: DeleteFile
// Description	    : delete the file with the given index
// Return type		: bool 
// Argument         : WORD uIndex
//		index of the file to be deleted
	bool DeleteFile(WORD uIndex);

/*	delete files from the archive opened in the Delete mode specified by aIndexes
	or aNames

	aIndexes is a array of indexes of the files inside the archive;
		the index no. 0 is the first file in the archive

	aNames is a array of file names inside the archive; they must be the 
	same as they apppear in the archive (the name and the path (if persists) 
	is required, lower and upper case are not distinguished)

*/
	void DeleteFiles(CWordArray &aIndexes);
	void DeleteFiles(CStringArray &aNames, bool bCaseSensitive = false);


// Function name	: SetGlobalComment
// Description	    : set the global comment in the archive
// Return type		: bool 
//		return false if the archive is closed or if it is an existing disk spanning archive
// Argument         : const CString& szComment
	bool SetGlobalComment(const CString& szComment);

// Function name	: GetGlobalComment
// Description	    : get the global commment
// Return type		: CString 
//		return an empty string if the archive is closed
	CString GetGlobalComment();


// Function name	: SetFileComment
// Description	    : set the comment of the file with the given index
// Return type		: bool 
//		return false if the comment change is imposible
// Argument         : WORD uIndex
//		index of the file
// Argument         : CString szComment
//		comment to add
	bool SetFileComment(WORD uIndex, CString szComment);

// Function name	: GetArchivePath
// Description	    : return the path of the currently opended archive volume
// Return type		: CString 
	CString GetArchivePath();

// Function name	: GetCurrentDisk
// Description	    : return the zero-base number of the current disk
// Return type		: int 
//		return -1 if there is no current disk (archive is closed)
	int GetCurrentDisk();

// Function name	: GetSpanMode
// Description	    : return the disk spanning mode of the cuurrent archive
// Return type		: int 
//		CZipStorage::tdSpan		 == - 2 - exisitng TD compatible disk spanning
//		CZipStorage::pkzipSpan	 == - 1 - exisitng pkzip compatible disk spanning
//		CZipStorage::noSpan		 ==	  0 - no disk spanning
//		CZipStorage::pkzipSpan	 ==   1 - pkzip compatible disk spanning in creation
//		CZipStorage::tdSpan		 ==   2 - TD compatible disk spanning in creation
	int GetSpanMode();

// Function name	: IsFileDirectory
// Description	    : check if the file with the given index is a directory
// Argument         : WORD uIndex
//		index of the file
// Return type		: bool 
//		return true if the file is a directory
//		return false if the file is not a directory or if there is no file
//		with the given index
	bool IsFileDirectory(WORD uIndex);

// Function name	: FindFile
// Description	    : find the file in the archive
// 	This function requires CZipCentralDir::m_bFindFastEnabled set to true
// 	Use EnableFindFast()
// Return type		: int
//		the index of the file found or -1 if no file was found
// Argument         : CString szFileName
//		the name of the file to be found
// Argument         : bool bCaseSensitive = false
//		if true - perform case sensitive search
	int FindFile(CString szFileName, bool bCaseSensitive = false);


/*
	Function name	: EnableFindFast
	Description	    : 
	 	Enable fast finding by the file name of the files inside the archive.
 		Set CZipCentralDir::m_bFindFastEnabled to true, which is required by FindFile.
		Do not enable it, if you don't plan to use FindFile function

	Return type		: void 
	Argument         : bool bEnable = true
*/
	void EnableFindFast(bool bEnable = true);


/*
	Function name	: SetConvertAfterOpen
	Description	    : Set CZipCentralDir::m_bConvertAfterOpen value. Use before opening the archive
	see CZipCentralDir::m_bConvertAfterOpen
	Return type		: void
	Argument         : bool bConvertAfterOpen
*/
	void SetConvertAfterOpen (bool bConvertAfterOpen)
	{
		if (!IsClosed())
		{
			TRACE(_T("Set it before opening the archive"));
			return;
		}
		m_centralDir.m_bConvertAfterOpen = bConvertAfterOpen;

	}


// Function name	: GetFileInfo
// Description	    : get the info of the file with the given index
// Return type		: bool 
//		true if successful
// Argument         : CZipFileHeader & fhInfo
//		structure to receive info
// Argument         : WORD uIndex
//		zero-based index of the file
	bool GetFileInfo(CZipFileHeader & fhInfo, WORD uIndex);


// Function name	: GetNoEntries
// Description	    : get number of files in the archive
// Return type		: int 
	int GetNoEntries();

// Function name	: Close
// Description	    : close archive
// Return type		: void 
// Argument         : bool bAfterException  = false
//		set it to true if you want to close and reuse CZipArchive after is has thrown an exception
//		( it doesn't write any data to the file but only makes some cleaning then)
	void Close(bool bAfterException = false);



// Function name	: IsClosed
// Description	    : test if the archive or the current volume file is closed
// Return type		: bool 
// Argument         : bool bArchive = true
//		if true test for the whole archive, if false - for the volume file only
	bool IsClosed(bool bArchive = true);

// specify whether to control memory allocation and freeing by zlib library
// strongly suggested to set it to true (default)
// set it before opening a file (new or current) in the archive
	bool m_bDetectZlibMemoryLeaks;


	CZipArchive();
	virtual ~CZipArchive();

////////////////////////////////////////////////////////////////////////
//////////////////////  static helper functions  ///////////////////////
////////////////////////////////////////////////////////////////////////

// Function name	: GetFileTitle
// Description	    : get the title of the file
// Return type		: CString 
// Argument         : LPCTSTR lpszFilePath
	static CString GetFileTitle(LPCTSTR lpszFilePath);

// Function name	: GetFileDirAndName
// Description	    : get the directory and the file name from the file path
// Return type		: static CString 
// Argument         : LPCTSTR lpszFilePath
	static CString GetFileDirAndName(LPCTSTR lpszFilePath);

// Function name	: GetDrive
// Description	    : return the (drive:) part from the path
// Return type		: static CString 
// Argument         : LPCTSTR lpszFilePath
	static CString GetDrive(LPCTSTR lpszFilePath);

// Function name	: IsDriveRemovable
// Description	    : return true if the file, path or (disk:) specified by the
//		argument is (on) a removable drive
// Return type		: static bool 
// Argument         : LPCTSTR lpszFilePath
	static bool IsDriveRemovable(LPCTSTR lpszFilePath);

// Function name	: DirectoryExists
// Description	    : check if the given directory exists
// Return type		: static bool 
// Argument         : LPCTSTR lpszDir
	static bool DirectoryExists(LPCTSTR lpszDir);


// Function name	: FileExists
// Description	    : check if the given file or directory exists
// Return type		: static int 
//		return -1 if the given file is a directory, 1 if is a file
//		or 0 if there is no such a file
// Argument         : LPCTSTR lpszName
	static int FileExists(LPCTSTR lpszName);

// Function name	: ForceDirectory
// Description	    : create nested directories with a single command
// Return type		: static bool 
// Argument         : LPCTSTR lpDirectory
	static bool ForceDirectory(LPCTSTR lpDirectory);

// Function name	: GetFilePath
// Description	    : get the path of the given file
// Return type		: static CString 
// Argument         : LPCTSTR strFilePath
	static CString GetFilePath(LPCTSTR lpszFilePath);


// Function name	: GetFileExt
// Description	    : return the file extension
// Return type		: static CString 
// Argument         : LPCTSTR lpszFilePath
	static CString GetFileExt(LPCTSTR lpszFilePath);


// Function name	: GetFileName
// Description	    : return the name of the file (title + extension)
// Return type		: static CString 
// Argument         : LPCTSTR lpszFilePath
	static CString GetFileName(LPCTSTR lpszFilePath);

	// just a helper for a various purposes
	static const DWORD* GetCRCTable();
	// function for a VERY advanced use - you normally never need that
	CZipStorage* GetStorage(){return &m_storage;}
	
protected:
	void EmptyPtrList();
	void CryptDecodeBuffer(DWORD uCount);
	void CryptEncodeBuffer();
	void CryptEncode(char &c);
	void CryptCryptHeader(long iCrc, CZipAutoBuffer& buf);
	DWORD CryptCRC32(DWORD l, char c);
	void CryptDecode(char &c);
	char CryptDecryptByte();
	bool CryptCheck();
	void CryptUpdateKeys(char c);
	void CryptInitKeys();
	CZipAutoBuffer m_pszPassword;
	DWORD m_keys[3];

	static int CompareWords(const void *pArg1, const void *pArg2);
	bool IsDirectory(DWORD uAttr);
	void DeleteInternal(WORD uIndex);
	DWORD RemovePackedFile(DWORD uStartOffset, DWORD uEndOffset);
	CZipFileHeader* CurrentFile();
	void CheckForError(int iErr);
	CZipInternalInfo m_info;
	CZipStorage m_storage;
	CPtrList m_list;
	static void* myalloc(void* opaque, UINT items, UINT size);
	static void myfree(void* opaque, void* address);
	enum {extract = -1, nothing, compress};
	// 0 - no file inside archive opened
	// -1 - current opened for extract
	// 1 - new opened for compression
	char m_iFileOpened;
	void ThrowError(int err);
	CZipCentralDir m_centralDir;
	static TCHAR m_gszCopyright[];
};

#endif // !defined(AFX_ZIPARCHIVE_H__A7F528A6_1872_4071_BE66_D56CC2DDE0E6__INCLUDED_)

⌨️ 快捷键说明

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