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

  1. unit Fzip;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, azip, StdCtrls, Buttons, addzipu;
  8.  
  9. type
  10.   TfrmZIP = class(TForm)
  11.     lblInfo: TLabel;
  12.     btnCancel: TSpeedButton;
  13.     btnOK: TSpeedButton;
  14.     edtHidden: TEdit;
  15.     procedure FormShow(Sender: TObject);
  16.     procedure btnCancelClick(Sender: TObject);
  17.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  18.     procedure btnOKClick(Sender: TObject);
  19.     procedure edtHiddenChange(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     procedure DOZip;
  23.     function Trim(s : string) : string;
  24.   public
  25.     { Public declarations }
  26.   end;
  27.  
  28. var
  29.   frmZIP: TfrmZIP;
  30.   iDoZIP : Integer;
  31.   {$IFDEF WIN32}
  32.   sArchiveName : String[255];
  33.   {$ELSE}
  34.   sArchiveName : String[128];
  35.   {$ENDIF}
  36.  
  37. implementation
  38.  
  39. uses zwiz;
  40.  
  41. {$R *.DFM}
  42.  
  43. procedure TfrmZIP.FormShow(Sender: TObject);
  44. var
  45.    I : Integer;
  46. begin
  47.     I := addZIP_SetWindowHandle(edtHidden.Handle);
  48.     frmZIP.Caption := 'Confirm';
  49.     lblInfo.Caption := 'You are about to start creating the archive. Press OK to proceed, Cancel to quit.';
  50.     iDoZIP := 1;
  51. end;
  52.  
  53. procedure TfrmZIP.btnCancelClick(Sender: TObject);
  54. begin
  55.    Close;  
  56. end;
  57.  
  58. procedure TfrmZIP.FormClose(Sender: TObject; var Action: TCloseAction);
  59. begin
  60.    Action := caFree;
  61. end;
  62.  
  63. procedure TfrmZIP.btnOKClick(Sender: TObject);
  64. begin
  65.     Caption := 'Compressing...';
  66.     btnOK.Visible := False;
  67.     btnCancel.Left := ((Width - btnCancel.Width) div 2);
  68.     btnCancel.Enabled := False;
  69.     DoZIP;
  70.     frmZIP.Caption := 'Finished';
  71.     lblInfo.Caption := 'Finished';
  72.     btnCancel.Caption := '&OK';
  73.     btnCancel.Enabled := True;
  74.  
  75. end;
  76.  
  77. procedure TfrmZIP.edtHiddenChange(Sender: TObject);
  78. var
  79.    sFile, cAdditem, cAction : String;
  80.    lSize : LongInt;
  81.    iWidth, Selector : Integer;
  82. begin
  83.     cAction := GetAction((edtHidden.Text));
  84.     If LowerCase(Trim(cAction)) = 'copying' then
  85.        Selector := 1
  86.     Else If LowerCase(Trim(cAction)) = 'deleting' then
  87.        Selector := 2
  88.     Else If LowerCase(Trim(cAction)) = 'error' then
  89.        Selector := 3
  90.     Else If LowerCase(Trim(cAction)) = 'warning' then
  91.        Selector := 4
  92.     Else If LowerCase(Trim(cAction)) = 'zipping' then
  93.        Selector := 5;
  94.  
  95.     Case Selector of
  96.         1 : begin
  97.             {copying}
  98.             end;
  99.         2 : begin
  100.             {error}
  101.             end;
  102.         3 : begin
  103.             {warning}
  104.             end;
  105.         4 : begin
  106.             {comment}
  107.             end;
  108.         5 : begin
  109.             {zipping}
  110.             sFile := 'Compressing ' + GetFileName((edtHidden.Text));
  111.             sFile := sFile + ' - ' + (GetPercentComplete((edtHidden.Text)));
  112.             lblInfo.Caption := sFile;
  113.             lblInfo.update;
  114.             end;
  115.     end;
  116. end;
  117.  
  118. procedure TfrmZIP.DOZip;
  119. var
  120.    {$IFDEF WIN32}
  121.    sTempFile : String[255];
  122.    {$ELSE}
  123.    sTempFile : String[128];
  124.    {$ENDIF}
  125.    pPassWord, pTempFile, pArchiveName, pFiles : PChar;
  126.    I : Integer;
  127. begin
  128.  
  129.    pFiles := StrAlloc(65526);
  130.    {$IFDEF WIN32}
  131.    pArchiveName := StrAlloc(255);
  132.    pTempFile := StrAlloc(255);
  133.    {$ELSE}
  134.    pArchiveName := StrAlloc(127);
  135.    pTempFile := StrAlloc(127);
  136.    {$ENDIF}
  137.  
  138.     { Set the name of the archive}
  139.     StrPCopy(pArchiveName, sArchiveName);
  140.     I := addZIP_ArchiveName(pArchiveName);
  141.  
  142.     pFiles := '';
  143.     { Create pipe-delimited list of files and call the appropriate function}
  144.     For I := 0 To frmWizard.lstSelected.Items.Count - 1 do
  145.         begin
  146.            sTempFile := Trim(frmWizard.lstSelected.Items[I]) + '|';
  147.            StrPCopy(pTempFile, sTempFile);
  148.            StrCat(pFiles, pTempFile);
  149.         end;
  150.  
  151.     I := addZIP_Include(pFiles);
  152.  
  153.     If (frmWizard.radPathYes.Checked = True) Then
  154.         I := addZIP_SaveStructure(SAVE_ABSOLUTE_PATH)
  155.     Else
  156.         I := addZIP_SaveStructure(SAVE_FILENAME_ONLY);
  157.  
  158.     If (frmWizard.radPasswordYes.Checked = True) Then
  159.        begin
  160.           pPassWord := StrAlloc(Length(frmWizard.edtPassword.Text) + 1);
  161.           StrPCopy(pPassWord, frmWizard.edtPassword.Text);
  162.           I := addZIP_Encrypt(pPassword);
  163.           StrDispose(pPassWord);
  164.        end;
  165.  
  166.     If (frmWizard.radCompressNone.Checked = True) Then
  167.         I := addZIP_SetCompressionLevel(COMPRESSION_NONE)
  168.     Else If (frmWizard.radCompressMinimum.Checked = True) Then
  169.         I := addZIP_SetCompressionLevel(COMPRESSION_MINIMUM)
  170.     Else If (frmWizard.radCompressNormal.Checked = True) Then
  171.         I := addZIP_SetCompressionLevel(COMPRESSION_NORMAL)
  172.     Else
  173.         I := addZIP_SetCompressionLevel(COMPRESSION_MAXIMUM);
  174.  
  175.     If (frmWizard.radMultiYes.Checked = True) Then
  176.         I := addZIP_Span(True)
  177.     Else
  178.         I := addZIP_Span(False);
  179.  
  180.     If (frmWizard.radLFNYes.Checked = True) Then
  181.         I := addZIP_UseLFN(True)
  182.     Else
  183.         I := addZIP_UseLFN(False);
  184.  
  185.     If (frmWizard.radCommentYes.Checked = True) Then
  186.        begin
  187.           I := addZIP_Comment(frmWizard.mmoComment.Lines.GetText);
  188.        end;
  189.  
  190.     I := addZIP;
  191.  
  192.     StrDispose(pFiles);
  193.     StrDispose(pArchiveName);
  194.     StrDispose(pTempFile);
  195. end;
  196.  
  197. function TfrmZIP.Trim(s : string) : string;
  198. var
  199.   sLen : byte absolute s;
  200. begin
  201.   while (sLen>0) and (s[1] in [' ',^I]) do
  202.     Delete(s,1,1);
  203.  
  204.   while (sLen>0) and (s[sLen] in [' ',^I]) do
  205.     Dec(sLen);
  206.  
  207.   result:=s;
  208. end;
  209.  
  210. end.
  211.