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

📄 ziparchive.h

📁 文件压缩/解压动态链接库
💻 H
📖 第 1 页 / 共 2 页
字号:

#if !defined(AFX_ZIPARCHIVE_H__A7F528A6_1872_4071_BE66_D56CC2DDE0E6__INCLUDED_)
#define AFX_ZIPARCHIVE_H__A7F528A6_1872_4071_BE66_D56CC2DDE0E6__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ZipStorage.h"	// Added by ClassView
#include "ZipException.h"
#include "ZipCentralDir.h"	// Added by ClassView
#include "ZipInternalInfo.h"	// Added by ClassView


//////////////////////////////////////////////////////////////////////////
/////////////////////  CZipArchive   /////////////////////////////////////

class CZipArchive  
{
public:
	static int SingleToWide(CZipAutoBuffer &szSingle, CString& szWide);
	static int WideToSingle(LPCTSTR lpWide, CZipAutoBuffer &szSingle);

// Function name	: TestFile
// Description	    : Test the file with the given index
//		the function throws CException*, but performs all the necessary cleanup
//		before, so that the next file can be tested after catchig the exception
//		and examining it for the reason of error.
// Return type		: bool 
//		return false if the incorrect action has been taken by 
//		the user or the programmer (it is when OpenFile(WORD nIndex) or 
//		GetFileInfo(CZipFileHeader & fhInfo, WORD uIndex) return false or uBufSize
//		is 0
// Argument         : WORD uIndex
//		index of the file to test
// 	Argument         : ZIPCALLBACKFUN pCallback = NULL
//		See the description at AddNewFile
// 	Argument         : void* pUserData = NULL
// Argument         : DWORD uBufSize = 65535
//		the size of the buffer used during extraction
	bool TestFile(WORD uIndex, ZIPCALLBACKFUN pCallback = NULL, void* pUserData = NULL, DWORD uBufSize = 65535);

// Function name	: CloseFileAfterTestFailed
// Description	    : Perform the necessary cleanup after the exception 
//		while testing the archive so that next files in the archive can be tested
// Return type		: void 
	void CloseFileAfterTestFailed();


// Function name	: SetPassword
// Description	    : set the password for the file that is going to be opened or created
//						use this function BEFORE opening or adding a file					
// Return type		: bool 
//						return false if the password contains ASCII characters
//						with values 128 or higher or the file inside archive is
//						opened		
// Argument         : LPCTSTR lpszPassword = NULL
//						set it to NULL to clear password
	bool SetPassword(LPCTSTR lpszPassword = NULL);

// Function name	: SetAdvanced
// Description	    :  set advanced options
// Return type		: void 
// Argument         : int iWriteBuffer = 65535
//		buffer used during write operation to the disk, the bigger, the better;
//		it is pointless, however, to set it bigger than the size of the volume;
//		the optimal size is the size of the volume
// Argument         : int iExtractBuffer = 16384
//		set the size of the buffer used in extracting and compressing files
//		default 16384, must not be < 1024
//		set it before opening the archive
// Argument         : int iSearchBuffer = 32768
//		set the size of the buffer used in searching for the central dir
//		useful with big archives, default 32768, must not be < 1024
	void SetAdvanced(int iWriteBuffer = 65535, int iExtractBuffer = 16384, int iSearchBuffer = 32768);

// Function name	: SetSpanCallback
// Description	    : set callback function used during operations on a
//		pkzip compatible disk spanning archive to change disks; 
//		set it usualy before opening the archive for reading
// Return type		: void 
// Argument         : ZIPCALLBACKFUN pFunc
//		for the description of callback function see CZipStorage.h
// Argument         : void* pData
//		user data to be passed to the callback function as the last parameter
	void SetSpanCallback(ZIPCALLBACKFUN pFunc, void* pData = NULL);

//	archive open modes	
	enum {open, openReadOnly, create, createSpan};

//		Disk spanning archive modes:
//		pkzip compatible mode (pkSpan):
//			- only on removeble devices
//			- autodetect the size of the volume
//			- write a label to the disk
//			- there is a need to set the span callback function
//		TD mode (tdSpan):
//			- may be created on non removable devices
//			- uses user-defined volume size
//			- no need to set the span callback function

// Function name	: Open
// Description	    : Open a zip archive
// Return type		: void
// Argument         : LPCTSTR szPathName
//		Path to the archive
// Argument         : int iMode= CZipArchive::open;
//		open mode flags:
//		open			open an existing archive
//		openReadOnly	open an existing archive as read only file 
//			(this mode is intended to use in self extract code)
//			if you try to add or delete a file in this mode, an exception will be thrown
//		create			create a new archive
//		createSpan		create a disk spanning archive
// Argument         : int iVolumeSize = 0
//		if iMode == createSpan and iVolumeSize <= 0 then create disk spanning 
//			archive in pkzip mode
//		if iMode == createSpan and iVolumeSize > 0 then create disk spanning 
//			archive in TD mode
//		if iMode == open and the exisitng archive is a spanned archive
//			the pkSpan mode is assumed if the archive is on a removable device
//			or tdSpan otherwise;
//			if you want to open tdSpan archive on a removable device, set iVolumeSize
//			to a value different from 0	
//		if iMode == create this argument doesn't matter
	void Open(LPCTSTR szPathName, int iMode = open, int iVolumeSize = 0);

// Function name	: Open
// Description	    : Open or create an archive in CMemFile
// Return type		: void 
// Argument         : CMemFile& mf
// Argument         : int iMode = open
//		the following modes are valid:  open, openReadOnly, create
	void Open(CMemFile& mf, int iMode = open);


// Function name	: AddNewFile
// Description	    : add quickly a new file to the archive
// Return type		: bool 
// Argument         : LPCTSTR lpszFilePath
//		file to be added
// Argument         : int iLevel = Z_DEFAULT_COMPRESSION
//		the compression level (see OpenNewFile() for detailed desciption)
// Argument			: bool bFullPath
//		if true, include full path of the file inside the archive	
// 	Argument         : ZIPCALLBACKFUN pCallback = NULL
// callback function (may be NULL)
// 	To set the callback function for this operation pass its pointer as the 
// 	argument (do not use SetSpanCallback for it - its for different purposes).
// 	The callback function, if set, is called after reading and writing one portion of data.
// 	- the first argument (DWORD):
// 			total number of bytes to read (the size of the file)
// 	- the second one (int) :
// 			total number bytes already read
// 	- the third argument (void*): 
// 		pUserData argument passed to #AddNewFile
// 	Argument         : void* pUserData = NULL
// 		user - defined data passed on to the callback function
// 		(doesn't matter if there is no callback function defined)
// Argument         : DWORD nBufSize = 65535
//		the size of the buffer used during compression

/*
*/
	bool AddNewFile(LPCTSTR lpszFilePath, int iLevel = -1, bool bFullPath = true, ZIPCALLBACKFUN pCallback = NULL, void* pUserData = NULL, unsigned long nBufSize = 65535);

// Function name	: OpenNewFile
// Description	    : add a new file to the zip archive
// Return type		: bool 
//		return false in the following cases:
//		- the lpszFilePath is not NULL and the file	attributes and data was not correctly retreived
//		- a file is already opened for extraction or compression
//		- archive is an existing disk span archive
//		- maximum file count inside archive reached (65535)
// Argument         : CZipFileHeader & header
//		structure that have addtional information; the following fields are valid:
//			- m_uMethod - file compression method; can be 0 (storing) or Z_DEFLATE (deflating)
//				otherwise Z_DEFLATE is assumed
//			- m_uModDate, m_uModTime - use SetTime method of CFileHeadeer to set them
//				if lpszFilePath is not NULL this fields are updated automaticaly
//			- m_uExternalAttr - attributes of the file
//				if lpszFilePath is not NULL this field is updated automaticaly
//			- m_szFileName - file name (may be with path) to be stored inside archive
//				to represent this file
//			- m_szComment - file comment
//			- m_pExtraField - LOCAL extra field, use SetExtraField() after opening 
//				a new file, but before closing it to set the extra field 
//				in the header in the central directory
//		other fields are ignored - they are updated automaticaly
// Argument         : int iLevel = Z_DEFAULT_COMPRESSION
//		the level of compression (-1, 0 - 9); named values:
//		Z_DEFAULT_COMPRESSION	: -1
//		Z_NO_COMPRESSION		: 0
//		Z_BEST_SPEED			: 1
//		Z_BEST_COMPRESSION		: 9
// Argument         : LPCTSTR lpszFilePath = NULL
//		the path to the file to retreive date and attributes from
	bool OpenNewFile(CZipFileHeader & header, int iLevel = Z_DEFAULT_COMPRESSION, LPCTSTR lpszFilePath = NULL);

// Function name	: WriteNewFile
// Description	    : compress the contents of the buffer and write it to a new file
// Return type		: bool 
//		return false if the new file hasn't been opened
// Argument         : void *pBuf
//		buffer containing the data to be compressed and written
// Argument         : DWORD iSize
//		the size of the buffer
	bool WriteNewFile(void *pBuf, DWORD iSize);

// Function name	: SetExtraField
// Description	    : set the extra field in the file header in the central directory
//		must be used after opening a new file in the archive, but before closing it
// Return type		: void 
// Argument         : char *pBuf
//		bufer with the data to be copied
// Argument         : DWORD iSize
//		size of the buffer
	void SetExtraField(char *pBuf, WORD iSize);

// Function name	: CloseNewFile
// Description	    : close the new file in the archive
// Return type		: bool 
//		return false if no new file is opened
// Argument         : bool bAfterException  = false
//		set it to true if you want to reuse CZipArchive after is has thrown an exception
	bool CloseNewFile();

// Function name	: ExtractFile
// Description	    : fast extracting
// Return type		: bool 
// 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

⌨️ 快捷键说明

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