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

📄 zip.cpp

📁 所有压缩格式的压缩解压缩。
💻 CPP
字号:
// Zip.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "Zip.h"
#include "../public/codecfunc.h"
#include "mfc_zip/ziparchive.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//
//	Note!
//
//		If this DLL is dynamically linked against the MFC
//		DLLs, any functions exported from this DLL which
//		call into MFC must have the AFX_MANAGE_STATE macro
//		added at the very beginning of the function.
//
//		For example:
//
//		extern "C" BOOL PASCAL EXPORT ExportedFunction()
//		{
//			AFX_MANAGE_STATE(AfxGetStaticModuleState());
//			// normal function body here
//		}
//
//		It is very important that this macro appear in each
//		function, prior to any calls into MFC.  This means that
//		it must appear as the first statement within the 
//		function, even before any object variable declarations
//		as their constructors may generate calls into the MFC
//		DLL.
//
//		Please see MFC Technical Notes 33 and 58 for additional
//		details.
//

/////////////////////////////////////////////////////////////////////////////
// CZipApp

BEGIN_MESSAGE_MAP(CZipApp, CWinApp)
	//{{AFX_MSG_MAP(CZipApp)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZipApp construction

CZipApp::CZipApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CZipApp object

CZipApp theApp;

/////////////////////////////////////////////////////////////////////////////
//以下三个是接口函数
void GetDllInfo(LPCODECLIBINFO pcdi)
{
	lstrcpy(pcdi->szLibName,"Zip格式压缩/解压缩库");
	lstrcpy(pcdi->szFileType,"Zip 压缩包");
	lstrcpy(pcdi->szFileFilter,"*.zip;*.gz");	//多个扩展名一定要用分号隔开
	pcdi->dwVersion=CDL_CUR_VERSION_NUMBER|0x10000;	//本库版本号:0.1.0.0
	lstrcpy(pcdi->szAuthor,"秦丰林");
	lstrcpy(pcdi->szEmail,"Qinfenglin@chinaren.com");
}
void GetFunctionInfo(LPFUNCTIONINFO pfi)
{
	pfi->lpfnCreate=Create;
	pfi->lpfnRelease=Release;
	pfi->lpfnGetNoEntries=GetNoEntries;
	pfi->lpfnGetFileInfo=GetFileInfo;
	pfi->lpfnAddNewFile=AddNewFile;
	pfi->lpfnExtractFile=ExtractFile;
	pfi->lpfnDeleteFiles=DeleteFiles;
	pfi->lpfnTestFile=NULL;		//不支持
	pfi->lpfnSetFileName=SetFileName;
	pfi->lpfnSetPassword=NULL;	//不支持
	pfi->lpfnGetComment=GetComment;
	pfi->lpfnSetComment=SetComment;
}
void CDLAboutBox()
{
	MessageBox(NULL,"\n\tZip 格式压缩/解压缩库 Version 1.0\t\t\n\n"
				"\tCopyright(C) 2002-2002\n\tIvy Software  秦丰林\n\n",
				"关于 Zip CDL",MB_OK);
}
////////////////////////////////////////////////////////////////////
//以下为压缩/解压缩处理函数
HCXFILE Create(LPCTSTR szPathName,int iMode)
{
	CZipArchive *pZip=new CZipArchive;

	pZip->Open(szPathName,iMode);
	if (pZip->GetSpanMode())
	{
		delete pZip;
		pZip=NULL;
	}
	return (HCXFILE)pZip;
}
int  GetNoEntries(HCXFILE hFile)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	return pZip->GetNoEntries();
}
BOOL GetFileInfo(HCXFILE hFile,LPFILEINFO lpfi,int nIndex)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	CFileHeader fh;
	if (!pZip->GetFileInfo(fh,nIndex)) return FALSE;

	lstrcpy(lpfi->szFileName,fh.m_szFileName);
	lpfi->dwFileSize=fh.m_uUncomprSize;
	lpfi->dwPackedSize=fh.m_uComprSize;
	lpfi->dwDateTime=(fh.m_uModDate<<16)|fh.m_uModTime;
	lpfi->bIsDirectory=pZip->IsFileDirectory(nIndex);
	lpfi->bEncrypted=FALSE;		//暂不支持
	lpfi->dwFileAttr=fh.m_uExternalAttr;
	lpfi->dwCRC32=fh.m_uCrc32;

	return TRUE;
}
///////////////////////////////////////////////////////////////////
// 若lpszPos==NULL使用绝对路径
// 否则lpszPos是文件的存储位置
BOOL AddNewFile(HCXFILE hFile,LPCTSTR lpszFileName,LPCTSTR lpszPos,int iLevel)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	if (lpszPos)
	{
		AfxMessageBox("该库只支持绝对路径的压缩");
		return FALSE;
	}

	return pZip->AddNewFile(lpszFileName,iLevel);
}
BOOL ExtractFile(HCXFILE hFile,int nIndex,LPCTSTR lpszPath)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	return pZip->ExtractFile(nIndex,lpszPath);
}
BOOL DeleteFiles(HCXFILE hFile,int *indexes)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	if (indexes[0]==-1)
		return FALSE;
	else if (indexes[1]==-1)
		return pZip->DeleteFile(indexes[0]);
	else
	{
		CWordArray ar;
		int i=0;
		while (indexes[i]!=-1) ar.Add(indexes[i++]);
		pZip->DeleteFiles(ar);

		return TRUE;
	}
}
void Release(HCXFILE hFile)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	if (!pZip->IsClosed())	pZip->Close();

	delete pZip;
}
BOOL SetFileName(HCXFILE hFile,int nIndex,LPCTSTR lpszFileName)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	AfxMessageBox("不能改名");

	return FALSE;
}
/////////////////////////////////////////////////////////////
// nIndex==-1 表示取全局描述
BOOL GetComment(HCXFILE hFile,int nIndex,char *buf,int size)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	CString comment;
	CFileHeader fh;
	if (nIndex<0)
		comment=pZip->GetGlobalComment();
	else
	{
		pZip->GetFileInfo(fh,nIndex);
		comment=fh.m_szComment;
	}
	memcpy(buf,(LPCTSTR)comment,size);
	buf[size-1]=0;

	return !comment.IsEmpty();
}
BOOL SetComment(HCXFILE hFile,int nIndex,LPCTSTR lpszComment)
{
	CZipArchive *pZip=(CZipArchive*)hFile;

	CFileHeader fh;
	BOOL b=TRUE;
	if (nIndex<0)
		b=pZip->SetGlobalComment(CString(lpszComment));
	else
	{
		pZip->GetFileInfo(fh,nIndex);
		fh.m_szComment=lpszComment;
	}
	return b;
}

⌨️ 快捷键说明

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