unit ZipFileExplorer;

// (C) 1999-2000 Bjorn Braker //
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ComCtrls, LsFileExplorer26, Menus, Buttons, StdCtrls, FileCtrl,
  Grids, SortGrid, ZipMstr ;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    View1: TMenuItem;
    Tools1: TMenuItem;
    Help1: TMenuItem;
    Open1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    LargeIcon1: TMenuItem;
    SmallIcon1: TMenuItem;
    List1: TMenuItem;
    Detail1: TMenuItem;
    Cut1: TMenuItem;
    Copy1: TMenuItem;
    Paste1: TMenuItem;
    N4: TMenuItem;
    SelectAll1: TMenuItem;
    Panel1: TPanel;
    StatusBar1: TStatusBar;
    LsDirTree101: TLsDirTree10;
    LsFileListView261: TLsFileListView26;
    Splitter1: TSplitter;
    BtnExit: TSpeedButton;
    BtnAddFolder: TSpeedButton;
    BtnDeleteFolder: TSpeedButton;
    BtnEditFolder: TSpeedButton;
    BtnPrevLevel: TSpeedButton;
    BtnRefresh: TSpeedButton;
    BtnCut: TSpeedButton;
    BtnCopy: TSpeedButton;
    BtnPaste: TSpeedButton;
    BtnIcon: TSpeedButton;
    BtnSIcon: TSpeedButton;
    BtnList: TSpeedButton;
    BtnDetail: TSpeedButton;
    CbxShowFolder: TCheckBox;
    BtnSearch: TSpeedButton;
    DeleteFiles1: TMenuItem;
    RenameFile1: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    Refresh1: TMenuItem;
    FindFolderorFiles1: TMenuItem;
    GoTo1: TMenuItem;
    AboutLsFileExplorer261: TMenuItem;
    BtnGoTo: TSpeedButton;
    StringGrid1: TSortGrid;
    Splitter2: TSplitter;
    CloseArchive1: TMenuItem;
    DeleteArchive1: TMenuItem;
    NewArchive1: TMenuItem;
    ZipMaster1: TZipMaster;
    OpenDialog1: TOpenDialog;
    Actions1: TMenuItem;
    Add1: TMenuItem;
    Extract1: TMenuItem;
    Delete1: TMenuItem;
    View2: TMenuItem;
    N2: TMenuItem;
    SelectAll2: TMenuItem;
    InvertSelection1: TMenuItem;
    N3: TMenuItem;
    Options1: TMenuItem;
    N7: TMenuItem;
    ToolBar1: TMenuItem;
    Splitter3: TSplitter;
    OpenDialog2: TOpenDialog;
    OpenDialog3: TOpenDialog;

    procedure SetBtnMenuState(Sender: TObject);
    procedure GetStatistics(Sender: TObject);
    procedure BtnExitClick(Sender: TObject);
    procedure LsFileListView261DblClick(Sender: TObject);
    procedure BtnCutClick(Sender: TObject);
    procedure BtnCopyClick(Sender: TObject);
    procedure BtnPasteClick(Sender: TObject);
    procedure BtnIconClick(Sender: TObject);
    procedure BtnDetailClick(Sender: TObject);
    procedure BtnPrevLevelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CbxShowFolderClick(Sender: TObject);
    procedure BtnGoToClick(Sender: TObject);
    procedure LsFileListView261KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure BtnRefreshClick(Sender: TObject);
    procedure BtnAddFolderClick(Sender: TObject);
    procedure BtnDeleteFolderClick(Sender: TObject);
    procedure BtnEditFolderClick(Sender: TObject);
    procedure LsDirTree10ShortCuts1Click(Sender: TObject);
    procedure LsFileListView26ShortCuts1Click(Sender: TObject);
    procedure AboutLsFileExplorer261Click(Sender: TObject);
    procedure BtnSIconClick(Sender: TObject);
    procedure BtnListClick(Sender: TObject);
    procedure LsFileListView261Click(Sender: TObject);
    procedure LsFileListView261MouseUp(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BtnSearchClick(Sender: TObject);
    procedure LsFileListView261Change(Sender: TObject; Item: TListItem;
      Change: TItemChange);
    procedure DeleteFiles1Click(Sender: TObject);
    procedure RenameFile1Click(Sender: TObject);
    procedure SelectAll1Click(Sender: TObject);
    procedure NewArchive1Click(Sender: TObject);
    procedure ZipMaster1DirUpdate(Sender: TObject);
    procedure ZipMaster1Message(Sender: TObject; ErrCode: Integer;
      Message: String);
    procedure ZipMaster1Progress(Sender: TObject; ProgrType: ProgressType;
      Filename: String; FileSize: Integer);
    procedure DeleteArchive1Click(Sender: TObject);
    procedure CloseArchive1Click(Sender: TObject);
    procedure ToolBar1Click(Sender: TObject);
    procedure Delete1Click(Sender: TObject);
    procedure Extract1Click(Sender: TObject);
    procedure Add1Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
  private
    { Private declarations }
    CanPaste : Boolean;

  public
    { Public declarations }
     Procedure FillGrid;
  end;

var
  Form1: TForm1;
  ExtractDir: String;
  ExpandDirs: Boolean;
  OverWr: Boolean;
  AllFiles: Boolean;
  Canceled: Boolean;
  ZipFName: String;

implementation

{$R *.DFM}

uses About, msgunit, extrunit, Addunit;

Procedure TForm1.FillGrid;
var
  i: Integer;
begin
  with StringGrid1 do
  begin
    { Empty data from string grid }
    FixedRows:=0;
    RowCount:=1; { remove everything from grid except col titles }
    if ZipMaster1.Count = 0 then
       Exit;

    for i:=0 to ZipMaster1.Count-1 do
    begin
       RowCount := RowCount + 1;
       { We have to set fixed rows after the rowcount is more than 1}
       FixedRows:=1;
       with ZipDirEntry(ZipMaster1.ZipContents[i]^) do
       begin
          { The "-1" below is an offset for the row titles }
          Cells[0,RowCount-1] := FileName;
          Cells[1,RowCount-1] := IntToStr(CompressedSize);
          Cells[2,RowCount-1] := IntToStr(UncompressedSize);
          Cells[3,RowCount-1] := FormatDateTime('ddddd  t',FileDateToDateTime(DateTime));
       end; // end with
    end; // end for
  end; // end with
end;




procedure TForm1.FormCreate(Sender: TObject);
var
  CurDir : string;
begin
  CurDir := GetCurrentDir;
  if CurDir <> '' then
  begin
    LsFileListView261.Directory := CurDir;
    LsDirTree101.OpenPath(CurDir);
  end;
  SetBtnMenuState(Sender);
begin
  with StringGrid1 do
  begin
    { Make sure "goColMoving" is false in object inspector. This lets the
      TSortGrid use Mouse Clicks on the col headers. }
    FixedRows:=0;
    RowCount:=1;  { first row is fixed, and used for column headers }
    ColCount:=4;
    Cells[0,0] := 'File Name       (Click on a column header to sort)';
    Cells[1,0] := 'Compr Size';
    Cells[2,0] := 'Uncmpr Size';
    Cells[3,0] := 'Date/Time';
    ColWidths[0]:=316;
    ColWidths[1]:=84;
    ColWidths[2]:=84;
    ColWidths[3]:=120;
  end;
end;
end; //FormCreate

procedure TForm1.SetBtnMenuState(Sender: TObject);
begin
  BtnAddFolder.Enabled := Assigned(LsDirTree101.Selected);
  BtnDeleteFolder.Enabled := Assigned(LsDirTree101.Selected);
  BtnEditFolder.Enabled := Assigned(LsDirTree101.Selected);
  BtnCut.Enabled := Assigned(LsFileListView261.Selected);
  BtnCopy.Enabled := Assigned(LsFileListView261.Selected);
  BtnPaste.Enabled := (CanPaste = True);
  Cut1.Enabled := Assigned(LsFileListView261.Selected);
  Copy1.Enabled := Assigned(LsFileListView261.Selected);
  Paste1.Enabled := CanPaste = True;
//  Open1.Enabled := Assigned(LsFileListView261.Selected);
  DeleteFiles1.Enabled := Assigned(LsFileListView261.Selected);
  RenameFile1.Enabled := Assigned(LsFileListView261.Selected);
end; //SetBtnMenuState

procedure TForm1.GetStatistics(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := '';
  StatusBar1.Panels[1].Text := '';
  with LsFileListView261 do
  begin
    if Selected <> nil then
    begin
      StatusBar1.Panels[0].Text := IntToStr(Items.Count) + ' object(s)  --  ' +
        IntToStr(SelectedNumber) + '  selected ';
      StatusBar1.Panels[1].Text := ' Selected Size = ' +
        FormatFloat('###,##0.00 KB', (SelectedSize/1024)) +
        '( Disk free space: ' +
        FormatFloat('###,### MB', (DriveFreeSpace)) + ' )';
    end
    else begin
      StatusBar1.Panels[0].Text := IntToStr(Items.Count) + ' object(s)';
      StatusBar1.Panels[1].Text := ' Selected Size = 0 KB' +
        '  ( Disk free space: '+
        FormatFloat('###,### MB', (DriveFreeSpace)) + ' )';
    end;
  end;
end; //GetStatistics

procedure TForm1.BtnAddFolderClick(Sender: TObject);
var
  PNode     : TTreeNode;
  NewFolder : string;
begin
  with LsDirTree101 do
  begin
    NewFolder := '';
    PNode := Selected;
    if Assigned(Selected) then
    begin
//      if not InputQuery('Create New Folder',
//        'Enter the new folder name', NewFolder) then
//        exit;
//      LsDirTree101.AddNewNode(PNode, NewFolder);
      LsDirTree101.AddNewNode(PNode, '');
    end;
  end;
end; //BtnAddFolderClick

procedure TForm1.BtnDeleteFolderClick(Sender: TObject);
begin
  with LsDirTree101 do
  begin
    if (Selected <> nil) and (Assigned(Selected)) then
      DeleteNode(Selected);
  end;
end; //BtnDeleteFolderClick

procedure TForm1.BtnEditFolderClick(Sender: TObject);
begin
  with LsDirTree101 do
  begin
    if (Selected <> nil) and (Assigned(Selected)) then
      Selected.EditText;
  end;
end; //BtnEditFolderClick

procedure TForm1.BtnSearchClick(Sender: TObject);
begin
  LsFileListView261.SetFocus;
  LsFileListView261.FindFile;
end; //BtnSearchClick

procedure TForm1.BtnGoToClick(Sender: TObject);
var
  PathName: string;
begin
  InputQuery('Go to Folder', 'Enter the name and path of the folder to open',
             PathName);
  if (PathName = '') or (Length(PathName) = 1) then exit;
  if PathName[Length(PathName)] <> '\' then
    PathName := PathName + '\';
  if DirectoryExists(PathName) then
  begin
    LsFileListView261.Directory := PathName;
    LsDirTree101.OpenPath(PathName);
  end
  else begin
    if (Length(PathName) <= 3) and (PathName[2] = ':') then
      MessageDlg(UpperCase(PathName) + '  not ready', mtError, [mbOK], 0)
    else
      MessageDlg(PathName + '  not found', mtError, [mbOK], 0);
      exit;
  end;
end; //BtnSearchClick

procedure TForm1.LsFileListView261DblClick(Sender: TObject);
var
S: String;
begin
        if OpenDialog2.Execute then
        begin
                S := Opendialog2.Filename;
                Zipmaster1.ZipFilename := S;
   {   Title:='Open Existing ZIP File';
      Options:=Options+[ofHideReadOnly,ofShareAware,ofPathMustExist,ofFileMustExist];
      Filter :='ZIP Files (*.ZIP)|*.zip';
      if Execute then
      begin    }
//         ZipFName.Caption:=Filename;
//         ZipMaster1.ZipFileName:=LsFileListView261.SelectedItem;
      end;
end;
procedure TForm1.BtnCutClick(Sender: TObject);
begin
  LsFileListView261.CutCopy(2);
  Cut1.Enabled := False;
  CanPaste := True;
  SetBtnMenuState(Sender);
end; //BtnCutClick

procedure TForm1.BtnCopyClick(Sender: TObject);
begin
  LsFileListView261.CutCopy( 0 );
  Copy1.Enabled := False;
  CanPaste := True;
  SetBtnMenuState(Sender);
end; //BtnCopyClick

procedure TForm1.BtnPasteClick(Sender: TObject);
begin
  LsFileListView261.Paste;
  CanPaste := False;
  Cut1.Enabled := True;
  Copy1.Enabled := True;
  SetBtnMenuState(Sender);
end; //BtnPasteClick

procedure TForm1.BtnPrevLevelClick(Sender: TObject);
begin
  LsFileListView261.OneLevelUp;
  SetBtnMenuState(Sender);
end; //BtnPrevLevelClick

procedure TForm1.BtnRefreshClick(Sender: TObject);
var
  TreePath: string;
begin
  with LsDirTree101 do
  begin
    if (Selected <> nil) and  (Assigned(Selected)) then
      TreePath := SelectedPath;
    ReLoad;
    OpenPath(SelectedPath);
    LsFileListView261.Directory := SelectedPath;
    LsFileListView261.UpdateFileList;
  end;
end; //BtnRefreshClick

procedure TForm1.CbxShowFolderClick(Sender: TObject);
begin
  with CBxShowFolder do
  begin
    if Checked = True then
      LsFileListView261.ShowFolders := True
    else
      LsFileListView261.ShowFolders := False;
  end;
end; //CbxShowFolderClick

procedure TForm1.LsFileListView261MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  GetStatistics(Sender);
end; //LsFileListView261MouseUp

procedure TForm1.LsFileListView261KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_Return) or (key = VK_Space) or (Key = VK_BACK) then
    GetStatistics(Sender);
end; //LsFileListView261KeyUp

procedure TForm1.SelectAll1Click(Sender: TObject);
var
  i: integer;
begin
  if not Assigned(LsFileListView261) then exit;
  with LsFileListView261 do
  begin
    if Items.Count = 0 then exit;
    for i := 0 to Items.Count - 1  do
      Selected := Items[ i ];
  end;
end; //SelectAll1Click

procedure TForm1.LsDirTree10ShortCuts1Click(Sender: TObject);
begin

  AboutForm.ShowModal;
end; //LsDirTree10ShortCuts1Click

procedure TForm1.LsFileListView26ShortCuts1Click(Sender: TObject);
begin

  AboutForm.ShowModal;
end; //LsFileListView26ShortCuts1Click

procedure TForm1.AboutLsFileExplorer261Click(Sender: TObject);
begin

  AboutForm.ShowModal;
end; //AboutLsFileExplorer261Click

procedure TForm1.LsFileListView261Click(Sender: TObject);
begin
ZipMaster1.ZipFileName:=LsFileListView261.SelectedItem;//  SetBtnMenuState(Sender);
ZipFname := zipmaster1.ZipFilename;
end; //LsFileListView261Click

procedure TForm1.LsFileListView261Change(Sender: TObject; Item: TListItem;
  Change: TItemChange);
begin
  SetBtnMenuState(Sender);
end; //LsFileListView261Change

procedure TForm1.DeleteFiles1Click(Sender: TObject);
begin
  LsFileListView261.DeleteItems;
end; //DeleteFiles1Click

procedure TForm1.RenameFile1Click(Sender: TObject);
begin
  LsFileListView261.NewFolder;
end; //RenameFile1Click

procedure TForm1.BtnIconClick(Sender: TObject);
begin
  LsFileListView261.ViewStyle := vsIcon;
end; //BtnIconClick

procedure TForm1.BtnSIconClick(Sender: TObject);
begin
  LsFileListView261.ViewStyle := vsSmallIcon;
end; //BtnSIconClick

procedure TForm1.BtnListClick(Sender: TObject);
begin
  LsFileListView261.ViewStyle := vsList;
end; //BtnListClick

procedure TForm1.BtnDetailClick(Sender: TObject);
begin
  LsFileListView261.ViewStyle := vsReport;
end; //BtnDetailClick

procedure TForm1.BtnExitClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.NewArchive1Click(Sender: TObject);
var
   ans:Boolean;
begin
   with OpenDialog1 do
   begin
      Title:='Create New ZIP File';
      Options:=Options+[ofHideReadOnly,ofShareAware];
      Options:=Options-[ofPathMustExist,ofFileMustExist];
      Filter :='ZIP Files (*.ZIP)|*.zip';
      if Execute then
      begin
        if Pos('.zip', lowercase(Filename)) = 0 then
           FileName:=FileName+'.zip';
        if FileExists(FileName) then
        begin
           Ans:=MessageDlg('Overwrite Existing File: ' + FileName + '?',
                          mtConfirmation,[mbYes,mbNo],0)=mrYes;
           if Ans then
              DeleteFile(FileName)
           else
              Exit;  { Don't use the new name }
        end;
        ZipFName :=Filename;
        ZipMaster1.ZipFileName:=FileName;
      end;
   end; { end with }
end;
procedure TForm1.ZipMaster1DirUpdate(Sender: TObject);
begin
   FillGrid;
   //FilesLabel.Caption:=IntToStr(ZipMaster1.Count);
end;

procedure TForm1.ZipMaster1Message(Sender: TObject; ErrCode: Integer;
  Message: String);
begin
MsgForm.Memo1.Lines.Add(Message);
   if ErrCode > 0 then
      ShowMessage('Error Msg from DLL: ' + Message);
end;

procedure TForm1.ZipMaster1Progress(Sender: TObject;
  ProgrType: ProgressType; Filename: String; FileSize: Integer);
begin
begin
   if ProgrType = NewFile then
   begin
      {ShowMessage('in OnProgress type 1, size= ' + IntToStr(FileSize));}
      MsgForm.FileBeingZipped.Caption:=FileName;
      with MsgForm.ProgressBar1 do
      begin
         min:=1;    { first step }
         max:=10;   { reasonable value for now ... }
         step:=1;   { no. of steps for each "StepIt" }
         position:=min; { current position of bar }

         { Max is assigned the approximate # of callbacks }
         if (FileSize div 32768) > 1 then
            Max := FileSize div 32768  { total no of steps }
         else
            Max := 1;
         if (FileSize < 32768) then
            StepIt;   { max out progress for small files }
      end;
   end;

   if ProgrType = ProgressUpdate then
   begin
      {ShowMessage('in OnProgress type 2'); }
      with MsgForm.ProgressBar1 do
         if position < Max then
            StepIt;
   end;

   if ProgrType = EndOfBatch then
   begin
      { reset the progress bar and filename }
      {ShowMessage('In OnProgress type 3');}
      MsgForm.FileBeingZipped.Caption:='';
      with MsgForm.ProgressBar1 do
      begin
         min:=1;
         max:=10;
         step:=1;
         position:=min;
      end;
   end;
   Application.ProcessMessages;
end;

end;

procedure TForm1.DeleteArchive1Click(Sender: TObject);
var
Filename: string;
begin
        if OpenDialog3.Execute then
        begin
                Filename := OpenDialog3.Filename;
                windows.DeleteFile ('Filename');
        end;
end;

procedure TForm1.CloseArchive1Click(Sender: TObject);
begin
        StringGrid1.Clear;
end;

procedure TForm1.ToolBar1Click(Sender: TObject);
begin
        if ToolBar1.Checked = true then
        begin
                Toolbar1.Checked := False
        end
        else
        begin
                Toolbar1.Checked := True;
        end;
        if ToolBar1.Checked = true then Panel1.Show;
        if ToolBar1.Checked = False then Panel1.Hide;
end;
procedure TForm1.Delete1Click(Sender: TObject);
var
   i: Integer;
   Ans: Boolean;
begin
   with StringGrid1 do
   begin
      if (RowCount - 1) < 1 then
      begin
         ShowMessage('Error - no files to delete');
         Exit;
      end;
      Ans:=MessageDlg('Delete selected files from: '
        + ZipMaster1.ZipFileName + '?',
                   mtConfirmation,[mbYes,mbNo],0)=mrYes;
      if not Ans then
         Exit;
         
      ZipMaster1.FSpecArgs.Clear;
      for i := Selection.Top to Selection.Bottom do
      begin
         ZipMaster1.FSpecArgs.Add(Cells[0,i]);
        { ShowMessage('Selecting ' + Cells[0,i]); for debugging }
      end; { end for }

      if ZipMaster1.FSpecArgs.Count < 1 then
      begin
         ShowMessage('Error - no files selected');
         Exit;
      end;
   end; { end with }

   MsgForm.Memo1.Clear;
   MsgForm.Show;
   { Put this message into the message form's memo }
   ZipMaster1Message(self,0,'Beginning delete from ' + ZipMaster1.ZipFileName);

   ZipMaster1.Verbose:=True;
   ZipMaster1.Trace:=False;
   try
      ZipMaster1.Delete;
   except
      ShowMessage('Fatal error trying to delete');
   end;
   ShowMessage(IntToStr(ZipMaster1.SuccessCnt)+' files were Deleted');
end;

procedure TForm1.Extract1Click(Sender: TObject);
var
   i: Integer;
begin
  { if not FileExists(ZipFName) then
   begin
      ShowMessage('Error: file not found: ' + ZipFName);
      Exit;
   end;
   Extract.ShowModal;
   if (ExtractDir = '') or Canceled then
      Exit;  }
                             extract.showmodal;
   with StringGrid1 do
   begin
      if (RowCount - 1) < 1 then
      begin
         ShowMessage('Error - no files to extract');
         Exit;
      end;
      ZipMaster1.FSpecArgs.Clear;
      { Get fspecs of selected files, unless user wants all files extracted }
      if not AllFiles then
      begin
         for i := Selection.Top to Selection.Bottom do
         begin
            ZipMaster1.FSpecArgs.Add(Cells[0,i]);
          { ShowMessage('Selecting ' + Cells[0,i]); } { for debugging }
         end; { end for }
         if ZipMaster1.FSpecArgs.Count < 1 then
         begin
            ShowMessage('Error - no files selected');
            Exit;
         end;
      end;
   end; { end with }

   MsgForm.Memo1.Clear;
   MsgForm.Show;
   { Put this message into the message form's memo }
   ZipMaster1Message(self,0,'Beginning Extract from ' + ZipMaster1.ZipFileName);

   with ZipMaster1 do
   begin
      ExtrBaseDir:=ExtractDir;
      Verbose:=True;
      Trace:=False;
      ExtrOptions:=[];
      if ExpandDirs then
         ExtrOptions:=ExtrOptions+[ExtrDirNames];
      if Overwr then
         ExtrOptions:=ExtrOptions+[ExtrOverwrite];
      try
         Extract;
      except
         ShowMessage('Error in Extract; Fatal DLL Exception in mainunit');
      end;
      ShowMessage(IntToStr(SuccessCnt)+' files were extracted');
   end; { end with }
end;


procedure TForm1.Add1Click(Sender: TObject);
begin
 if ZipMaster1.ZipFileName = '' then
   begin
      ShowMessage('Error - open a zip file first');
      Exit;
   end;
   AddForm.Left:=Left;
   AddForm.Top:=Top;
   AddForm.Width:=Width;
   AddForm.Height:=Height;
   Canceled:=False;
   AddForm.ShowModal;  { let user pick filenames to add }
   if Canceled then
      Exit;
   if AddForm.SelectedList.Items.Count = 0 then
   begin
      ShowMessage('No files selected');
      Exit;
   end;
   MsgForm.Memo1.Clear;
   MsgForm.Show;
   { Put this message into the message form's memo }
   ZipMaster1Message(self,0,'Beginning Add to ' + ZipMaster1.ZipFileName);

   with ZipMaster1 do
   begin
      { We want any DLL error messages to show over the top
        of the message form. }
      Verbose:=True;
      Trace:=False;
      AddOptions:=[];
      if AddForm.RecurseCB.Checked then
         AddOptions:=AddOptions+[AddRecurseDirs];  { we want recursion }
      if AddForm.DirnameCB.Checked then
         AddOptions:=AddOptions+[AddDirNames];  { we want dirnames }
      FSpecArgs.Clear;
      FSpecArgs.Assign(AddForm.SelectedList.Items); { specify filenames }
      AddForm.SelectedList.Clear;
      try
         Add;
      except
         ShowMessage('Error in Add; Fatal DLL Exception in mainunit');
      end;
      ShowMessage(IntToStr(SuccessCnt)+' files were added');
   end; { end with }
end;


procedure TForm1.SpeedButton1Click(Sender: TObject);
var
   ans:Boolean;
begin
   with OpenDialog1 do
   begin
      Title:='Create New ZIP File';
      Options:=Options+[ofHideReadOnly,ofShareAware];
      Options:=Options-[ofPathMustExist,ofFileMustExist];
      Filter :='ZIP Files (*.ZIP)|*.zip';
      if Execute then
      begin
        if Pos('.zip', lowercase(Filename)) = 0 then
           FileName:=FileName+'.zip';
        if FileExists(FileName) then
        begin
           Ans:=MessageDlg('Overwrite Existing File: ' + FileName + '?',
                          mtConfirmation,[mbYes,mbNo],0)=mrYes;
           if Ans then
              DeleteFile(FileName)
           else
              Exit;  { Don't use the new name }
        end;
        ZipFName :=Filename;
        ZipMaster1.ZipFileName:=FileName;
      end;
   end; { end with }
end;
procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
 if ZipMaster1.ZipFileName = '' then
   begin
      ShowMessage('Error - open a zip file first');
      Exit;
   end;
   AddForm.Left:=Left;
   AddForm.Top:=Top;
   AddForm.Width:=Width;
   AddForm.Height:=Height;
   Canceled:=False;
   AddForm.ShowModal;  { let user pick filenames to add }
   if Canceled then
      Exit;
   if AddForm.SelectedList.Items.Count = 0 then
   begin
      ShowMessage('No files selected');
      Exit;
   end;
   MsgForm.Memo1.Clear;
   MsgForm.Show;
   { Put this message into the message form's memo }
   ZipMaster1Message(self,0,'Beginning Add to ' + ZipMaster1.ZipFileName);

   with ZipMaster1 do
   begin
      { We want any DLL error messages to show over the top
        of the message form. }
      Verbose:=True;
      Trace:=False;
      AddOptions:=[];
      if AddForm.RecurseCB.Checked then
         AddOptions:=AddOptions+[AddRecurseDirs];  { we want recursion }
      if AddForm.DirnameCB.Checked then
         AddOptions:=AddOptions+[AddDirNames];  { we want dirnames }
      FSpecArgs.Clear;
      FSpecArgs.Assign(AddForm.SelectedList.Items); { specify filenames }
      AddForm.SelectedList.Clear;
      try
         Add;
      except
         ShowMessage('Error in Add; Fatal DLL Exception in mainunit');
      end;
      ShowMessage(IntToStr(SuccessCnt)+' files were added');
   end; { end with }
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
 var
 i: Integer;
 begin{ if not FileExists(ZipFName) then
   begin
      ShowMessage('Error: file not found: ' + ZipFName);
      Exit;
   end;
   Extract.ShowModal;
   if (ExtractDir = '') or Canceled then
      Exit;  }
                             extract.show;
   with StringGrid1 do
   begin
      if (RowCount - 1) < 1 then
      begin
         ShowMessage('Error - no files to extract');
         Exit;
      end;
      ZipMaster1.FSpecArgs.Clear;
      { Get fspecs of selected files, unless user wants all files extracted }
      if not AllFiles then
      begin
         for i := Selection.Top to Selection.Bottom do
         begin
            ZipMaster1.FSpecArgs.Add(Cells[0,i]);
          { ShowMessage('Selecting ' + Cells[0,i]); } { for debugging }
         end; { end for }
         if ZipMaster1.FSpecArgs.Count < 1 then
         begin
            ShowMessage('Error - no files selected');
            Exit;
         end;
      end;
   end; { end with }

   MsgForm.Memo1.Clear;
   MsgForm.Show;
   { Put this message into the message form's memo }
   ZipMaster1Message(self,0,'Beginning Extract from ' + ZipMaster1.ZipFileName);

   with ZipMaster1 do
   begin
      ExtrBaseDir:=ExtractDir;
      Verbose:=True;
      Trace:=False;
      ExtrOptions:=[];
      if ExpandDirs then
         ExtrOptions:=ExtrOptions+[ExtrDirNames];
      if Overwr then
         ExtrOptions:=ExtrOptions+[ExtrOverwrite];
      try
         Extract;
      except
         ShowMessage('Error in Extract; Fatal DLL Exception in mainunit');
      end;
      ShowMessage(IntToStr(SuccessCnt)+' files were extracted');
   end; { end with }
end;
end.