home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- File: MainMn.cpp
- Description: Zip Manager sample application using The Xceed Zip Compression
- Library 4
- Copyright (c) 1995-1999 Xceed Software Inc.
- *******************************************************************************/
-
- #include <vcl\vcl.h>
- #include <string.h>
- #pragma hdrstop
-
- #include "MainMn.h"
- #include "Tools.h"
-
- #pragma link "XceedZipLib_OCX"
- #pragma resource "*.dfm"
-
- TMainFormFm *MainFormFm = 0;
-
- //
- // Private declarations
- //
- int MinWidth;
- long TotalSize;
- long TotalZipSize;
- long FilesLbBytes;
- bool Testing;
-
- //
- // Constructor
- //
- __fastcall TMainFormFm::TMainFormFm(TComponent* Owner)
- : TForm(Owner)
- {
- }
-
- //
- // Destructor
- //
- void __fastcall TMainFormFm::FormCreate(TObject *Sender)
- {
- Application->OnHint = StatusBarShowHint;
- MinWidth = Width;
- Caption = "Untitled - Xceed Zip Demo";
- Application->Title = Caption;
- }
-
- //
- // StatusBarShowHint:
- // Update status bar state.
- //
- void __fastcall TMainFormFm::StatusBarShowHint(TObject *Sender)
- {
- StatusLb->Visible = (Application->Hint.Length()==0);
- HintLb->Visible = (Application->Hint.Length()!=0);
- HintLb->Caption = Application->Hint;
- }
-
- //
- // The EnableInterface procedure is used to 'shut down' parts of the graphical
- // interface of this demo while the TXceedZip component is working. It turns off
- // menus, changes the cursor to an hourglass, etc. It can also be called to turn
- // everything back on.
- //
- void TMainFormFm::EnableInterface(bool Enable)
- {
- static int DisableCount = 0;
- bool ControlsEnable = false;
-
- if (Enable)
- {
- // Keep track of multiple disables/enables, and enable interface only when
- // there are as many 'enables' as there were 'disables'.
- DisableCount--;
- if (DisableCount <= 0)
- {
- DisableCount = 0;
- ControlsEnable = true;
- }
- }
- else
- {
- DisableCount++;
- }
-
- FileMn->Enabled = ControlsEnable;
- EditMn->Enabled = ControlsEnable;
- OptionsMn->Enabled = ControlsEnable;
- HelpMn->Enabled = ControlsEnable;
- FilesLb->Enabled = ControlsEnable;
-
- // Do not allow abort when not using a temp file, it can corrupt the archive.
- AbortSb->Enabled = (!ControlsEnable) && (MainXz->UseTempFile == True);
-
- if (ControlsEnable)
- Cursor = crDefault;
- else
- Cursor = crHourGlass;
-
- if (Enable)
- {
- ProgressBar1->Position = 0;
- StatusLb->Caption = AnsiString(FilesLb->Items->Count) + " Entries, " +
- FloatToStrF(TotalSize, ffNumber, 10, 0) + " Bytes, " +
- FloatToStrF(TotalZipSize, ffNumber, 10, 0) + " Bytes.";
- }
-
- HintLb->Caption = "";
-
- // The HintLb and StatusLb labels are one on top of the other.
- HintLb->Visible = ControlsEnable;
- StatusLb->Visible = !ControlsEnable;
- }
-
- //
- // The LoadFileList procedure asks the TXceedZipProxy component for a list of files
- // contained in the current archive. It calls the List method and expects to
- // receive all the information via the OnListing event. See the MainXzListing
- // procedure to see how the information is placed into the demo's main listbox.
- //
- void TMainFormFm::LoadFileList()
- {
- xcdError Err;
-
- long TotalFiles;
- long CompressedBytes;
- long UnCompressedBytes;
- short CompressionRatio;
- TOLEBOOL IsZipFileSpanned;
-
- TotalSize = 0;
- TotalZipSize = 0;
- FilesLb->Items->Clear();
- FilesLbBytes = 0;
-
- Err = MainXz->GetZipFileInformation(&TotalFiles,&CompressedBytes,&UnCompressedBytes,&CompressionRatio,&IsZipFileSpanned);
- ProgressBar1->Max = TProgressRange(TotalFiles);
-
- if (TotalFiles > 100)
- {
- StatusLb->Caption = "Reading " + AnsiString(TotalFiles) + " items...";
- }
-
- FilesLb->Items->BeginUpdate();
- MainXz->FilesToProcess = "";
- Err = MainXz->ListZipContents();
-
- if (Err != xerNothingToDo)
- {
- HandleError(Err, "reading archive contents", MainXz);
- }
-
- FilesLb->Items->EndUpdate(); //**-** this line produce bug
-
- ProgressBar1->Position = 0;
- ProgressBar1->Max = TProgressRange(100); // reset to usual maximum
- }
-
- //
- // The FileMnClick procedure makes sure that the proper items are enabled in the
- // File menu.
- //
- void __fastcall TMainFormFm::FileMnClick(TObject *Sender)
- {
- bool ZipFileNameEmpty;
- ZipFileNameEmpty = (MainXz->ZipFilename.Length() == 0);
-
- FileCloseMn->Enabled = (!ZipFileNameEmpty);
- FileFixMn->Enabled = (ZipFileNameEmpty) && (!MainXz->SpanMultipleDisks);
- FileDeleteMn->Enabled = (ZipFileNameEmpty);
- FileTestMn->Enabled = (ZipFileNameEmpty);
- }
-
- //
- // The FileNewMnClick procedure creates a new archive file, but the archive file
- // is not really created until files are added to it first.
- //
- void __fastcall TMainFormFm::FileNewMnClick(TObject *Sender)
- {
- NewZipDg->FileName = "";
- EnableInterface(false);
- if (NewZipDg->Execute())
- {
- if (FileExists(NewZipDg->FileName))
- {
- DeleteFile(NewZipDg->FileName.c_str());
- }
-
- // Inform the TXceedZip component of the zip file name to use.
- MainXz->ZipFilename = NewZipDg->FileName;
- Caption = ExtractFileName(MainXz->ZipFilename) + " - XceedZip Demo";
- Application->Title = Caption;
- FilesLb->Clear();
- FilesLbBytes = 0;
- TotalSize = 0;
- TotalZipSize = 0;
- StatusLb->Caption = "";
- }
- EnableInterface(true);
- }
-
- //
- // The FileOpenMnClick procedure opens an already existing archive, and calls
- // LoadFileList to list the archive's contents into the demo's main listbox.
- //
- void __fastcall TMainFormFm::FileOpenMnClick(TObject *Sender)
- {
- OpenZipDg->Title = "Open Archive";
- OpenZipDg->FileName = "";
- EnableInterface(false);
- if (OpenZipDg->Execute())
- {
- // Inform the TXceedZip component of the zip file name to use. }
- MainXz->ZipFilename = OpenZipDg->FileName;
- Caption = MainXz->ZipFilename + " - XceedZip Demo";
- Application->Title = Caption;
- // Call procedure that will list the contents of the archive into the
- // demo's main listbox.
- LoadFileList();
- }
- EnableInterface(True);
- }
-
- //
- // The FileCloseMnClick procedure closes an archive. It does not really close the
- // archive because the archive is already closed when not being used. It only
- // clears the main listbox, the ZipFileName property of the TXceedZip component,
- // and the application title is reset.
- //
- void __fastcall TMainFormFm::FileCloseMnClick(TObject *Sender)
- {
- MainXz->ZipFilename = "";
- Caption = "Untitled - XceedZip Demo";
- Application->Title = Caption;
- FilesLb->Clear();
- FilesLbBytes = 0;
- StatusLb->Caption = "";
- }
-
- void __fastcall TMainFormFm::FileExitMnClick(TObject *Sender)
- {
- Close();
- }
-
- //
- // The FileDeleteMnClick procedure prompts the user for an archive file to
- // delete, then deletes it.
- //
- void __fastcall TMainFormFm::FileDeleteMnClick(TObject *Sender)
- {
- OpenZipDg->Title = "Delete Archive";
- OpenZipDg->FileName = "";
- EnableInterface(false);
-
- if ((OpenZipDg->Execute()))
- {
- AnsiString Msg("Are you sure you want to delete file \r\n '" + OpenZipDg->FileName + "' ?");
- if (Application->MessageBox(Msg.c_str(), "Confirmation", MB_YESNO + MB_ICONQUESTION) == IDYES)
- {
- DeleteFile(OpenZipDg->FileName.c_str());
- }
- }
- EnableInterface(true);
- }
-
- //
- // The FileTestMnClick procedure tells the TXceedZip component to test the
- // contents of an archive file selected by the user. A dialog box is opened for
- // the user to select the archive file. Note: The Test method is used, but is not
- // passed a list of files to process. Without a list of files to process, the
- // TXceedZip component will test all the files in the archive. You can pass a
- // list of files to test in the same way that files are passed to the Extract
- // method in the EditExtractMnClick procedure in this demo. This way, you can
- // test specific files.
- //
- void __fastcall TMainFormFm::FileTestMnClick(TObject *Sender)
- {
- xcdError Err;
-
- OpenZipDg->Title = "Test Archive";
- OpenZipDg->FileName = "";
- EnableInterface(false);
- // Open a dialog box to ask for the archive filename.
- if (OpenZipDg->Execute())
- {
- // Inform the TXceedZip component of the filename.
- MainXz->ZipFilename = OpenZipDg->FileName;
-
- // Since it may take long before getting an OnTesting event so we can
- // display 'Testing file...' we will display 'Testing archive...' until then.
- StatusLb->Caption = "Testing archive " + MainXz->ZipFilename;
-
- // used so that skipping messages are different
- Testing = true;
-
- // Execute the Test method. Put return value in Err.
- Err = MainXz->TestZipFile(true);
- Testing = false;
-
- // Since we are testing an archive file, XcdSuccess means that all the
- // files in the archive have passed the test.
- if (Err == xerSuccess)
- {
- Application->MessageBox("All files in the archive are OK.", "Confirmation", MB_OK + MB_ICONQUESTION);
- }
- else
- {
- if (Err == xerFilesSkipped)
- {
- // We can permit ourselves to say 'Some files were skipped', without
- // specifying which ones, because the OnSkippingFile event will have
- // already informed us about each file being skipped.
- Application->MessageBox("All files tested in the archive are OK.\r\n (Some files were skipped)", "Information", MB_OK + MB_ICONINFORMATION);
- }
- else
- {
- // Regular error handler.
- HandleError(Err, "testing", MainXz);
- }
- MainXz->ZipFilename = "";
- }
- EnableInterface(true);
- }
- }
-
- //
- // The EditMnClick procedure makes sure that the proper menu items in the Edit
- // menu are enabled. For example, when we are in Multidisk mode, the Update,
- // Delete and UpdateZIPDate commands cannot be used.
- //
- void __fastcall TMainFormFm::EditMnClick(TObject *Sender)
- {
- EditAddMn->Enabled = (MainXz->ZipFilename.Length() != 0) && ((MainXz->SpanMultipleDisks == xdsNever) || (FilesLb->Items->Count == 0));
- EditDeleteMn->Enabled = (FilesLb->SelCount > 0) && (!MainXz->SpanMultipleDisks);
- EditExtractMn->Enabled = (FilesLb->SelCount > 0);
- EditUpdateMn->Enabled = (MainXz->ZipFilename.Length() != 0) && (!MainXz->SpanMultipleDisks);
- EditSelectAllMn->Enabled = (FilesLb->Items->Count > 0);
- }
-
- //
- // The EditAddMnClick procedure adds files to the currently opened archive file.
- // A dialog box is opened to allow the user to select the files to be added to
- // the archive. Files selected in the demo's main listbox are not considered.
- //
- void __fastcall TMainFormFm::EditAddMnClick(TObject *Sender)
- {
- AddFilesDg->FileName = "";
- EnableInterface(false);
- // Allow user to select files to add with a dialog box.
- if (AddFilesDg->Execute())
- {
- // Add all the files selected from the dialog box to the TXceedZip
- // component's list of files to process.
- MainXz->FilesToProcess = AddFilesDg->Files->Text;
- StatusLb->Caption = "Adding selected files.";
- // Add the files, handle return code.
- if (HandleError(MainXz->Zip(), "adding", MainXz) != 2)
- {
- // If in Multidisk mode, tell user the add was completed (so that
- // the user may understand that any further disk swapping is only
- // to read the contents of the archive.
- if (MainXz->SpanMultipleDisks)
- {
- Application->MessageBox("Add operation completed. To test the archive, "
- "you must close it first, then select the test "
- "option from the file menu.", "Information", MB_OK + MB_ICONINFORMATION);
-
- // Update the demo's main listbox to reflect the new additions.
- LoadFileList();
- }
- }
- }
- EnableInterface(true);
- }
-
- //
- // The EditDeleteMnClick procedure takes the selected files in the demo's listbox
- // and instructs the TXceedZip component to delete these files from the currently
- // opened archive.
- //
- void __fastcall TMainFormFm::EditDeleteMnClick(TObject *Sender)
- {
- EnableInterface(false);
- // Add all the files that are selected in the demo's main listbox to the
- // TXceedZip component's list of files to process. Since the main listbox
- // contains a list of files already in the currently opened archive, only files
- // in the archive can be selected to delete.
- AssignFromLb(FilesLb, MainXz);
- StatusLb->Caption = "Deleting selected files.";
- // Delete the files, handle return code
- HandleError(MainXz->RemoveFiles(), "deleting", MainXz);
- // Update the demo's main listbox to reflect the current contents of the
- // currently opened archive file.
- LoadFileList();
- EnableInterface(true);
- }
-
- //
- // The EditExtractMnClick procedure takes the selected files in the demo's
- // listbox and instructs the TXceedZipProxy component to extract these files into the
- // user selected destination. A dialog box is opened to let the user select the
- // destination directory.
- //
- void __fastcall TMainFormFm::EditExtractMnClick(TObject *Sender)
- {
- char Dir[260];
-
- GetCurrentDirectory(260, Dir);
- if (FilesLb->SelCount > 0)
- {
- // Ask the user where to extract the files.
- if (SelectDirectory (Dir, Handle))
- {
- EnableInterface(false);
- // Add all the files that are selected in the demo's main listbox to the
- // TXceedZip component's list of files to process. Since the main listbox
- // contains a list of files already in the currently opened archive, only
- // files in the archive can be selected to extract.
- AssignFromLb(FilesLb, MainXz);
- // Tell TXceedZip component where the user wants to extract the files.
- MainXz->UnzipToFolder = Dir;
- StatusLb->Caption = "Extracting selected files.";
- //Extract the files, handle return code.
- HandleError(MainXz->Unzip(), "extracting", MainXz);
- // No need to update the main listbox here - contents have not changed.
- EnableInterface(true);
- }
- }
- }
-
- //
- // The EditUpdateMnClick procedure updates files in the currently opened archive
- // file. A dialog box is opened to allow the user to select files to be updated
- // in the archive. Update means that only files newer than those already in the
- // archive file will be added or replaced into the archive.
- //
- void __fastcall TMainFormFm::EditUpdateMnClick(TObject *Sender)
- {
- AddFilesDg->FileName = "";
- EnableInterface(false);
- // Allow user to select files to update with a dialog box.
- if (AddFilesDg->Execute())
- {
- // Add all the files selected from the dialog box to the TXceedZip
- // component's list of files to process.
- MainXz->FilesToProcess = AddFilesDg->Files->Text;
- StatusLb->Caption = "Updating files.";
- // Update the files, handle error
- if (HandleError(MainXz->Zip(), "updating", MainXz))
- {
- // Update the demo's main listbox to reflect the new additions.
- LoadFileList();
- }
- }
- EnableInterface(true);
- }
-
- //
- // The EditSelectAllMnClick procedure selects all the items in the demo's main
- // listbox.
- //
- void __fastcall TMainFormFm::EditSelectAllMnClick(TObject *Sender)
- {
- SendMessage(FilesLb->Handle, LB_SELITEMRANGE, 1, (long) FilesLb->Items->Count - 1);
- }
-
- void __fastcall TMainFormFm::OptionsMnClick(TObject *Sender)
- {
- OptionsUseTempFileMn->Checked = MainXz->UseTempFile && (!MainXz->SpanMultipleDisks);
- OptionsUseTempFileMn->Enabled = !MainXz->SpanMultipleDisks;
- MultidiskmodeMn->Checked = MainXz->SpanMultipleDisks;
- NoCompression->Checked = (MainXz->CompressionLevel == 0);
- Fastestcompression->Checked = (MainXz->CompressionLevel == 1);
- Normalcompression->Checked = (MainXz->CompressionLevel == 6);
- Bestcompression->Checked = (MainXz->CompressionLevel == 9);
- }
-
- //
- // The OptionsUseTempFileMnClick procedure informs the TXceedZip component
- // whether or not to use a temporary file when adding files.
- //
- void __fastcall TMainFormFm::OptionsUseTempFileMnClick(TObject *Sender)
- {
- MainXz->UseTempFile = !MainXz->UseTempFile;
- OptionsUseTempFileMn->Checked = MainXz->UseTempFile;
- }
-
- void __fastcall TMainFormFm::MultidiskmodeMnClick(TObject *Sender)
- {
- MainXz->SpanMultipleDisks = !MainXz->SpanMultipleDisks;
- MultidiskmodeMn->Checked = !MainXz->SpanMultipleDisks;
- }
-
- //
- // The HelpAboutMnClick option opens an about box for this demo.
- //
- void __fastcall TMainFormFm::HelpAboutMnClick(TObject *Sender)
- {
- Application->MessageBox("Zip Manager sample application for C++Builder 4\r\n"
- "Using The Xceed Zip Compression Library 4\n\r"
- "Copyright ⌐ 1995-1999 Xceed Software Inc., all rights reserved.\n\r\n\r",
- "Information", MB_OK | MB_ICONINFORMATION);
- }
-
- //
- // The AbortSbClick procedure prompts the user (with a message box), if they want
- // to stop the current operation. This procedure is called when the user clicks
- // on the little stop sign in the bottom right corner of the demo's main form.
- //
- void __fastcall TMainFormFm::AbortSbClick(TObject *Sender)
- {
- if (Application->MessageBox("Are you sure you want to abort the current process?",
- "Confirmation", MB_YESNO + MB_ICONWARNING) == IDYES)
- {
- MainXz->Abort = true;
- }
- }
-
- //
- // The FilesLbDrawItem procedure draws the items contained in the demo's main
- // listbox using the proper format. For example, the filename and path are
- // separated into the 1st and 7th column when being displayed. Column widths
- // are set according to the FilesHd header control which can be resized by
- // the user at runtime.
- //
- void __fastcall TMainFormFm::FilesLbDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
- {
- TRect R(Rect);
- AnsiString FileName, ItemStr, Str;
- TListBox *Ctrl = dynamic_cast<TListBox *> (Control);
-
- if ((State.Contains(odGrayed)) || (State.Contains(odDisabled)))
- {
- Ctrl->Canvas->Font->Color = clGrayText;
- }
-
- ItemStr = Ctrl->Items->Strings[Index];
- int I = 1;
-
- R.Right = R.Left + FilesHd->Sections->Items[0]->Width;
- ParseTab(ItemStr, I, FileName);
- Ctrl->Canvas->TextRect(R, R.Left + 2, R.Top, ExtractFileName(FileName));
-
- R.Left = R.Right;
- R.Right = R.Left + FilesHd->Sections->Items[1]->Width;
- ParseTab(ItemStr, I, Str );
- Ctrl->Canvas->TextRect(R, R.Left + (R.Right - R.Left) - Ctrl->Canvas->TextWidth(Str) - 2, R.Top, Str);
-
- R.Left = R.Right;
- R.Right = R.Left + FilesHd->Sections->Items[2]->Width;
- ParseTab(ItemStr, I, Str);
- Ctrl->Canvas->TextRect(R, R.Left + (R.Right - R.Left) - Ctrl->Canvas->TextWidth(Str) - 2, R.Top, Str);
-
- R.Left = R.Right;
- R.Right = R.Left + FilesHd->Sections->Items[3]->Width;
- ParseTab(ItemStr, I, Str);
- Ctrl->Canvas->TextRect(R, R.Left + (R.Right - R.Left) - Ctrl->Canvas->TextWidth(Str) - 2, R.Top, Str);
-
- R.Left = R.Right;
- R.Right = R.Left + FilesHd->Sections->Items[4]->Width;
- ParseTab(ItemStr, I, Str);
- Ctrl->Canvas->TextRect(R, R.Left + (R.Right - R.Left) - Ctrl->Canvas->TextWidth(Str) - 2, R.Top, Str);
-
- R.Left = R.Right;
- R.Right = R.Left + FilesHd->Sections->Items[5]->Width;
- ParseTab(ItemStr, I, Str);
- Ctrl->Canvas->TextRect(R, R.Left + (((R.Right - R.Left) - Ctrl->Canvas->TextWidth(Str)) / 2), R.Top, Str);
-
- R.Left = R.Right;
- R.Right = Rect.Right;
- Ctrl->Canvas->TextRect(R, R.Left + 2, R.Top, ExtractFilePath(FileName));
- }
-
- void __fastcall TMainFormFm::FilesLbMeasureItem(TWinControl *Control, int Index, int &Height)
- {
- Height = FilesLb->Canvas->TextHeight("W");
- }
-
- //
- // MainXz events
- //
-
- //
- // See the note for the MainXzDeleting procedure/handler, because this handler is
- // identical except for replacing Deleting with Fixing.
- //
- void __fastcall TMainFormFm::FastestcompressionClick(TObject *Sender)
- {
- MainXz->CompressionLevel = 1;
- }
-
- void __fastcall TMainFormFm::NormalcompressionClick(TObject *Sender)
- {
- MainXz->CompressionLevel = 6;
- }
-
- void __fastcall TMainFormFm::BestcompressionClick(TObject *Sender)
- {
- MainXz->CompressionLevel = 9;
- }
-
- void __fastcall TMainFormFm::NoCompressionClick(TObject *Sender)
- {
- MainXz->CompressionLevel = 0;
- }
-
- void __fastcall TMainFormFm::FilesHdSectionResize(THeaderControl *HeaderControl, THeaderSection *Section)
- {
- FilesLb->Refresh();
- }
-
- void __fastcall TMainFormFm::SetSfxConfiguration ()
- {
- /* The SfxExtractDirectory property should contain the path where files
- will be extracted to by default.
-
- The following variables are available when specifying
- a value for SfxExtractDirectory:
-
- %W = The location of the Windows Directory
- %S = The location of the Windows System directory
- %e = The directory where the self-extractor is being run from.
- %% = The '%' symbol. */
-
- MainXz->SfxDefaultUnzipToFolder = "%e";
-
- /* The SfxReadmePath should contain the path and filename of a text file
- to display after extracting files. */
-
- MainXz->SfxReadmeFile = "";
-
- /* The SfxRunExePath property should contain the path and filename of an
- executable to run after succesfully extracting all the files. This
- property also should contain the parameters the executable.
-
- The following variables are available when specifying
- a value for RunExePath:
-
- %d = The DefaultExtractDir, or the user-selected
- directory where files were extracted.
- %W = The location of the Windoes Directory
- %S = The location of the Windows System directory
- %e = The directory where the self-extractor is
- being run from.
- %% = The '%' symbol. */
-
- MainXz->SfxExecuteAfter = "";
-
- /* Default password to be used by self-extractor to extract files */
- MainXz->SfxDefaultPassword = "";
-
- /* Default overwrite behavior (Ask, Never, Always) */
- MainXz->SfxExistingFileBehavior = xseAsk;
- }
-
- //
- // The MainXzFileStatus procedure is a handler for the OnFileStatus event
- // generated by the TXceedZip component whenever a new file is going to be
- // added to an archive. This particular handler simply displays which file is
- // being added into the demo's status label, and resets the progress bar to
- // 0%.
- //
-
- void __fastcall TMainFormFm::MainXzFileStatus(TObject *Sender,
- BSTR sFilename, long lSize, long lCompressedSize,
- long lBytesProcessed, short nBytesPercent, short nCompressionRatio,
- TOLEBOOL bFileCompleted)
- {
- if( MainXz->CurrentOperation == xcoZipping )
- {
- StatusLb->Caption = WideString( "Adding '" ) + sFilename + "'.";
- ProgressBar1->Position = 0;
- }
- if (MainXz->CurrentOperation == xcoUnzipping)
- {
- StatusLb->Caption = WideString( "Extracting '" ) + sFilename + "'.";
- ProgressBar1->Position = 0;
- }
- if (MainXz->CurrentOperation == xcoTestingZipFile)
- {
- StatusLb->Caption = WideString( "Testing '" ) + sFilename + "'.";
- ProgressBar1->Position = 0;
- }
- }
-
- //
- // The MainXzRemovingFile procedure is a handler for the OnRemovingFile event
- // generated by the TXceedZipProxy component whenever a file is being deleted
- // from an archive. This particular handler simply displays which file is
- // being deleted into the demo's status label, and resets the progress bar to
- // 0%. Note: The progress bar will not be updated beyond 0% during the delete
- // operation because the delete operation does not generate OnStatus events.*/
- //
- void __fastcall TMainFormFm::MainXzRemovingFile(TObject *Sender,
- BSTR sFilename, BSTR sComment, long lSize, long lCompressedSize,
- xcdFileAttributes xAttributes, long lCRC, DATE dtLastModified,
- DATE dtLastAccessed, DATE dtCreated, xcdCompressionMethod xMethod,
- TOLEBOOL bEncrypted)
- {
- StatusLb->Caption = WideString("Deleting '")+ sFilename + "'.";
- ProgressBar1->Position = 0;
- }
-
- //
- // The MainXzListingFile procedure is an event handler for the OnListingFile
- // event generated by the TXceedZipProxy component because the ListZipContents
- // method was called to list files in an archive. This particular handler here
- // takes information of each file and adds it to the demo's main listbox.
- // No more than 64000 bytes of files and file information will be added to the
- // listbox.
- //
- void __fastcall TMainFormFm::MainXzListingFile(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)
- {
- AnsiString NewListBoxData;
-
- if( xAttributes & xfaFolder )
- {
- NewListBoxData = "<Folder>\t" +
- TDateTime(dtLastModified).DateString() + "\t" +
- TDateTime(dtLastModified).TimeString() + "\t" +
- FloatToStrF(lSize, ffNumber, 10, 0) + "\t" +
- FloatToStrF(lCompressedSize, ffNumber, 10, 0) + "\t" +
- IntToStr(nCompressionRatio) + "%";
- }
- else
- {
- NewListBoxData = WideString(sFilename) + "\t" +
- TDateTime(dtLastModified).DateString() + "\t" +
- TDateTime(dtLastModified).TimeString() + "\t" +
- FloatToStrF(lSize, ffNumber, 10, 0) + "\t" +
- FloatToStrF(lCompressedSize, ffNumber, 10, 0) + "\t" +
- IntToStr(nCompressionRatio) + "%";
- }
-
- if (FilesLbBytes < 64000)
- {
- FilesLb->Items->Add(NewListBoxData);
- FilesLbBytes = FilesLbBytes + NewListBoxData.Length();
- }
-
- if (ProgressBar1->Max > 100)
- {
- ProgressBar1->Position++;
- }
-
- TotalSize = TotalSize + lCompressedSize;
- TotalZipSize = TotalZipSize + nCompressionRatio;
- }
-
- //
- // The MainXzSkipping procedure is an event handler for the TXceedZip component's
- // OnSkippingFile event. A message box is displayed to inform the user that a
- // file is being skipped. The reason why is also indicated.
- //
- void __fastcall TMainFormFm::MainXzSkippingFile(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)
- {
- AnsiString SkipMsg;
-
- if (!Testing)
- {
- SkipMsg = WideString("Skipping '") + sFilename + "', ";
- }
- else
- {
- SkipMsg = WideString("File '") + sFilename + "' failed test: ";
- }
-
- switch (xcdSkippingReason(xReason))
- {
- case xsrInvalidCRC:
- SkipMsg = SkipMsg + "CRC does not check out.";
- break;
- case xsrSkipOlderDate:
- SkipMsg = SkipMsg + "file is already up to date.";
- break;
- case xsrInvalidPassword:
- SkipMsg = SkipMsg + "invalid or no password to decrypt file.";
- break;
- case xsrSkipExisting:
- SkipMsg = SkipMsg + "instructed not to overwrite.";
- break;
- }
- Application->MessageBox(SkipMsg.c_str(), "Warning", MB_OK + MB_ICONWARNING);
-
- ProgressBar1->Position = 0;
- }
-
- void __fastcall TMainFormFm::MainXzGlobalStatus(TObject *Sender,
- long lFilesTotal, long lFilesProcessed, long lFilesSkipped,
- short nFilesPercent, long lBytesTotal, long lBytesProcessed,
- long lBytesSkipped, short nBytesPercent, long lBytesOutput,
- short nCompressionRatio)
- {
- ProgressBar1->Position = nBytesPercent;
- }
-
- void __fastcall TMainFormFm::FileFixMnClick(TObject *Sender)
- {
- xcdError Err;
-
- MainFormFm->OpenZipDg->Title = "Fix Archive";
- MainFormFm->OpenZipDg->FileName = "";
-
- EnableInterface(false);
-
- if (MainFormFm->OpenZipDg->Execute())
- {
- // Tell the TXceedZip component which archive file to work with. }
- MainFormFm->MainXz->ZipFilename = MainFormFm->OpenZipDg->FileName;
-
- // Call the Fix method (aggressive = True, set Err to the return value. }
- Err = MainFormFm->MainXz->Convert(MainXz->ZipFilename);
-
- // Since we are fixing, Err=XcdSuccess means the archive has been fixed. }
- if (Err == xerSuccess)
- {
- Application->MessageBox("The specified Zip file has been fixed.", "Information", MB_OK + MB_ICONINFORMATION);
- }
- else
- {
- if (Err == xerNotAZipFile)
- {
- Application->MessageBox("The specified Zip file is too corrupted to be fixed.", "Information", MB_OK + MB_ICONINFORMATION);
- }
- else
- {
- // Some other error, pass it to the error handling routine.
- HandleError(Err, "fixing", MainXz);
-
- MainFormFm->MainXz->ZipFilename = "";
- }
- }
- }
- EnableInterface(true);
- }
- //
- // The following procedure handles the OnInsertdisk event, which occurs when
- // multidisk mode is activated and the component requires another disk to
- // be inserted. This procedure simply informs the user to insert the right
- // disk (depending on the lDisknumber parameter, and waits for the user to
- // press OK...
- //
- void __fastcall TMainFormFm::MainXzInsertDisk(TObject *Sender,
- long lDiskNumber, TOLEBOOL *bDiskInserted)
- {
-
- int response;
- AnsiString msg;
-
- if (lDiskNumber == 0)
- {
- msg = "Please insert the last disk of the set.";
- }
- else
- {
- msg = "Please insert disk #" + AnsiString(lDiskNumber) + " of the set.";
- }
- response = Application->MessageBox(msg.c_str(), "Confirmation", MB_OKCANCEL + MB_ICONQUESTION);
-
- if (response == IDOK)
- {
- // C++Builder 4 creates a rather strange
- // "void *bDiskInserted_which_is_really_a_Ptr_to_TOLEBOOL"
- // First, their naming is real ugly. Second, it's a VARIANT_BOOL, not a
- // TOLEBOOL object. It can be faked as a TOLEBOOL, but it's dangerous.
- *( VARIANT_BOOL* )bDiskInserted = VARIANT_TRUE;
- }
- }
-
- //
- // The MainXzReplace procedure is an event handler for the OnReplace event
- // generated by the TXceedZip component whenever a file that is being extracted
- // may overwrite an already existing file. This procedure displays a message box
- // to allow the user to decide to skip the file or not. Notes: The Overwrite
- // property must be set to xowAsk for the OnReplace event to occur. Also, the
- // choice to rename the file could also be given, as well as the choice of always
- // overwriting or never overwriting. See 'OnReplace' in the online help.
- //
- void __fastcall TMainFormFm::MainXzReplacingFile(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)
- {
- int UserAnswer;
- AnsiString msg;
-
- msg = WideString("The file '") + sFilename + "' already exists. Do you want to replace this file?";
- UserAnswer = Application->MessageBox(msg.c_str(), "Confirmation", MB_YESNOCANCEL + MB_ICONWARNING);
-
- switch( UserAnswer )
- {
- case IDYES:
- // Tell the TXceedZipProxy component to replace this file.
- *( VARIANT_BOOL* )bReplaceFile = VARIANT_TRUE;
- break;
-
- case IDNO:
- // Tell the TXceedZipProxy component to skip this file.
- *( VARIANT_BOOL* )bReplaceFile = VARIANT_FALSE;
- break;
-
- default:
- // Tell the XceedZip component to stop the entire operation. }
- MainXz->Abort = true;
- }
- }
- //---------------------------------------------------------------------------
-
-