home *** CD-ROM | disk | FTP | other *** search
/ BUG 6 / BUGCD1997_09.BIN / UTIL / ADDZIP / ADDZIP.EXE / DELPHI / ZIPWIZ / ZWIZ.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1997-06-01  |  12.9 KB  |  501 lines

  1. unit Zwiz;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, FileCtrl, azip, fZip;
  8.  
  9. type
  10.   TfrmWizard = class(TForm)
  11.     imgWizard: TImage;
  12.     grpStep1: TGroupBox;
  13.     lblArchiveName: TLabel;
  14.     edtArchive: TEdit;
  15.     shpLine: TShape;
  16.     btnCancel: TSpeedButton;
  17.     btnBack: TSpeedButton;
  18.     btnNext: TSpeedButton;
  19.     btnFinish: TSpeedButton;
  20.     btnBrowse: TSpeedButton;
  21.     grpStep2: TGroupBox;
  22.     grpStep3: TGroupBox;
  23.     grpStep4: TGroupBox;
  24.     grpStep5: TGroupBox;
  25.     GroupBox1: TGroupBox;
  26.     grpPassword: TGroupBox;
  27.     grpCompression: TGroupBox;
  28.     radPathNo: TRadioButton;
  29.     radPathYes: TRadioButton;
  30.     radPasswordYes: TRadioButton;
  31.     radPasswordNo: TRadioButton;
  32.     lblPassword: TLabel;
  33.     edtPassword: TEdit;
  34.     radCompressNone: TRadioButton;
  35.     radCompressMinimum: TRadioButton;
  36.     radCompressNormal: TRadioButton;
  37.     radCompressMaximum: TRadioButton;
  38.     lblFiles: TLabel;
  39.     lstFiles: TFileListBox;
  40.     dirFiles: TDirectoryListBox;
  41.     drvFiles: TDriveComboBox;
  42.     btnAdd: TSpeedButton;
  43.     btnRemove: TSpeedButton;
  44.     lstSelected: TListBox;
  45.     grpMultiDisk: TGroupBox;
  46.     radMultiNo: TRadioButton;
  47.     radMultiYes: TRadioButton;
  48.     grpLFN: TGroupBox;
  49.     radLFNYes: TRadioButton;
  50.     radLFNNo: TRadioButton;
  51.     grpComment: TGroupBox;
  52.     radCommentNo: TRadioButton;
  53.     radCommentYes: TRadioButton;
  54.     mmoComment: TMemo;
  55.     mmoSummary: TMemo;
  56.     procedure btnCancelClick(Sender: TObject);
  57.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  58.     procedure FormShow(Sender: TObject);
  59.     procedure btnBackClick(Sender: TObject);
  60.     procedure btnNextClick(Sender: TObject);
  61.     procedure edtArchiveChange(Sender: TObject);
  62.     procedure btnFinishClick(Sender: TObject);
  63.     procedure btnAddClick(Sender: TObject);
  64.     procedure btnRemoveClick(Sender: TObject);
  65.     procedure lstFilesClick(Sender: TObject);
  66.     procedure dirFilesChange(Sender: TObject);
  67.     procedure radCommentNoClick(Sender: TObject);
  68.     procedure radCommentYesClick(Sender: TObject);
  69.     procedure radPasswordNoClick(Sender: TObject);
  70.     procedure radPasswordYesClick(Sender: TObject);
  71.     procedure btnBrowseClick(Sender: TObject);
  72.   private
  73.     { Private declarations }
  74.     procedure AlignGroups;
  75.     procedure HideGroup(GroupNum : Integer);
  76.     procedure ShowGroup(GroupNum : Integer);
  77.     Function CheckFloppyDrives (cFileName : String) : Boolean;
  78.     procedure DisplaySummary;
  79.     function Trim(s : string) : string;
  80.     procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GetMinMaxInfo;
  81.   public
  82.     { Public declarations }
  83.   end;
  84.  
  85. var
  86.   frmWizard: TfrmWizard;
  87.   m_iStep : Integer;
  88.  
  89.   Const m_cMaxSteps = 5;
  90.  
  91. implementation
  92.  
  93. {$R *.DFM}
  94.  
  95. procedure TfrmWizard.btnCancelClick(Sender: TObject);
  96. begin
  97.    Close;
  98. end;
  99.  
  100. procedure TfrmWizard.FormClose(Sender: TObject; var Action: TCloseAction);
  101. begin
  102.    Action := caFree;
  103. end;
  104.  
  105. procedure TfrmWizard.FormShow(Sender: TObject);
  106. var
  107.    I: Integer;
  108. begin
  109.  
  110.     I := addZIP_SetParentWindowHandle(frmWizard.Handle);
  111.     m_iStep := 1;
  112.     AlignGroups;
  113.     grpStep1.Visible := True;
  114.     grpStep2.Visible := False;
  115.     grpStep3.Visible := False;
  116.     grpStep4.Visible := False;
  117.     grpStep5.Visible := False;
  118.     mmoSummary.Color := clBtnFace;
  119.  
  120. end;
  121.  
  122. procedure TfrmWizard.AlignGroups;
  123. begin
  124.    grpStep2.Top := GrpStep1.Top;
  125.    grpStep2.Left := GrpStep1.Left;
  126.    grpStep2.Width := GrpStep1.Width;
  127.    grpStep2.Height := GrpStep1.height;
  128.    grpStep3.Top := GrpStep1.Top;
  129.    grpStep3.Left := GrpStep1.Left;
  130.    grpStep3.Width := GrpStep1.Width;
  131.    grpStep3.Height := GrpStep1.height;
  132.    grpStep4.Top := GrpStep1.Top;
  133.    grpStep4.Left := GrpStep1.Left;
  134.    grpStep4.Width := GrpStep1.Width;
  135.    grpStep4.Height := GrpStep1.height;
  136.    grpStep5.Top := GrpStep1.Top;
  137.    grpStep5.Left := GrpStep1.Left;
  138.    grpStep5.Width := GrpStep1.Width;
  139.    grpStep5.Height := GrpStep1.height;
  140.  
  141. end;
  142.  
  143. procedure TfrmWizard.btnBackClick(Sender: TObject);
  144. begin
  145.     If (m_iStep > 1) Then
  146.        begin
  147.           HideGroup(m_iStep);
  148.           If (m_iStep = m_cMaxSteps) Then
  149.               btnNext.Enabled := True;
  150.           m_iStep := m_iStep - 1;
  151.           If (m_iStep = 1) Then
  152.               btnBack.Enabled := False;
  153.           ShowGroup(m_iStep);
  154.        End;
  155.  
  156. end;
  157.  
  158. procedure TfrmWizard.HideGroup(GroupNum : Integer);
  159. begin
  160.   case GroupNum of { which group to disable }
  161.   1 : begin
  162.          grpStep1.Visible := False
  163.       end;
  164.   2 : begin
  165.          grpStep2.Visible := False
  166.       end;
  167.   3 : begin
  168.          grpStep3.Visible := False
  169.       end;
  170.   4 : begin
  171.          grpStep4.Visible := False
  172.       end;
  173.   5 : begin
  174.          grpStep5.Visible := False
  175.       end;
  176.   end; { case }
  177. end;
  178.  
  179. procedure TfrmWizard.ShowGroup(GroupNum : Integer);
  180. begin
  181.   case GroupNum of { which group to disable }
  182.   1 : begin
  183.          grpStep1.Visible := True
  184.       end;
  185.   2 : begin
  186.          grpStep2.Visible := True
  187.       end;
  188.   3 : begin
  189.          grpStep3.Visible := True
  190.       end;
  191.   4 : begin
  192.          grpStep4.Visible := True
  193.       end;
  194.   5 : begin
  195.          grpStep5.Visible := True
  196.       end;
  197.   end; { case }
  198. end;
  199.  
  200. procedure TfrmWizard.btnNextClick(Sender: TObject);
  201. begin
  202.  
  203.  
  204.     If (m_iStep < m_cMaxSteps) Then
  205.        begin
  206.           HideGroup(m_iStep);
  207.           If (m_iStep = 1) Then
  208.               btnBack.Enabled := True;
  209.               If (Pos(':', edtArchive.Text) > 0) Then
  210.                  begin
  211.                     If CheckFloppyDrives(edtArchive.Text) = False Then
  212.                        begin
  213.                           grpMultiDisk.Enabled := False;
  214.                           radMultiNo.Enabled := False;
  215.                           radMultiYes.Enabled := False;
  216.                        end
  217.                     Else
  218.                         begin
  219.                            grpMultiDisk.Enabled := True;
  220.                            radMultiNo.Enabled := True;
  221.                            radMultiYes.Enabled := True;
  222.                         end
  223.                  end
  224.               Else
  225.                  begin
  226.                     grpMultiDisk.Enabled := False;
  227.                     radMultiNo.Enabled := False;
  228.                     radMultiYes.Enabled := False;
  229.                  End
  230.           End;
  231.           m_iStep := m_iStep + 1;
  232.           If (m_iStep = m_cMaxSteps) Then
  233.              begin
  234.                 btnNext.Enabled := False;
  235.                 DisplaySummary;
  236.              End;
  237.           ShowGroup(m_iStep);
  238.     End;
  239.  
  240.  
  241. Function TfrmWizard.CheckFloppyDrives (cFileName : String) : Boolean;
  242. var
  243.    {$IFDEF WIN32}
  244.    pFileName : PChar;
  245.    wResult : Word;
  246.    {$ELSE}
  247.    Drive : String;
  248.    DriveNumber, wResult : Word;
  249.    {$ENDIF}
  250. begin
  251.  
  252.    CheckFloppyDrives := False;
  253.  
  254.    {$IFDEF WIN32}
  255.    pFileName := StrAlloc(2);
  256.    StrPCopy(pFileName, Copy(UpperCase(cFileName), 1, 1));
  257.    wResult := GetDriveType(pFileName);
  258.    StrDispose(pFileName);
  259.    {$ELSE}
  260.    Drive := UpperCase(Copy(cFileName, 1, 1));
  261.    DriveNumber := Ord(Drive[1]) - 65;  {Drive must be upper case}
  262.    wResult := Word(GetDriveType(DriveNumber));
  263.    {$ENDIF}
  264.  
  265.    If wResult = DRIVE_REMOVABLE then
  266.       CheckFloppyDrives := True;
  267. End;
  268.  
  269. procedure TfrmWizard.DisplaySummary;
  270. var
  271.   sSummary : String;
  272.   I : Integer;
  273.   sFill : array[1..10] of Char;
  274. begin
  275.     sFill := '          ';
  276.     mmoSummary.Clear;
  277.  
  278.     sSummary := 'Compress the following ' + IntToStr(lstSelected.Items.Count) + ' file';
  279.     If (lstSelected.items.Count > 1) Then
  280.         sSummary := sSummary + 's';
  281.  
  282.     sSummary := sSummary + ' to the archive ' + edtArchive.Text + '.';
  283.  
  284.     mmoSummary.Lines.Add(sSummary);
  285.     mmoSummary.Lines.Add('');
  286.  
  287.     For I := 0 To lstSelected.items.Count - 1 do
  288.         begin
  289.            sSummary := sFill + lstSelected.Items[I];
  290.            mmoSummary.Lines.Add(sSummary);
  291.         end;
  292.  
  293.     mmoSummary.Lines.Add('');
  294.  
  295.     sSummary := 'Selected options ';
  296.     mmoSummary.Lines.Add(sSummary);
  297.  
  298.     If (radPathYes.Checked = True) Then
  299.         sSummary := sFill + 'Full path information saved'
  300.     Else
  301.         sSummary := sFill + 'Only filenames saved';
  302.  
  303.     mmoSummary.Lines.Add(sSummary);
  304.  
  305.     If (radPasswordYes.Checked = True) Then
  306.         sSummary := sFill + 'Files will be encrypted'
  307.     Else
  308.         sSummary := sFill + 'Files will not be encrypted';
  309.  
  310.     mmoSummary.Lines.Add(sSummary);
  311.  
  312.     If (radCompressNone.Checked = True) Then
  313.         sSummary := sFill + 'Files will be stored without compression'
  314.     Else If (radCompressMinimum.Checked = True) Then
  315.         sSummary := sFill + 'Files will hame minimum compressed'
  316.     Else If (radCompressNormal.Checked = True) Then
  317.         sSummary := sFill + 'Files will have normal compression'
  318.     Else
  319.         sSummary := sFill + 'Files will have maximum compression';
  320.  
  321.     mmoSummary.Lines.Add(sSummary);
  322.  
  323.     If (radMultiYes.Checked = True) Then
  324.         sSummary := sFill + 'Archive may span multiple disks'
  325.     Else
  326.         sSummary := sFill + 'Archive will not span disks';
  327.  
  328.     mmoSummary.Lines.Add(sSummary);
  329.  
  330.     If (radLFNYes.Checked = True) Then
  331.         sSummary := sFill + 'Long filenames will be stored'
  332.     Else
  333.         sSummary := sFill + 'Short (8.3) filenames will be stored';
  334.  
  335.     mmoSummary.Lines.Add(sSummary);
  336.  
  337.     If (radCommentYes.Checked = True) Then
  338.        begin
  339.           sSummary := sFill + 'Archive will have a comment added';
  340.           mmoSummary.Lines.Add(sSummary);
  341.        end;
  342. end;
  343.  
  344. procedure TfrmWizard.edtArchiveChange(Sender: TObject);
  345. begin
  346.     If (Length(edtArchive.Text) = 0) Then
  347.         btnNext.Enabled := False
  348.     Else
  349.         btnNext.Enabled := True;
  350. end;
  351.  
  352. {Supresses leading and trailing blanks}
  353. function TfrmWizard.Trim(s : string) : string;
  354. var
  355.   sLen : byte absolute s;
  356. begin
  357.   while (sLen>0) and (s[1] in [' ',^I]) do
  358.     Delete(s,1,1);
  359.  
  360.   while (sLen>0) and (s[sLen] in [' ',^I]) do
  361.     Dec(sLen);
  362.  
  363.   result:=s;
  364. end;
  365.  
  366. procedure TfrmWizard.btnFinishClick(Sender: TObject);
  367. begin
  368.    If (grpStep5.Visible = False) Then
  369.        begin
  370.           DisplaySummary;
  371.           HideGroup(m_iStep);
  372.           ShowGroup(m_cMaxSteps);
  373.           m_iStep := m_cMaxSteps;
  374.        End;
  375.    with TfrmZip.Create(Application) do
  376.    try
  377.       sArchiveName := edtArchive.Text;
  378.       ShowModal;
  379.    finally
  380.       Free;
  381.    end;
  382.    Close;
  383.  
  384. end;
  385.  
  386. procedure TfrmWizard.btnAddClick(Sender: TObject);
  387. var
  388.    sFilename : String;
  389. begin
  390.     sFilename := lstFiles.Filename;
  391.     lstSelected.Items.Add(LowerCase(sFilename));
  392.     If (lstSelected.items.Count = 1) Then
  393.        begin
  394.           btnNext.Enabled := True;
  395.           btnFinish.Enabled := True;
  396.           btnRemove.Enabled := True;
  397.        end;
  398.  
  399. end;
  400.  
  401. procedure TfrmWizard.btnRemoveClick(Sender: TObject);
  402. begin
  403.     lstSelected.Items.Delete(lstSelected.ItemIndex);
  404.     If (lstSelected.Items.Count = 0) Then
  405.        begin
  406.           btnNext.Enabled := False;
  407.           btnFinish.Enabled := False;
  408.           btnRemove.Enabled := False;
  409.        End;
  410.  
  411. end;
  412.  
  413. procedure TfrmWizard.lstFilesClick(Sender: TObject);
  414. begin
  415.    btnAdd.Enabled := True;
  416. end;
  417.  
  418. procedure TfrmWizard.dirFilesChange(Sender: TObject);
  419. begin
  420.    btnAdd.Enabled := False;
  421. end;
  422.  
  423. procedure TfrmWizard.radCommentNoClick(Sender: TObject);
  424. begin
  425.     If (radCommentNo.Checked = True) Then
  426.         mmoComment.Enabled := False;
  427. end;
  428.  
  429. procedure TfrmWizard.radCommentYesClick(Sender: TObject);
  430. begin
  431.     If (radCommentYes.Checked = True) Then
  432.        mmoComment.Enabled := True;
  433. end;
  434.  
  435. procedure TfrmWizard.radPasswordNoClick(Sender: TObject);
  436. begin
  437.     If (radPasswordNo.Checked = True) Then
  438.        begin
  439.           edtPassword.Enabled := False;
  440.           lblPassword.Enabled := False;
  441.        End;
  442. end;
  443.  
  444. procedure TfrmWizard.radPasswordYesClick(Sender: TObject);
  445. begin
  446.     If (radPasswordYes.Checked = True) Then
  447.        begin
  448.           edtPassword.Enabled := True;
  449.           lblPassword.Enabled := True;
  450.        End;
  451. end;
  452.  
  453. procedure TfrmWizard.btnBrowseClick(Sender: TObject);
  454. begin
  455.  
  456.    with TOpenDialog.Create(Self) do
  457.    try
  458.       Title := 'Enter a name for a .ZIP archive';
  459.       Filename := '';
  460.       InitialDir := ExtractFilepath(Application.ExeName);
  461.       DefaultExt := '.ZIP';
  462.       Filter := 'ZIP Files (*.ZIP)|*.ZIP|All Files (*.*)|*.*';
  463.       FilterIndex := 1;
  464.       HelpContext := 0;
  465.       Options := Options + [ofPathMustExist];
  466.  
  467.       if Execute then
  468.          begin
  469.             If Trim(Filename) <> '' Then
  470.                edtArchive.Text := Filename
  471.             Else
  472.                edtArchive.Text := '';
  473.          End
  474.       Else
  475.          edtArchive.Text := ''
  476.    finally
  477.      Free
  478.    end;
  479.  
  480. end;
  481.  
  482. procedure TfrmWizard.WMGetMinMaxInfo(var MSG: Tmessage);
  483. Begin
  484.   inherited;
  485.   with PMinMaxInfo(MSG.lparam)^ do
  486.   begin
  487.     with ptMaxTrackSize do
  488.     begin
  489.       X := 504;
  490.       Y := 420;
  491.     end;
  492.     with ptMinTrackSize do
  493.     begin
  494.       X := 504;
  495.       Y := 420;
  496.     end;
  497.   end;
  498. end;
  499.  
  500. end.
  501.