分类: C/C++
2008-03-18 13:39:26
class FileInfo { public: const FileInfo &operator = (const FileInfo &fi); FileInfo(CString szFileName, UINT nFileSize, UINT nPos, char type = 0); FileInfo(); virtual ~FileInfo(); public: CString szFileName; UINT nSize; UINT nPos; char type; // d --- directory , f --- file , other --- no define };合并文件类CCombineFiles定义如下:
class CCombineFiles { public: bool Combine(CStringArray &fileList, CString szToFileName); CCombineFiles(CString szExeFileName); virtual ~CCombineFiles(); public: bool WriteFileInfo(FileInfo fi, FILE *fp); bool WriteString(CString szStr, FILE *fp); bool WriteListInfo(CArray其中WriteFileInfo函数负责写入文件或目录的信息; WriteString负责写入一个字符串,字符串结构是“长度+字符列表"; WriteListInfo函数负责写入要合并的文件列表信息,他多次调用WriteFileInfo来完成; CombineFile负责写入文件数据; CombineFile负责写入一个目录的所有数据,它调用CombineFile和WriteListInfo来写入文件数据和目录中的文件列表信息。&fiList, FILE *fp, UINT nStartOffset); bool CombineFile(CString szFileName, FILE *fp); bool CombineDirectory(CString szDir, FILE *fp); CString m_szExeFileName; };
class CExtractFiles { public: bool ExtractFiles(CArray与合并文件类CCombineFiles一一对应,在合并中的合并函数对应都有其分解时的读取函数。这里就不多说了。&fiList, CString szPath); bool ReadFileList(CArray &fileList); CExtractFiles(CString filename); virtual ~CExtractFiles(); public: bool ExtractDirectory(FileInfo fi, CString szPath, FILE *fp); bool ExtractFile(FileInfo fi, CString szPath, FILE *fp); bool ReadString(CString &szStr, FILE *fp); bool ReadFileInfo(FileInfo &fi, FILE *fp); bool ReadListInfo(CArray &fiList, FILE *fp, UINT &nStartOffset); bool ReadFileList(CArray &fiList, FileInfo dir); CArray m_fileList; CString m_filename; };
szExeName = "G:\\COM\\TestEvent\\TestBp\\bp.exe";详细情况请参阅源代码。