Multi-file merger and decomposition (reproduced)

xiaoxiao2021-03-06  123

Combined with the decomposition of multi-file: Lee kg Inquiry

Source code download This program example how to merge multiple files into a file and can be self-decomposed. This technology is useful when making installations. I learned this technology at this website and organize him to integrate files and directories. The core program includes a consolidated file class CCOMBINEFILES, a class CEXTRACTFILES and a data class fileInfo file and directory representing a file or directory information are represented by the fileInfo class. Such definitions are as follows:

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

}

The merged file class CCOMBINEFILES is defined as follows:

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

& fix, file * fp, uint nstartoffset;

Bool Combinefile (CSTRING SZFILENAME, FILE * FP);

Bool Combinedirectory (CString Szdir, File * FP);

CString M_SZEXEFILENAME;

}

The WriteFileInfo function is responsible for writing information about the file or directory; WriteString is responsible for writing a string, the string structure is "length character list"; the WriteListinfo function is responsible for writing a list of files to be merged, he multiple calls writefileinfo to complete Combinefile is responsible for writing file data; CombineFile is responsible for writing all data for a directory, calling CombineFile and WriteListInfo to write a list of files in the file data and directory. The Combine function is a function for external calls, which combines the files and directories in the filelist to SZTOFileName. The algorithm of the merged file is that the data of each file is placed in the beginning of the merged file, and the merged file list is stored at the end of the merged file; after merge with this directory as a separate file processing, only need In the file information, this file is indicated to generate a directory after decomposition, and then its data is a merged file; Decomposition file class CEXTRACTFILES is defined as follows:

Class CextractFiles

{

PUBLIC:

Bool Extractfiles (Carray

& fixist, 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

& fix, file * fp, uint & nstartoffset;

Bool ReadfileList (Carray

& fixInfo dir);

Carray

m_filelist; cstring m_filename;

Corresponding to the merged file class CCOMBINEFILES, the merge function in the merge has a read function when it is decomposed. Not much here. Example: File lists include F1, F2, F3 three files and directories D, and there are two files F4, F5 in the directory D. Set the merger file named Combine. The merge process is as follows: First, the F4 and F5 in the directory D are merged, and the two data is written to Combine; then write the F4 and F5 file information to Combine; then write the file data of F1, F2, F3 to Combine Finally, the file information of the files F1, F2, F3, and directory D is written to Combine. Shimer and and complete. When the decomposition reads the file information, read the file data according to the file information, and writes the decomposed file. To merge the self-decomposition file, simply set the extension of the merged file to EXE, and specify the 205 lines in the Testbpdlg.cpp file to the path you compile BP.exe. E.g:

Szexename = "g: //com//testement//testbp//bp.exe";

For details, please refer to the source code.

转载请注明原文地址:https://www.9cbs.com/read-126515.html

New Post(0)