home *** CD-ROM | disk | FTP | other *** search
- /*===========================================================================*/
- /* Getting Started sample using The Xceed Zip Compression Library 4 */
- /* For C++Builder 4 */
- /* Copyright (c) 1999 Xceed Software Inc. */
- /*===========================================================================*/
-
- #include <vcl.h>
- #pragma hdrstop
-
- #include "Main.h"
-
- #pragma package(smart_init)
- #pragma link "XceedZipLib_OCX"
- #pragma resource "*.dfm"
-
- TfrmMain *frmMain;
-
- ////////////////////////////////////////////////////////////////////////////////
- // Property hints
-
- const char szBasePathHint[] =
- "BasePath property:\n"
- " This path determines where entries in the FilesToProcess and FilesToExclude\n"
- " properties are relative to. The base path never appears in the zip file, even if\n"
- " PreservePaths = True. Only the portion of the path and filename specified in\n"
- " the FilesToProcess property is actually stored in the zip file. Therefore,\n"
- " BasePath helps you control what portions of paths are stored in the zip file.\n"
- " (The BasePath property is irrelevant when you are using absolute paths)";
-
- const char szFilesToProcessHint[] =
- "FilesToProcess property:\n"
- " Multiline string that contains all the filenames and/or file masks to be\n"
- " processed (zipped, unzipped, etc). If you entered a path in the\n"
- " BasePath property, all entries with relative paths will be relative to\n"
- " the specified base path. The pipe character can be used instead of\n"
- " the linefeed to separate entries for the FilesToProcess property.";
-
- const char szFilesToExcludeHint[] =
- "FilesToExclude property:\n"
- " Multiline string that contains all filenames and/or file masks to exclude\n"
- " from the files to be processed by the FilesToProcess property. These\n"
- " entries are also relative to the path specified in the BasePath property\n"
- " if its not empty.";
-
- const char szProcessSubfoldersHint[] =
- "ProcessSubfolders property:\n"
- " If set to True, the contents of all encoutered subfolders will be processed.";
-
- const char szZipFilenameHint[] =
- "ZipFilename property:\n"
- " The filename of the zip file to work with. When unzipping, this file must\n"
- " exist. When zipping, if the file exists, it's updated. Otherwise, it is\n"
- " created. You must enter an absolute path for this property. The\n"
- " BasePath property does not interfere with the ZipFilename property.";
-
- const char szPreservePathsHint[] =
- "PreservePaths property:\n"
- " If set to True, the zip file will store both the path and the filename of\n"
- " each file that is being zipped. As usual, the portion of a file's path\n"
- " that is specified in the BasePath property will not be stored in the\n"
- " zip file. When PreservePaths is set to False, only filenames (no\n"
- " paths) are stored.";
-
- const char szUseTempFileHint[] =
- "UseTempFile property:\n"
- " If set to true, all zipping operations will be performed on a temp file\n"
- " located in the folder specified in the TempFolder property.\n"
- " Otherwise, the operation is performed directly on the zip file\n"
- " without using a temp file. You cannot remove files from an existing\n"
- " zip file, or update files already in an existing zip files without setting\n"
- " this property to True.";
-
- const char szTempFolderHint[] =
- "TempFolder property:\n"
- " Location of the temp file when the UseTempFile property is set to True.\n"
- " When you leave this property empty, the Windows default temp\n"
- " directory is used.";
-
- const char szRequiredFileAttributesHint[] =
- "RequiredFileAttributes property:\n"
- " Bit-field value that specifies all attributes that a file must have in\n"
- " order to be included in the process.";
-
- const char szExcludedFileAttributesHint[] =
- "ExcludedFileAttributes property:\n"
- " Bit-field value that specifies all attributes that a file must NOT have\n"
- " in order to be included in the process.";
-
- const char szMinDateToProcessHint[] =
- "MinDateToProcess property:\n"
- " Minimum value of a file's 'Last modifed date' required in order to be\n"
- " included in the process.";
-
- const char szMaxDateToProcessHint[] =
- "MaxDateToProcess property:\n"
- " Maximum value of a file's 'Last modifed date' required in order to be\n"
- " included in the process.";
-
- const char szMinSizeToProcessHint[] =
- "MinSizeToProcess property:\n"
- " Minimum file size that a file must have in order to be included in the process.";
-
- const char szMaxSizeToProcessHint[] =
- "MaxSizeToProcess property:\n"
- " Maximum file size that a file must have in order to be included in the process.";
-
- const char szUnzipToFolderHint[] =
- "UnzipToFolder property:\n"
- " Destination folder for files being unzipped. In this sample, the PreservePaths\n"
- " property is set to True, so if files are stored in the zip file with paths, those\n"
- " stored paths will be recreated inside the destination folder specified by the\n"
- " UnzipToFolder property.";
-
- const char szSkipIfExistingHint[] =
- "SkipIfExisting property:\n"
- " If the destination file (located in a zip file that is being updated, or\n"
- " on disk when a zip file is being unzipped) already exists, and this\n"
- " property is set to True, then the file won't be overwritten. This has\n"
- " the effect of only processing files that don't exist in the destination\n"
- " zip file or unzipping folder.";
-
- const char szSkipIfNotExistingHint[] =
- "SkipIfNotExisting property:\n"
- " Setting this property to True will cause only files that don't already\n"
- " exist in the destination unzipping location (when unzipping) or the\n"
- " zip file (when zipping) to be skipped.";
-
- const char szSkipIfOlderDateHint[] =
- "SkipIfOlderDate property:\n"
- " When updating a file (in a zip while zipping, or on disk while unzipping),\n"
- " the file is skipped if the existing file's 'Last modified date' is greater than\n"
- " the file being zipped or unzipped.";
-
- const char szSkipIfOlderVersionHint[] =
- "SkipIfOlderVersion property:\n"
- " When updating a file (in a zip while zipping, or on disk while unzipping),\n"
- " the file is skipped if the existing file's version resource value is greater\n"
- " than the file being zipped or unzipped.";
-
- const char szZipFilenameSfxHint[] =
- "ZipFilename property with Sfx:\n"
- " The filename of the zip file to work on. When creating or updating\n"
- " self-extracting zip files, you should enter an executable filename\n"
- " (use a .EXE extension).";
-
- const char szSfxBinaryModuleHint[] =
- "SfxBinaryModule property:\n"
- " This binary file will be prepended to the zip file, with configuration\n"
- " data if the binary is one of the Xceed Self-Extractor Module\n"
- " binaries. If you leave this field empty, a regular (non-sfx) zip file\n"
- " will be created.";
-
- const char szSfxStringsHint[] =
- "SfxStrings property array:\n"
- " This array contains all the strings displayed by the Xceed Self-Extractor\n"
- " Module binaries. For example, the 'xssTitle' index contains the title\n"
- " displayed by all dialog boxes.";
-
- const char szSfxMessagesHint[] =
- "SfxMessages property array:\n"
- " This array contains all messages displayed by the Xceed Self-Extractor Module\n"
- " binaries. These messages often appear in their own dialog boxes. If a particular\n"
- " message is left empty, the dialog box won't be displayed. As an example,\n"
- " leaving this field empty will avoid displaying an introduction message dialog.";
-
- ////////////////////////////////////////////////////////////////////////////////
- // Method hints
-
- const char szPreviewFilesHint[] =
- "PreviewFiles method:\n"
- " Lets you scan the disk for files that would be zipped with the current property\n"
- " settings. A PreviewingFile event is triggered for each file that matches an\n"
- " entry in the FilesToProcess property. Set this method's parameter to True to\n"
- " have the library calculate the compressed size of the previewed files.";
-
- const char szListZipContentsHint[] =
- "ListZipContents method:\n"
- " Lets you view the zip file's contents. Due to the fact that the FilesToProcess\n"
- " property and the other filtering properties affect the ListZipContents method,\n"
- " you can use it to preview which files would be unzipped by the Unzip method\n"
- " if it were called with the current property settings. A ListingFile event is\n"
- " triggered for each file in the zip file that is listed.";
-
- const char szZipHint[] =
- "Zip method:\n"
- " Lets you zip files. Only files that match all the entries in the FilesToProcess\n"
- " and filtering properties will be processed. For each file that matches the\n"
- " FilesToProcess property, the ZipPreprocessingFile event is triggered. That\n"
- " event provides you with the chance to change the inclusion state of a file,\n"
- " or to change its information before it is stored in the zip file.";
-
- const char szUnzipHint[] =
- "Unzip method:\n"
- " Lets you unzip files. Only files that match all the entries in the FilesToProcess\n"
- " and filtering properties will be processed. For each file that matches the\n"
- " FilesToProcess property, the UnzipPreprocessingFile event is triggered. That\n"
- " event provides you with the chance to change the inclusion state of a file, or\n"
- " to change its information before it is written to the destination unzipping folder.";
-
- const char szZipSfxHint[] =
- "Zip method with Sfx:\n"
- " It's just like creating a regular (non-sfx) zip file, but if you enter a value\n"
- " for the SfxBinaryModule property, the binary (or any file for that matter)\n"
- " is prepended to the zip file. The zip file is now self-extracting because\n"
- " the binary knows how to unzip the rest of the data after itself.\n"
- " Furthermore, if the library recognises an Xceed binary, it will add\n"
- " config data to the binary so that the self-extracting zip file can display\n"
- " intro messages and have custom behavior.";
-
- //
- // Constructor
- //
-
- __fastcall TfrmMain::TfrmMain( TComponent* Owner )
- : TForm(Owner)
- {
- // We update hints for better look.
- // We cannot put linefeeds in property editor!
- UpdateFieldHints();
-
- // We fill attribute lists
- FillAttributeList( lstPRequiredFileAttributes );
- FillAttributeList( lstPExcludedFileAttributes );
-
- // We set their initial state
- SetSelectedAttributes( lstPRequiredFileAttributes,
- xZip->RequiredFileAttributes );
- SetSelectedAttributes( lstPExcludedFileAttributes,
- xZip->ExcludedFileAttributes );
- }
-
- //
- // Utility methods
- //
-
- void TfrmMain::UpdateFieldHints( void )
- {
- // Previewing tab
- edtPFilesToProcess->Hint = szFilesToProcessHint;
- edtPFilesToExclude->Hint = szFilesToExcludeHint;
- chkPProcessSubfolders->Hint = szProcessSubfoldersHint;
- lstPRequiredFileAttributes->Hint = szRequiredFileAttributesHint;
- lstPExcludedFileAttributes->Hint = szExcludedFileAttributesHint;
- btPreviewFiles->Hint = szPreviewFilesHint;
-
- // Zipping tab
- edtZZipFilename->Hint = szZipFilenameHint;
- edtZBasePath->Hint = szBasePathHint;
- edtZFilesToProcess->Hint = szFilesToProcessHint;
- edtZFilesToExclude->Hint = szFilesToExcludeHint;
- chkZProcessSubfolders->Hint = szProcessSubfoldersHint;
- chkZPreservePaths->Hint = szPreservePathsHint;
- chkZUseTempFile->Hint = szUseTempFileHint;
- edtZTempFolder->Hint = szTempFolderHint;
- btZip->Hint = szZipHint;
-
- // Listing tab
- edtLZipFilename->Hint = szZipFilenameHint;
- dtLMinDateToProcess->Hint = szMinDateToProcessHint;
- dtLMaxDateToProcess->Hint = szMaxDateToProcessHint;
- edtLMinSizeToProcess->Hint = szMinSizeToProcessHint;
- edtLMaxSizeToProcess->Hint = szMaxSizeToProcessHint;
- btList->Hint = szListZipContentsHint;
-
- // Unzipping tab
- edtUZipFilename->Hint = szZipFilenameHint;
- edtUUnzipToFolder->Hint = szUnzipToFolderHint;
- edtUFilesToProcess->Hint = szFilesToProcessHint;
- edtUFilesToExclude->Hint = szFilesToExcludeHint;
- chkUSkipIfExisting->Hint = szSkipIfExistingHint;
- chkUSkipIfNotExisting->Hint = szSkipIfNotExistingHint;
- chkUSkipIfOlderDate->Hint = szSkipIfOlderDateHint;
- chkUSkipIfOlderVersion->Hint = szSkipIfOlderVersionHint;
- btUnzip->Hint = szUnzipHint;
-
- // Zipping Sfx tab
- edtSZipFilename->Hint = szZipFilenameSfxHint;
- edtSFilesToProcess->Hint = szFilesToProcessHint;
- edtSSfxBinaryModule->Hint = szSfxBinaryModuleHint;
- edtSTitle->Hint = szSfxStringsHint;
- edtSIntro->Hint = szSfxMessagesHint;
- btZipSfx->Hint = szZipSfxHint;
- }
-
- void TfrmMain::FillAttributeList( TCheckListBox* pList )
- {
- pList->Items->Clear();
- pList->Items->AddObject( "Archive", ( TObject* ) xfaArchive );
- pList->Items->AddObject( "Read-only", ( TObject* ) xfaReadOnly );
- pList->Items->AddObject( "Hidden", ( TObject* ) xfaHidden );
- pList->Items->AddObject( "System", ( TObject* ) xfaSystem );
- pList->Items->AddObject( "Volume label", ( TObject* ) xfaVolume );
- pList->Items->AddObject( "Folder", ( TObject* ) xfaFolder );
- pList->Items->AddObject( "Compressed", ( TObject* ) xfaCompressed );
- }
-
- xcdFileAttributes TfrmMain::GetSelectedAttributes( TCheckListBox* pList )
- {
- xcdFileAttributes xAttributes = xfaNone;
-
- for( int i = 0; i < pList->Items->Count; i++ )
- {
- if( pList->Checked[ i ] )
- {
- xAttributes += ( xcdFileAttributes ) pList->Items->Objects[ i ];
- }
- }
-
- return xAttributes;
- }
-
- void TfrmMain::SetSelectedAttributes( TCheckListBox* pList,
- xcdFileAttributes xAttribs )
- {
- for( int i = 0; i < pList->Items->Count; i++ )
- {
- pList->Checked[ i ] = ( ( ( xcdFileAttributes ) pList->Items->Objects[ i ] ) & xAttribs );
- }
- }
-
- void TfrmMain::ResetDefaultXceedZipProperties( TXceedZipProxy* pZip )
- {
- pZip->BasePath = "";
- pZip->CompressionLevel = xclHigh;
- pZip->EncryptionPassword = "";
- pZip->RequiredFileAttributes = xfaNone;
- pZip->ExcludedFileAttributes = xfaNone;
- pZip->FilesToProcess = "";
- pZip->FilesToExclude = "";
- pZip->MinDateToProcess = EncodeDate( 1900, 01, 01 );
- pZip->MaxDateToProcess = EncodeDate( 9999, 12, 31 );
- pZip->MinSizeToProcess = 0;
- pZip->MaxSizeToProcess = 0; // Zero means no upper limit
- pZip->SplitSize = 0; // Zero means no split
- pZip->PreservePaths = false;
- pZip->ProcessSubfolders = false;
- pZip->SkipIfExisting = false;
- pZip->SkipIfNotExisting = false;
- pZip->SkipIfOlderDate = false;
- pZip->SkipIfOlderVersion = false;
- pZip->TempFolder = ""; // Empty means default Windows temp folder
- pZip->UseTempFile = true;
- pZip->UnzipToFolder = "";
- pZip->ZipFilename = "";
- pZip->SpanMultipleDisks = xdsRemovableDrivesOnly;
- pZip->ExtraHeaders = 0;
-
- // General SFX stuff
- pZip->SfxBinaryModule = "";
- pZip->SfxResetButtons();
- pZip->SfxResetMessages();
- pZip->SfxResetStrings();
- }
-
- //
- // PreviewFiles method:
- // This method let's you list all files (through the "OnPreviewingFile" event)
- // that would be processed by the Zip method with the same property values.
- //
- void __fastcall TfrmMain::btPreviewFilesClick(TObject *Sender)
- {
- // To be sure other tabs settings do not interfere with this example, we
- // start by resetting XceedZip properties to default values
- ResetDefaultXceedZipProperties( xZip );
-
- // Clear the result list before starting
- edtResults->Clear();
- edtResults->Lines->Add( "PreviewFiles example:" );
-
- // Set properties displayed on this tab
- xZip->FilesToProcess = edtPFilesToProcess->Text; // required
- xZip->FilesToExclude = edtPFilesToExclude->Text;
- xZip->ProcessSubfolders = chkPProcessSubfolders->Checked;
- xZip->RequiredFileAttributes = GetSelectedAttributes( lstPRequiredFileAttributes );
- xZip->ExcludedFileAttributes = GetSelectedAttributes( lstPExcludedFileAttributes );
-
- // Launch the previewing
- xcdError xErr = xZip->PreviewFiles( false );
-
- // We can check the results here or in the ProcessCompleted event
- }
-
- //
- // Zip method:
- // The files that are matched by the filtering properties will be added to the
- // zip file specified by the ZipFilename property.
- //
- void __fastcall TfrmMain::btZipClick(TObject *Sender)
- {
- // To be sure other tabs settings do not interfere with this example, we
- // start by resetting XceedZip properties to default values
- ResetDefaultXceedZipProperties( xZip );
-
- // Clear the result list before starting
- edtResults->Lines->Clear();
- edtResults->Lines->Add( "Zip example:" );
-
- // Set properties displayed on this tab
- xZip->ZipFilename = edtZZipFilename->Text; // required
- xZip->BasePath = edtZBasePath->Text;
- xZip->FilesToProcess = edtZFilesToProcess->Text; // required
- xZip->FilesToExclude = edtZFilesToExclude->Text;
- xZip->ProcessSubfolders = chkZProcessSubfolders->Checked;
- xZip->PreservePaths = chkZPreservePaths->Checked;
- xZip->UseTempFile = chkZUseTempFile->Checked;
- xZip->TempFolder = edtZTempFolder->Text;
-
- // Launch the zipping
- xcdError xErr = xZip->Zip();
-
- // We can check the results here or in the ProcessCompleted event
- }
-
- //
- // ListZipContents method:
- // Lists (through the OnListingFile event) the files contained in the zip file
- // specified by the ZipFilename property. You can set the filtering propeties
- // to list only particular files, or leave the FilesToProcess empty to list
- // everything.
- //
- void __fastcall TfrmMain::btListClick(TObject *Sender)
- {
- // To be sure other tabs settings do not interfere with this example, we
- // start by resetting XceedZip properties to default values
- ResetDefaultXceedZipProperties( xZip );
-
- // Clear the result list before starting
- edtResults->Lines->Clear();
- edtResults->Lines->Add( "ListZipContents example:" );
-
- // Set properties displayed on this tab
- xZip->ZipFilename = edtLZipFilename->Text; // required
- xZip->MinDateToProcess = dtLMinDateToProcess->Date;
- xZip->MaxDateToProcess = dtLMaxDateToProcess->Date;
- xZip->MinSizeToProcess = StrToIntDef( edtLMinSizeToProcess->Text, 0 );
- xZip->MaxSizeToProcess = StrToIntDef( edtLMaxSizeToProcess->Text, 0 );
-
- // Launch the listing
- xcdError xErr = xZip->ListZipContents();
-
- // We can check the results here or in the ProcessCompleted event
- }
-
- //
- // Unzip method:
- // Unzips from the specified zip file (ZipFilename property) files that match
- // the filtering properties.
- //
- void __fastcall TfrmMain::btUnzipClick(TObject *Sender)
- {
- // To be sure other tabs settings do not interfere with this example, we
- // start by resetting XceedZip properties to default values
- ResetDefaultXceedZipProperties( xZip );
-
- // Clear the result list before starting
- edtResults->Lines->Clear();
- edtResults->Lines->Add( "Unzip example:" );
-
- // Set properties displayed on this tab
- xZip->ZipFilename = edtUZipFilename->Text; // required
- xZip->UnzipToFolder = edtUUnzipToFolder->Text; // required
- xZip->FilesToProcess = edtUFilesToProcess->Text; // required
- xZip->FilesToExclude = edtUFilesToExclude->Text;
- xZip->SkipIfExisting = chkUSkipIfExisting->Checked;
- xZip->SkipIfNotExisting = chkUSkipIfNotExisting->Checked;
- xZip->SkipIfOlderDate = chkUSkipIfOlderDate->Checked;
- xZip->SkipIfOlderVersion = chkUSkipIfOlderVersion->Checked;
-
- // Launch the unzipping
- xcdError xErr = xZip->Unzip();
-
- // We can check the results here or in the ProcessCompleted event
- }
-
- //
- // Zip method:
- // When SfxBinaryModule contains a filename, then the resulting zip file is a
- // self-extracting zip file that uses this binary module as a binary header.
- // But appart from that (and changing the Sfx options with the Sfx properties),
- // creating a self-extracting zip file is just like creating a normal zip file.
- //
- void __fastcall TfrmMain::btZipSfxClick(TObject *Sender)
- {
- // To be sure other tabs settings do not interfere with this example, we
- // start by resetting XceedZip properties to default values
- ResetDefaultXceedZipProperties( xZip );
-
- // Clear the result list before starting
- edtResults->Lines->Clear();
- edtResults->Lines->Add( "Zip Sfx example:" );
-
- // Set properties displayed on this tab
- xZip->ZipFilename = edtSZipFilename->Text; // required
- xZip->FilesToProcess = edtSFilesToProcess->Text; // required
- xZip->SfxBinaryModule = edtSSfxBinaryModule->Text; // required to make an EXE
-
- // IMPORTANT: The wrapper classes C++Builder creates around the Xceed Zip
- // ActiveX does not expose property arrays, like SfxButtons,
- // SfxMessages and SfxStrings. But it creates methods of the
- // form "Set_SfxButtons, Get_SfxButtons, etc". They work very
- // well, but strange enough: they are declared in the "private"
- // section of the class. In order for these two lines to compile,
- // you must open "XceedZipLib_TLB.h" and move the six methods
- // to the public section. The only catch is that the string
- // parameter is expected to be a BSTR, not a WideString. Just
- // typecast your AnsiString to a WideString!
- xZip->SfxStrings[ xssTitle ] = WideString( edtSTitle->Text ).c_bstr();
- xZip->SfxMessages[ xsmIntro ] = WideString( edtSIntro->Text ).c_bstr();
-
- // Launch the zipping
- xcdError xErr = xZip->Zip();
-
- // We can check the results here or in the ProcessCompleted event
- }
-
- //
- // Some of the Xceed Zip events:
- //
-
- //
- // OnFileStatus event:
- // Triggered during processing of a file, at every 32k. Gives a status on each
- // file, one at a time, while it is being processed. Perfect for a file by file
- // progress bar. You can use the CurrentOperation property to recall what this
- // XceedZip instance is doing and display a proper status message.
- //
- void __fastcall TfrmMain::xZipFileStatus(TObject *Sender, BSTR sFilename,
- long lSize, long lCompressedSize, long lBytesProcessed,
- short nBytesPercent, short nCompressionRatio,
- TOLEBOOL bFileCompleted)
- {
- if( lBytesProcessed == 0 )
- {
- switch( xZip->CurrentOperation )
- {
- case xcoZipping:
- edtResults->Lines->Add( WideString( "Zipping " ) + sFilename );
- break;
-
- case xcoUnzipping:
- edtResults->Lines->Add( WideString( "unzipping " ) + sFilename );
- break;
- }
- }
-
- barFile->Position = nBytesPercent;
- }
-
- //
- // OnGlobalStatus event:
- // Triggered during processing of files, at every 32k. Gives general status of
- // the complete process. Perfect for a general progress bar.
- //
- void __fastcall TfrmMain::xZipGlobalStatus(TObject *Sender,
- long lFilesTotal, long lFilesProcessed, long lFilesSkipped,
- short nFilesPercent, long lBytesTotal, long lBytesProcessed,
- long lBytesSkipped, short nBytesPercent, long lBytesOutput,
- short nCompressionRatio)
- {
- barGlobal->Position = nBytesPercent;
- }
-
- //
- // OnListingFile event:
- // Triggered while listing the contents of a zip file with the ListZipContents
- // method.
- //
- void __fastcall TfrmMain::xZipListingFile(TObject *Sender, BSTR sFilename,
- BSTR sComment, long lSize, long lCompressedSize,
- short nCompressionRatio, xcdFileAttributes xAttributes, long lCRC,
- DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated,
- xcdCompressionMethod xMethod, TOLEBOOL bEncrypted, long lDiskNumber,
- TOLEBOOL bExcluded, xcdSkippingReason xReason)
- {
- if( bExcluded )
- {
- edtResults->Lines->Add( WideString( "Excluding " ) + sFilename + " (" +
- xZip->GetErrorDescription( xvtSkippingReason, xReason ) + ")" );
- }
- else
- {
- edtResults->Lines->Add( WideString( "Including " ) + sFilename );
- }
- }
-
- //
- // OnPreviewingFile event:
- // Triggered when previewing files on disk with the PreviewFiles method.
- //
- void __fastcall TfrmMain::xZipPreviewingFile(TObject *Sender,
- BSTR sFilename, BSTR sSourceFilename, long lSize,
- xcdFileAttributes xAttributes, DATE dtLastModified,
- DATE dtLastAccessed, DATE dtCreated, TOLEBOOL bExcluded,
- xcdSkippingReason xReason)
- {
- if( bExcluded )
- {
- edtResults->Lines->Add( WideString( "Excluding " ) + sFilename + " (" +
- xZip->GetErrorDescription( xvtSkippingReason, xReason ) + ")" );
- }
- else
- {
- edtResults->Lines->Add( WideString( "Including " ) + sFilename );
- }
- }
-
- //
- // OnProcessCompleted event:
- // Triggered when any process submitted terminates. It is highly useful when
- // processing files with BackgroundProcessing set to true. This is how you
- // know the process completed!
- //
- void __fastcall TfrmMain::xZipProcessCompleted(TObject *Sender,
- long lFilesTotal, long lFilesProcessed, long lFilesSkipped,
- long lBytesTotal, long lBytesProcessed, long lBytesSkipped,
- long lBytesOutput, short nCompressionRatio, xcdError xResult)
- {
- // Display the error number and default message
- edtResults->Lines->Add( WideString( "Process completed with error code " ) +
- IntToStr( ( int )xResult ) );
- edtResults->Lines->Add( WideString( "-=> " ) +
- xZip->GetErrorDescription( xvtError, xResult ) );
-
- // Display statistics
- switch( xZip->CurrentOperation )
- {
- case xcoZipping:
- case xcoUnzipping:
- case xcoRemoving:
- edtResults->Lines->Add( IntToStr( ( int )lFilesProcessed ) + " file(s) processed for " +
- IntToStr( ( int )lBytesProcessed ) + " byte(s)" );
- edtResults->Lines->Add( IntToStr( ( int )lFilesSkipped ) + " file(s) skipped for " +
- IntToStr( ( int )lBytesSkipped ) + " byte(s)" );
- break;
-
- case xcoListing:
- edtResults->Lines->Add( IntToStr( ( int )lFilesTotal ) + " file(s) listed" );
- break;
-
- case xcoPreviewing:
- edtResults->Lines->Add( IntToStr( ( int )lFilesTotal ) + " file(s) previewed" );
- break;
- }
- }
-
- //
- // OnSkippingFile event:
- // Triggered during any processing, when a file is excluded because of the
- // filtering properties (0 < xReason < 100), or because an error prevented this
- // file from being processed (xReason >= 100).
- //
- void __fastcall TfrmMain::xZipSkippingFile(TObject *Sender, BSTR sFilename,
- BSTR sComment, BSTR sFilenameOnDisk, long lSize,
- long lCompressedSize, xcdFileAttributes xAttributes, long lCRC,
- DATE dtLastModified, DATE dtLastAccessed, DATE dtCreated,
- xcdCompressionMethod xMethod, TOLEBOOL bEncrypted,
- xcdSkippingReason xReason)
- {
- edtResults->Lines->Add( WideString( "Skipping " ) + sFilename + " (" +
- xZip->GetErrorDescription( xvtSkippingReason, xReason ) + ")" );
- }
-
- //
- // OnWarning event:
- // Triggered during processing when a recoverable error is encountered.
- //
- void __fastcall TfrmMain::xZipWarning(TObject *Sender, BSTR sFilename,
- xcdWarning xWarning)
- {
- edtResults->Lines->Add( WideString( "Warning for " ) + sFilename + " (" +
- xZip->GetErrorDescription( xvtWarning, xWarning ) + ")" );
- }
-
- //
- // OnZipContentsStatus event:
- // Triggered while reading the contents of an existing zip file. This happens
- // when unzipping, adding files to an existing zip file, removing files,
- // testing a zip file, converting a zip file, or getting the zip file's info.
- // This event is useful when dealing with very large zip files, and you want
- // to display a progress status while the zip file is read.
- //
- void __fastcall TfrmMain::xZipZipContentsStatus(TObject *Sender,
- long lFilesRead, long lFilesTotal, short nFilesPercent)
- {
- // We're not doing anything special here!
- }
-
- //
- // OnInsertDisk event:
- // Triggered when processing a spanned zip file, or when creating a spanned zip
- // file and the current disk is filled. When nDiskNumber is zero, it means the
- // last disk of the set is required, in order to read the zip file's list of
- // files.
- //
- void __fastcall TfrmMain::xZipInsertDisk(TObject *Sender, long lDiskNumber,
- TOLEBOOL *bDiskInserted)
- {
- // When nDiskNumber is 0, this means the last disk of the set is required
- int nAnswer;
-
- if( lDiskNumber == 0 )
- {
- nAnswer = MessageDlg( "This file is part of a multidisk zip file. Please "
- "insert the last disk of the set.", mtInformation,
- TMsgDlgButtons() << mbOK << mbCancel, 0 );
- }
- else
- {
- nAnswer = MessageDlg( AnsiString( "Please insert disk #" ) +
- IntToStr( ( int )lDiskNumber ) + ".", mtInformation,
- TMsgDlgButtons() << mbOK << mbCancel, 0 );
- }
-
- if( nAnswer == mrOk )
- {
- // CBuilder is wrong, the bDiskInserted parameter os a VARIANT_BOOL* NOT
- // TOLEBOOL
- * ( VARIANT_BOOL* ) bDiskInserted = VARIANT_TRUE;
- }
- }
- //---------------------------------------------------------------------------
- //
- // OnReplacingFile event:
- // Triggered while zipping or unzipping, when a file is about to be replaced.
- // The default value of the bReplaceFile parameter is true, so you do not need
- // to implement anything if you always want to replace files.
- //
-
- void __fastcall TfrmMain::xZipReplacingFile(TObject *Sender,
- BSTR sFilename, BSTR sComment, long lSize,
- xcdFileAttributes xAttributes, DATE dtLastModified,
- DATE dtLastAccessed, DATE dtCreated, BSTR sOrigFilename,
- long lOrigSize, xcdFileAttributes xOrigAttributes,
- DATE dtOrigLastModified, DATE dtOrigLastAccessed, DATE dtOrigCreated,
- TOLEBOOL *bReplaceFile)
- {
- edtResults->Lines->Add( WideString( "Replacing " ) + sOrigFilename );
- }
- //---------------------------------------------------------------------------
-
-