📄 zipbuilder.h
字号:
/* TZipBuilder component v1.60 by Chris Vleghert
* a C++ Builder 1, 3, 4 , 5 and 6 wrapper for the freeware ZIP and UNZIP DLL's
* from Chris Vleghert and E.W. Engler.
* e-mail: englere@abraxis.com
* www: http://www.geocities.com/SiliconValley/Network/2114
* v1.73 by Roger Aelbrecht August 15, 2003.
* http://web.wanadoo.be/driehoeksw
*/
#ifndef ZipMainUnitH
#define ZipMainUnitH
//---------------------------------------------------------------------------
#include <vcl\Buttons.hpp>
// including ShellApi.hpp is not needed
// ZipBuilder.cpp includes vcl.h that includes vcl0.h that includes dialogs.hpp and there ShlObj.hpp
// is included that has include ShellApi.hpp in it
//#include <vcl\ShellApi.hpp> // for TSHFileOpStruct definition
#include "CallBack.h"
#include "UnzipDLL.h"
#include "ZipDLL.h"
#include "ZipStructs.h"
//#define DEBUGCALLBACK
// When we want to build without disk spanning then define NO_SPAN
//#define NO_SPAN
//When we want to build without the code supporting the stream functions define NO_STREAM
//#define NO_STREAM
//When we want to build without self-extracting code then define NO_SFX
//#define NO_SFX
// when we want to build with the old internal self-extracting code then define INTERNAL_SFX
#define INTERNAL_SFX
#ifdef INTERNAL_SFX
#include "BuildIntSfx.h"
#undef NO_SFX
#endif
//---------------------------------------------------------------------------
//----------------------BCB1, BCB3, BCB4 and BCB5 differences---------------
#if __BORLANDC__ < 1328 // BCB1=0x0520(1312)
# // BCB_1 doesn't know 'PACKAGE'
# define PACKAGE
namespace Sysutils
{
extern bool __fastcall DeleteFile( const System::AnsiString aStr );
}
# define PGBCONV unsigned short int
# define mrNoToAll (Byte)(9)
# // The old style Out of Memory exception.
# include <except.h>
# define MEMEXCEPT xalloc
#else // BCB3=0x0530(1328)
# define PGBCONV unsigned int
# // xalloc is obsolete and not used in BCB3.
# include <new.h>
# define MEMEXCEPT std::bad_alloc
#endif
#if __BORLANDC__ > 1343 // BCB4=0x540(1344), BCB5=0x550(1360)
typedef __int64 SeekInt;
#else
typedef int SeekInt;
#endif
// We need a forward declaration.
namespace ZipBuilder
{
class TZipBuilder;
}
#if __BORLANDC__ < 1344
#pragma option -a4
#else
#pragma option -a8
#endif
struct MDZipData { // MyDirZipData
unsigned short DiskStart; // The number of the disk on which this file begins.
unsigned long RelOffLocal; // This is the offset from the start of the first disk on.
unsigned short FileNameLen;
char *FileName; // The name of the file we have handled correctly.
unsigned long CRC32; // Used in the unzip code.
unsigned long ComprSize;
unsigned long UnComprSize;
unsigned long DateTime;
};
#pragma option -a.
// Definition for if the datadescriptor record is present.
#define DescUsed( DirRec ) (DirRec.Flag & 0x0008)
//---------------------------------------------------------------------------
namespace ZipBuilder
{
typedef long __stdcall (*GetSHFormatAddress)( HWND hwnd, long drive, long Fid, long Opt );
typedef BOOL __stdcall (*GDiskFreeSpaceEx)( char *RootName, __int64 *FreeForCaller, __int64 *TotNoOfBytes, __int64 *TotNoOfFreeBytes );
#pragma option -a1
struct ZipDirEntry { // Data from the Central header
unsigned char MadeByVersion;
unsigned char HostVersionNo;
Word Version;
Word Flag;
Word CompressionMethod;
long DateTime;
long CRC32;
long CompressedSize;
long UncompressedSize;
Word FileNameLength;
Word ExtraFieldLength;
unsigned short FileCommentLen;
unsigned short StartOnDisk;
unsigned short IntFileAttrib;
unsigned long ExtFileAttrib;
unsigned long RelOffLocalHdr;
String FileName;
String FileComment;
bool Encrypted; // New v1.6
String ExtraData; // New v1.6, used in CopyZippedFiles()
};
#pragma option -a.
#if __BORLANDC__ < 1344
#pragma option -a4
#else
#pragma option -a8
#endif
struct ZipRenameRec {
String Source;
String Dest;
unsigned long DateTime;
};
#pragma option -a.
#pragma option -b-
enum ProgressType { NewFile, ProgressUpdate, EndOfBatch, TotalFiles2Process,
TotalSize2Process, NewExtra, ExtraUpdate };
// 1.73 added AddForceDest
enum AddOptsEnum { AddDirNames, AddRecurseDirs, AddMove, AddFreshen, AddUpdate,AddZipTime,
AddForceDOS, AddHiddenFiles, AddArchiveOnly, AddResetArchive,
AddEncrypt, AddSeparateDirs, AddVolume, AddFromDate, AddSafe, AddForceDest,
AddDiskSpan, AddDiskSpanErase };
#pragma option -b.
typedef Set<AddOptsEnum, AddDirNames, AddDiskSpanErase> AddOpts;
// When changing this enum also change the pointer array in the function AddSuffix,
// and the initialisation of ZipBuilder. Also keep assGIF as first and assEXE as last value.
#pragma option -b-
enum AddStoreSuffix{ assGIF = 0, assPNG, assZ, assZIP, assZOO, assARC, assLZH, assARJ, assTAZ,
assTGZ, assLHA, assRAR, assACE, assCAB, assGZ, assGZIP, assJAR, assEXE};
#pragma option -b.
typedef Set< AddStoreSuffix, assGIF, assEXE> AddStoreExts;
#pragma option -b-
enum SpanOptsEnum { spNoVolumeName, spCompatName, spWipeFiles, spTryFormat };
#pragma option -b.
typedef Set<SpanOptsEnum, spNoVolumeName, spTryFormat> SpanOpts;
#pragma option -b-
// 1.73 added ExtrForceDirs
enum ExtrOptsEnum { ExtrDirNames, ExtrOverWrite, ExtrFreshen, ExtrUpdate, ExtrForceDirs, ExtrTest };
#pragma option -b.
typedef Set<ExtrOptsEnum, ExtrDirNames, ExtrTest> ExtrOpts;
#pragma option -b-
enum OvrOpts { OvrConfirm, OvrAlways, OvrNever };
enum SFXOptsEnum { SFXAskCmdLine, SFXAskFiles, SFXAutoRun, SFXHideOverWriteBox,
SFXCheckSize, SFXNoSuccessMsg };
#pragma option -b.
typedef Set<SFXOptsEnum, SFXAskCmdLine, SFXNoSuccessMsg> SfxOpts;
#pragma option -b-
enum CPOpts { cpAuto, cpNone, cpOEM };
enum CodePageDirection { cpdOEM2ISO, cpdISO2OEM };
enum DeleteOpts { htdFinal, htdAllowUndo };
enum UnZipSkipTypes { stOnFreshen, stNoOverwrite, stFileExists, stBadPassword, stNoEncryptionDLL,
stCompressionUnknown, stUnknownZipHost, stZipFileFormatWrong, stGeneralExtractError };
enum ZipDiskStatusEnum { zdsEmpty, zdsHasFiles, zdsPreviousDisk, zdsSameFileName, zdsNotEnoughSpace };
#pragma option -b.
typedef Set<ZipDiskStatusEnum, zdsEmpty, zdsNotEnoughSpace> TZipDiskStatus;
#pragma option -b-
enum TZipDiskAction { zdaOk, zdaErase, zdaReject, zdaCancel };
#pragma option -b.
#pragma option -b-
enum TPasswordButton { pwbOk, pwbCancel, pwbCancelAll, pwbAbort };
#pragma option -b.
typedef Set<TPasswordButton, pwbOk, pwbAbort> TPasswordButtons;
typedef void __fastcall (__closure *TProgressEvent)( System::TObject *Sender, ProgressType ProgrType, String FileName, unsigned FileSize );
typedef void __fastcall (__closure *TMsgEvent)( System::TObject *Sender, int ErrCode, String Message );
typedef void __fastcall (__closure *TSetNewNameEvent)( System::TObject *Sender, String &OldFileName, bool &IsChanged );
typedef void __fastcall (__closure *TNewNameEvent)( System::TObject *Sender, int SeqNo, ZipDirEntry &ZipEntry );
typedef void __fastcall (__closure *TPasswordErrorEvent)( System::TObject *Sender, bool IsZipAction, String &NewPassword, String ForFile, unsigned &RepeatCount, TPasswordButton &Action );
typedef void __fastcall (__closure *TCRC32ErrorEvent)( System::TObject *Sender, String ForFile, unsigned FoundCRC, unsigned ExpectedCRC, bool &DoExtract );
typedef void __fastcall (__closure *TExtractOverwriteEvent)( System::TObject *Sender, String ForFile, bool IsOlder, bool &DoOverwrite, int DirIndex );
typedef void __fastcall (__closure *TExtractSkippedEvent)( System::TObject *Sender, String ForFile, UnZipSkipTypes SkipType, int ExtError );
typedef void __fastcall (__closure *TCopyZipOverwriteEvent)( System::TObject *Sender, String ForFile, bool &DoOverwrite );
typedef void __fastcall (__closure *TGetNextDiskEvent)( System::TObject *Sender, int DiskSeqNo, int DiskTotal, String Drive, bool &Cancel );
typedef void __fastcall (__closure *TStatusDiskEvent)( System::TObject *Sender, int PreviousDisk, String PreviousFile, TZipDiskStatus Status, TZipDiskAction &Action );
typedef void __fastcall (__closure *TFileCommentEvent)( System::TObject *Sender, String ForFile, String &FileComment, bool &IsChanged );
typedef void __fastcall (__closure *TTickerEvent)(TObject *Sender); //new in 1.72
typedef void __fastcall (__closure *TAfterCallBackEvent)(TObject *Sender, bool& DoStop);
typedef void __fastcall (__closure *TFileExtraEvent)(TObject *Sender,String ForFile, String& Data, bool &IsChanged); // changed 1.73
typedef void __fastcall (__closure *TItemProgressEvent)(TObject *Sender, String Item, unsigned FileSize, int PerCent); //new in 1.73
typedef void __fastcall (__closure *TTotalProgressEvent)(TObject *Sender, unsigned TotalSize, int PerCent); // new 1.73
typedef void __fastcall (__closure *TZipStrEvent)(TObject *Sender, int ID, AnsiString& Str); // new 1.73
#if __BORLANDC__ < 1344
#pragma option -a4
#else
#pragma option -a8
#endif
class PACKAGE TPasswordDlg : public TForm {
private:
TBitBtn *PwBtn[4];
TEdit *PwdEdit;
TLabel *PwdTxt;
public:
__fastcall TPasswordDlg( TComponent *Owner, int Dummy, TPasswordButtons pwb );
__fastcall virtual ~TPasswordDlg( void );
// And just to keep BCB1 happy...
__fastcall virtual TPasswordDlg( TComponent *Owner ) : TForm( Owner ) { }
virtual String __fastcall ShowModalPwdDlg( String Caption, String MsgTxt );
};
// 1.73 10 July 2003 RP changed to allow later translations
class PACKAGE EZipBuilder : public Sysutils::Exception {
public:
bool FDisplayMsg; // We do not always want to see a message after an exception.
int FResIdent; // We also save the Resource ID in case ZipMsg is not linked in the application.
AnsiString Arg1, Arg2; // save arguments for translation
// Exception.Create
__fastcall EZipBuilder( const int Ident, bool Display = true );
__fastcall EZipBuilder( const int Ident, const int DiskNo );
__fastcall EZipBuilder( const int Ident, const String Drive );
__fastcall EZipBuilder( const int Ident, const String File1, const String File2 );
// TObject.Destroy
inline __fastcall virtual ~EZipBuilder( void ) { }
};
// new 1.73 handling of abort exceptions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -