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

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, ShellAPI, AZIP, AUNZIP, Menus, Buttons, About, ExtCtrls, AddZipu;
  8.  
  9. type
  10.   TQuikZip = class(TForm)
  11.     txtZip: TEdit;
  12.     lstArchive: TListBox;
  13.     mnuMain: TMainMenu;
  14.     mnuArchive: TMenuItem;
  15.     mnuOptions: TMenuItem;
  16.     mnuHelp: TMenuItem;
  17.     mnuArchiveNew: TMenuItem;
  18.     mnuArchiveOpen: TMenuItem;
  19.     mnuArchiveSep1: TMenuItem;
  20.     mnuArchiveExit: TMenuItem;
  21.     mnuHelpAbout: TMenuItem;
  22.     mnuOptionsCompression: TMenuItem;
  23.     mnuOptionsStoreFull: TMenuItem;
  24.     mnuOptionsSep1: TMenuItem;
  25.     mnuOptionsExtractTo: TMenuItem;
  26.     mnuOptionsCompressionNone: TMenuItem;
  27.     mnuOptionsCompressionMinimum: TMenuItem;
  28.     mnuOptionsCompressionNormal: TMenuItem;
  29.     mnuOptionsCompressionMaximum: TMenuItem;
  30.     btnNew: TSpeedButton;
  31.     btnOpen: TSpeedButton;
  32.     btnDelete: TSpeedButton;
  33.     btnExtract: TSpeedButton;
  34.     btnView: TSpeedButton;
  35.     hdrArchive: THeader;
  36.     pnlStatusBar: TPanel;
  37.     mnuPopup: TPopupMenu;
  38.     mnuPopupSelectAll: TMenuItem;
  39.     mnuPopupDeselectAll: TMenuItem;
  40.     mnuPopupInvert: TMenuItem;
  41.     mnuPopupSep: TMenuItem;
  42.     mnuPopupExtract: TMenuItem;
  43.     mnuPopupView: TMenuItem;
  44.     mnuPopupDelete: TMenuItem;
  45.     mnuOptionsSep2: TMenuItem;
  46.     mnuOptionsOnTop: TMenuItem;
  47.     procedure FormShow(Sender: TObject);
  48.     procedure txtZipChange(Sender: TObject);
  49.     procedure mnuHelpAboutClick(Sender: TObject);
  50.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  51.     procedure btnOpenClick(Sender: TObject);
  52.     procedure mnuArchiveOpenClick(Sender: TObject);
  53.     procedure mnuOptionsStoreFullClick(Sender: TObject);
  54.     procedure lstArchiveDrawItem(Control: TWinControl; Index: Integer;
  55.       Rect: TRect; State: TOwnerDrawState);
  56.     procedure hdrArchiveSized(Sender: TObject; ASection, AWidth: Integer);
  57.     procedure mnuOptionsCompressionNormalClick(Sender: TObject);
  58.     procedure mnuOptionsCompressionNoneClick(Sender: TObject);
  59.     procedure mnuOptionsCompressionMinimumClick(Sender: TObject);
  60.     procedure mnuOptionsCompressionMaximumClick(Sender: TObject);
  61.     procedure FormResize(Sender: TObject);
  62.     procedure mnuOptionsExtractToClick(Sender: TObject);
  63.     procedure btnNewClick(Sender: TObject);
  64.     procedure mnuArchiveNewClick(Sender: TObject);
  65.     procedure mnuPopupPopup(Sender: TObject);
  66.     procedure mnuPopupSelectAllClick(Sender: TObject);
  67.     procedure mnuPopupDeselectAllClick(Sender: TObject);
  68.     procedure mnuPopupInvertClick(Sender: TObject);
  69.     procedure mnuOptionsOnTopClick(Sender: TObject);
  70.     procedure FormCreate(Sender: TObject);
  71.     procedure mnuPopupDeleteClick(Sender: TObject);
  72.     procedure btnDeleteClick(Sender: TObject);
  73.     procedure mnuPopupExtractClick(Sender: TObject);
  74.     procedure btnExtractClick(Sender: TObject);
  75.     procedure mnuPopupViewClick(Sender: TObject);
  76.     procedure btnViewClick(Sender: TObject);
  77.   private
  78.     { Private declarations }
  79.     function Trim(s: string): string;
  80.     function OpenArchive : Boolean;
  81.     procedure ListArchiveContents;
  82.     procedure AddFilesToArchive(pFile : PChar);
  83.     procedure UpdateStatusbar;
  84.     function GetItem(const sValue, sSep : String; const iItem : Integer): String;
  85.     Function GetPathName (CurrentPath : String) : String;
  86.     Function GetNewArchive : String;
  87.     procedure NewArchive;
  88.     procedure ProcessDroppedFiles(var MSG: Tmessage); message WM_DROPFILES;
  89.     procedure WMGetMinMaxInfo(var MSG: Tmessage); message WM_GetMinMaxInfo;
  90.     procedure DeleteFilesFromArchive;
  91.     procedure TopMostOn;
  92.     procedure TopMostOff;
  93.     procedure ExtractFilesFromArchive;
  94.     procedure ViewFiles;
  95.   public
  96.     { Public declarations }
  97.   end;
  98.  
  99. var
  100.   QuikZip: TQuikZip;
  101.   g_cArchiveName : PChar;
  102.   g_cExtract : String;
  103.   g_cTemp : String;
  104.   g_iCount : Integer; { the total number of files in the archive}
  105.   g_lSize : Longint;  { the total size (uncompressed) of the files in the archive}
  106.   g_iWidth : Integer;
  107.   g_iPathLen : Integer;
  108.  
  109. implementation
  110.  
  111. {$R *.DFM}
  112.  
  113. {Supresses leading and trailing blanks}
  114. function TQuikZip.Trim(s : string) : string;
  115. var
  116.   sLen : byte absolute s;
  117. begin
  118.   while (sLen>0) and (s[1] in [' ',^I]) do
  119.     Delete(s,1,1);
  120.  
  121.   while (sLen>0) and (s[sLen] in [' ',^I]) do
  122.     Dec(sLen);
  123.  
  124.   result:=s;
  125. end;
  126.  
  127. procedure TQuikZip.FormShow(Sender: TObject);
  128. var
  129.    i : integer;
  130. begin
  131.     {$IFDEF WIN32}
  132.        g_iPathLen := 255;
  133.     {$ELSE}
  134.        g_iPathLen := 127;
  135.     {$ENDIF}
  136.     I := addZIP_SetParentWindowHandle(QuikZip.Handle);
  137.     I := addUNZIP_SetParentWindowHandle(QuikZip.Handle);
  138.     I := addZIP_SetWindowHandle(txtZIP.handle);
  139.     I := addUNZIP_SetWindowHandle(txtZIP.handle);
  140.     g_cExtract := ExtractFilePath(Application.ExeName);
  141.     g_cArchiveName := StrAlloc(g_iPathLen);
  142.     TopMostOn;
  143. end;
  144.  
  145. procedure TQuikZip.txtZipChange(Sender: TObject);
  146. var
  147.    cAdditem, cAction : String;
  148.    lSize : LongInt;
  149.    iWidth, Selector : Integer;
  150. begin
  151.     cAction := GetAction((txtZIP.Text));
  152.     If LowerCase(Trim(cAction)) = 'view' then
  153.        Selector := 1
  154.     Else If LowerCase(Trim(cAction)) = 'error' then
  155.        Selector := 2
  156.     Else If LowerCase(Trim(cAction)) = 'warning' then
  157.        Selector := 3
  158.     Else If LowerCase(Trim(cAction)) = 'comment' then
  159.        Selector := 4;
  160.  
  161.     Case Selector of
  162.         1 : begin
  163.                If Trim(GetFileName((txtZIP.Text))) <> '' then
  164.                   begin
  165.                      cAdditem := GetFileName((txtZIP.Text)) + #9;
  166.                      iWidth := Pos(#9, cAdditem);
  167.                      If iWidth > g_iWidth then
  168.                          begin
  169.                             g_iWidth := iWidth;
  170.                             hdrArchive.SectionWidth[0] := g_iWidth * 7
  171.                          end;
  172.                      lSize := GetFileOriginalSize((txtZIP.Text));
  173.                      g_lSize := g_lSize + lSize;
  174.                      cAdditem := cAdditem + GetFileDate((txtZIP.Text)) + #9;
  175.                      cAdditem := cAdditem + GetFileTime((txtZIP.Text)) + #9;
  176.                      cAdditem := cAdditem + IntToStr(lSize) + #9;
  177.                      cAdditem := cAdditem + IntToStr(GetFileCompressedSize((txtZIP.Text))) + #9;
  178.                      cAdditem := cAdditem + GetFileCompressionRatio((txtZIP.Text)) + #9;
  179.                      cAdditem := cAdditem + GetFilePath((txtZIP.Text)) + #9;
  180.                      lstArchive.Items.Add(cAdditem);
  181.                      g_iCount := g_iCount + 1;
  182.                   end;
  183.             end;
  184.         2 : begin
  185.             {error}
  186.             end;
  187.         3 : begin
  188.             {warning}
  189.             end;
  190.         4 : begin
  191.             {comment}
  192.             end;
  193.     Else
  194.        begin
  195.           cAdditem := UpperCase(Trim(cAction)) + ' ' + GetFileName((txtZIP.Text));
  196.           cAdditem := cAdditem + ' - ' + GetFileCompressionRatio((txtZIP.Text));
  197.           pnlStatusBar.Caption := cAdditem;
  198.           pnlStatusBar.Update;
  199.        end;
  200.     end;
  201.  
  202. end;
  203.  
  204. procedure TQuikZip.mnuHelpAboutClick(Sender: TObject);
  205. begin
  206.    with TAboutBox.Create(Application) do
  207.    try
  208.       TopMostOff;
  209.       ShowModal;
  210.    finally
  211.       TopMostOn;
  212.       Free;
  213.    end;
  214. end;
  215.  
  216. procedure TQuikZip.FormClose(Sender: TObject; var Action: TCloseAction);
  217. begin
  218.    StrDispose(g_cArchiveName);
  219.    DragAcceptFiles(Handle, False);
  220.    Action := caFree;
  221. end;
  222.  
  223. Function TQuikZip.OpenArchive : Boolean;
  224. begin
  225.  
  226.    OpenArchive := False;
  227.  
  228.    TopMostOff;
  229.    with TOpenDialog.Create(Application) do
  230.    try
  231.       Filename := '*.ZIP';
  232.       InitialDir := ExtractFilePath(Application.Exename);
  233.       DefaultExt := '.ZIP';
  234.       Filter := 'ZIP Archives|*.zip';
  235.       FilterIndex := 1;
  236.       Title := 'Open Archive';
  237.       HelpContext := 0;
  238.       Options := Options + [ofFileMustExist];
  239.  
  240.       if Execute then
  241.          begin
  242.             g_iWidth := 15;
  243.             hdrArchive.SectionWidth[0] := g_iWidth * 6;
  244.             If Trim(Filename) <> '' Then
  245.                begin
  246.                   OpenArchive := True;
  247.                   StrPCopy (g_cArchiveName, Trim(Filename));
  248.                end;
  249.          end
  250.    finally
  251.      Free
  252.    end;
  253.    TopMostOn;
  254.  
  255. end;
  256.  
  257. procedure TQuikZip.ListArchiveContents;
  258. var
  259.    i : Integer;
  260. begin
  261.    QuikZip.Caption := 'QuickZIP - ' + StrPas(g_cArchiveName);
  262.    g_iCount := 0;
  263.    g_lSize := 0;
  264.    lstArchive.Clear;
  265.    Screen.Cursor := crHourglass;
  266.    i := addZIP_SetWindowHandle(txtZIP.handle);
  267.    i := addZIP_ArchiveName(g_cArchiveName);
  268.    i := addZIP_View(True);                                          
  269.    i := addZIP;
  270.    UpdateStatusBar;
  271.    Screen.Cursor := crDefault;
  272. end;
  273.  
  274. procedure TQuikZip.btnOpenClick(Sender: TObject);
  275. var
  276.    Result : Boolean;
  277. begin
  278.    Result := OpenArchive;
  279.    If Result = True then
  280.       ListArchiveContents;
  281. end;
  282.  
  283. procedure TQuikZip.mnuArchiveOpenClick(Sender: TObject);
  284. var
  285.    Result : Boolean;
  286. begin
  287.    Result := OpenArchive;
  288.    If Result = True then
  289.       ListArchiveContents;
  290. end;
  291.  
  292. procedure TQuikZip.AddFilesToArchive(pFile : PChar);
  293. var
  294.    i : Integer;
  295. begin
  296.     If (mnuOptionsCompressionNone.Checked = True) Then
  297.         i := addZIP_SetCompressionLevel(COMPRESSION_NONE)
  298.     Else If (mnuOptionsCompressionMinimum.Checked = True) Then
  299.         i := addZIP_SetCompressionLevel(COMPRESSION_MINIMUM)
  300.     Else If (mnuOptionsCompressionNormal.Checked = True) Then
  301.         i := addZIP_SetCompressionLevel(COMPRESSION_NORMAL)
  302.     Else
  303.         i := addZIP_SetCompressionLevel(COMPRESSION_MAXIMUM);
  304.  
  305.     If (mnuOptionsStoreFull.Checked = False) Then
  306.         i := addZIP_SaveStructure(SAVE_FILENAME_ONLY);
  307.  
  308.     Screen.Cursor := crHourglass;
  309.     i := addZIP_Include(pFile);
  310.     i := addZIP_ArchiveName(g_cArchiveName);
  311.     i := addZIP;
  312.     Screen.Cursor := crDefault;
  313. end;
  314.  
  315. procedure TQuikZip.mnuOptionsStoreFullClick(Sender: TObject);
  316. begin
  317.    mnuOptionsStoreFull.Checked := Not mnuOptionsStoreFull.Checked;
  318. end;
  319.  
  320. procedure TQuikZip.UpdateStatusBar;
  321. var
  322.    cStatus : String;
  323. begin
  324.     If (g_iCount > 0) Then
  325.        begin
  326.           cStatus := ' This archive contains ' + Format('%.0n', [Int(g_iCount)]) + ' files, ';
  327.           cStatus := cStatus + 'with a total uncompressed size of ' + Format('%.0n', [Int(g_lSize)]) + ' bytes';
  328.        end
  329.     Else
  330.        cStatus := '';
  331.     pnlStatusBar.Caption := cStatus;
  332. end;
  333.  
  334. procedure TQuikZip.lstArchiveDrawItem(Control: TWinControl; Index: Integer;
  335.   Rect: TRect; State: TOwnerDrawState);
  336. var
  337.   sText, sFile, sRatio, sPath : String;
  338.   lSize, lCompSize : Longint;
  339.   iOldRight : Integer;
  340.   sDate, sTime : String;
  341.   P : array[0..255] of Char;
  342. begin
  343.   {Based on code written by Arjen Broeze.}
  344.   with TListBox(Control) do
  345.    begin
  346.      sText := Items[Index];
  347.      sFile := GetItem(sText, #9, 1);
  348.      sDate := GetItem(sText, #9, 2);
  349.      sTime := GetItem(sText, #9, 3);
  350.      lSize := StrToInt(GetItem(sText, #9, 4));
  351.      lCompSize := StrToInt(GetItem(sText, #9, 5));
  352.      sRatio := GetItem(sText, #9, 6);
  353.      sPath := GetItem(sText, #9, 7);
  354.      with Canvas do
  355.       begin
  356.          FillRect(Rect);
  357.          StrPCopy(P, sFile);
  358.          DrawText(Handle, P, lstrlen(P), Rect, DT_LEFT or DT_SINGLELINE);
  359.          inc(Rect.left, hdrArchive.SectionWidth[0]);
  360.          StrPCopy(P, sDate);
  361.          DrawText(Handle, P, lstrlen(P), Rect, DT_LEFT or DT_SINGLELINE);
  362.          inc(Rect.left, hdrArchive.SectionWidth[1]);
  363.          StrPCopy(P, sTime);
  364.          DrawText(Handle, P, lstrlen(P), Rect, DT_LEFT or DT_SINGLELINE);
  365.          inc(Rect.left, hdrArchive.SectionWidth[2]);
  366.          StrPCopy(P, Format('%.0n', [Int(lSize)]));
  367.          iOldRight := Rect.Right;
  368.          Rect.right := Rect.left + hdrArchive.SectionWidth[3]-3;
  369.          DrawText(Handle, P, lstrlen(P), Rect, DT_RIGHT or DT_SINGLELINE);
  370.          inc(Rect.left, hdrArchive.SectionWidth[3]);
  371.          Rect.right := Rect.left + hdrArchive.SectionWidth[4]-3;
  372.          StrPCopy(P, sRatio);
  373.          DrawText(Handle, P, lstrlen(P), Rect, DT_RIGHT or DT_SINGLELINE);
  374.          inc(Rect.left, hdrArchive.SectionWidth[4]);
  375.          Rect.right := Rect.left + hdrArchive.SectionWidth[5]-3;
  376.          StrPCopy(P, Format('%.0n', [Int(lCompSize)]));
  377.          DrawText(Handle, P, lstrlen(P), Rect, DT_RIGHT or DT_SINGLELINE);
  378.          inc(Rect.left, hdrArchive.SectionWidth[5]+3);
  379.          Rect.Right := iOldRight;
  380.          StrPCopy(P, sPath);
  381.          DrawText(Handle, P, lstrlen(P), Rect, DT_LEFT or DT_SINGLELINE);
  382.       end;
  383.    end;
  384.  
  385. end;
  386.  
  387. function TQuikZip.GetItem(const sValue, sSep : String; const iItem : Integer): String;
  388. var
  389.   iPos,
  390.   iCount,
  391.   iSepLen : Integer;
  392.   sVal    : String;
  393. begin
  394.   sVal := sValue;
  395.   Result := '';
  396.   iSepLen := Length(sSep);
  397.   iCount := 1;
  398.   iPos := Pos(sSep, sValue);
  399.   while (iPos > 0) and (iCount < iItem) do
  400.    begin
  401.      inc(iCount);
  402.      sVal := Copy(sVal, iPos+iSepLen, Length(sVal));
  403.      iPos := Pos(sSep, sVal);
  404.    end;
  405.   if iCount = iItem then
  406.    begin
  407.      if iPos = 0 then
  408.       { last item }
  409.       Result := sVal
  410.      else
  411.       Result :=    Copy(sVal, 1, iPos-1);
  412.    end;
  413. end;
  414. procedure TQuikZip.hdrArchiveSized(Sender: TObject; ASection,
  415.   AWidth: Integer);
  416. begin
  417.    lstArchive.Repaint;
  418. end;
  419.  
  420. procedure TQuikZip.mnuOptionsCompressionNormalClick(Sender: TObject);
  421. begin
  422.    mnuOptionsCompressionNormal.Checked := not mnuOptionsCompressionNormal.Checked;
  423.    If mnuOptionsCompressionNormal.Checked = True then
  424.       begin
  425.          mnuOptionsCompressionNone.Checked := False;
  426.          mnuOptionsCompressionMinimum.Checked := False;
  427.          mnuOptionsCompressionMaximum.Checked := False;
  428.       end;
  429. end;
  430.  
  431. procedure TQuikZip.mnuOptionsCompressionNoneClick(Sender: TObject);
  432. begin
  433.    mnuOptionsCompressionNone.Checked := not mnuOptionsCompressionNone.Checked;
  434.    If mnuOptionsCompressionNone.Checked = True then
  435.       begin
  436.          mnuOptionsCompressionNormal.Checked := False;
  437.          mnuOptionsCompressionMinimum.Checked := False;
  438.          mnuOptionsCompressionMaximum.Checked := False;
  439.       end;
  440. end;
  441.  
  442. procedure TQuikZip.mnuOptionsCompressionMinimumClick(Sender: TObject);
  443. begin
  444.    mnuOptionsCompressionMinimum.Checked := not mnuOptionsCompressionMinimum.Checked;
  445.    If mnuOptionsCompressionMinimum.Checked = True then
  446.       begin
  447.          mnuOptionsCompressionNone.Checked := False;
  448.          mnuOptionsCompressionNormal.Checked := False;
  449.          mnuOptionsCompressionMaximum.Checked := False;
  450.       end;
  451. end;
  452.  
  453. procedure TQuikZip.mnuOptionsCompressionMaximumClick(Sender: TObject);
  454. begin
  455.    mnuOptionsCompressionMaximum.Checked := not mnuOptionsCompressionMaximum.Checked;
  456.    If mnuOptionsCompressionMaximum.Checked = True then
  457.       begin
  458.          mnuOptionsCompressionNone.Checked := False;
  459.          mnuOptionsCompressionMinimum.Checked := False;
  460.          mnuOptionsCompressionNormal.Checked := False;
  461.       end;
  462. end;
  463.  
  464. procedure TQuikZip.FormResize(Sender: TObject);
  465. begin
  466.    pnlStatusBar.Top := Height - pnlStatusbar.Height - 48;
  467.    pnlStatusBar.Width := Width - 8;
  468.    lstArchive.Height := pnlStatusBar.Top - lstArchive.Top - 5;
  469.    hdrArchive.Width := Width - 8;
  470.    lstArchive.Width := Width - 8;
  471. end;
  472.  
  473. procedure TQuikZip.mnuOptionsExtractToClick(Sender: TObject);
  474. var
  475.    sResult : String;
  476. begin
  477.    sResult := GetpathName(g_cExtract);
  478.    If Trim(sresult) <> '' Then
  479.       g_cExtract := sResult;
  480. end;
  481.  
  482. Function TQuikZip.GetPathName (CurrentPath : String) : String;
  483. var
  484.    DirPath, sTempFilepath : String;
  485.    iEndPos : Integer;
  486. begin
  487.  
  488.    If Trim(CurrentPath) <> '' Then
  489.        DirPath := Trim(CurrentPath)
  490.    Else
  491.        DirPath := 'C:\';
  492.  
  493.    TopMostOff;
  494.  
  495.    with TOpenDialog.Create(Self) do
  496.    try
  497.       Title := 'Set Extract Directory';
  498.       Filename := 'IGNOREME.TXT';
  499.       InitialDir := DirPath;
  500.       DefaultExt := '.TXT';
  501.       Filter := 'All Files (*.*)|*.*';
  502.       FilterIndex := 1;
  503.       HelpContext := 0;
  504.       Options := Options + [ofPathMustExist];
  505.  
  506.       if Execute then
  507.          begin
  508.             If Length(Filename) <= 12 Then
  509.                sTempFilepath := ''
  510.             Else
  511.                sTempFilepath := Filename;
  512.  
  513.             If Trim(sTempFilepath) <> '' Then
  514.                begin
  515.                   iEndPos := Pos('IGNOREME.TXT', UpperCase(sTempFilepath));
  516.                   If iEndPos <> 0 Then
  517.                       GetPathName := ExtractFilepath(sTempFilepath)
  518.                   Else
  519.                       GetPathName := CurrentPath;
  520.                end
  521.             Else
  522.                GetPathName := CurrentPath;
  523.          End
  524.       Else
  525.          GetPathName := CurrentPath
  526.    finally
  527.      Free
  528.    end;
  529.  
  530.    TopMostOn;
  531.  
  532. End;
  533.  
  534. Function TQuikZip.GetNewArchive : String;
  535. var
  536.    sTempFilepath : String;
  537. begin
  538.  
  539.  
  540.    TopMostOff;
  541.  
  542.    with TOpenDialog.Create(Self) do
  543.    try
  544.       Title := 'Enter a name for a .ZIP archive';
  545.       Filename := '';
  546.       InitialDir := ExtractFilepath(Application.ExeName);
  547.       DefaultExt := '.ZIP';
  548.       Filter := 'ZIP Files (*.ZIP)|*.ZIP|All Files (*.*)|*.*';
  549.       FilterIndex := 1;
  550.       HelpContext := 0;
  551.       Options := Options + [ofPathMustExist];
  552.  
  553.       if Execute then
  554.          begin
  555.             If Trim(Filename) <> '' Then
  556.                GetNewArchive := Filename
  557.             Else
  558.                GetNewArchive := '';
  559.          End
  560.       Else
  561.          GetNewArchive := ''
  562.    finally
  563.      Free
  564.    end;
  565.    TopMostOn;
  566.  
  567. End;
  568.  
  569. procedure TQuikZip.NewArchive;
  570. var
  571.    sResult : String;
  572. begin
  573.    sResult := GetNewArchive;
  574.    If Trim(sresult) <> '' then
  575.       begin
  576.          StrPCopy (g_cArchiveName, Trim(sResult));
  577.          ListArchiveContents;
  578.       end;
  579. end;
  580.  
  581. procedure TQuikZip.btnNewClick(Sender: TObject);
  582. begin
  583.    NewArchive;
  584. end;
  585.  
  586. procedure TQuikZip.mnuArchiveNewClick(Sender: TObject);
  587. begin
  588.    NewArchive;
  589. end;
  590.  
  591. procedure TQuikZip.mnuPopupPopup(Sender: TObject);
  592. begin
  593.    If (lstArchive.Items.Count > 0) Then
  594.       mnuPopupSelectAll.Enabled := True
  595.    else
  596.       mnuPopupSelectAll.Enabled := False;
  597.  
  598.    If (lstArchive.SelCount > 0) Then
  599.       begin
  600.          mnuPopupExtract.Enabled := True;
  601.          mnuPopupDelete.Enabled := True;
  602.          mnuPopupView.Enabled := True;
  603.          mnuPopupDeselectAll.Enabled := True;
  604.          mnuPopupInvert.Enabled := True;
  605.       end
  606.    else
  607.       begin
  608.          mnuPopupExtract.Enabled := False;
  609.          mnuPopupDelete.Enabled := False;
  610.          mnuPopupView.Enabled := False;
  611.          mnuPopupDeselectAll.Enabled := False;
  612.          mnuPopupInvert.Enabled := False;
  613.       end;
  614.  
  615. end;
  616.  
  617. procedure TQuikZip.mnuPopupSelectAllClick(Sender: TObject);
  618. var
  619.    i : Longint;
  620. begin
  621.    i := SendMessage(lstArchive.handle, LB_SELITEMRANGE, 1, MAKELONG(0 ,lstArchive.Items.Count -1));
  622. end;
  623.  
  624. procedure TQuikZip.mnuPopupDeselectAllClick(Sender: TObject);
  625. var
  626.    i : Longint;
  627. begin
  628.    i := SendMessage(lstArchive.handle, LB_SELITEMRANGE, 0, MAKELONG(0 ,lstArchive.Items.Count -1));
  629. end;
  630.  
  631. procedure TQuikZip.mnuPopupInvertClick(Sender: TObject);
  632. var
  633.    i : integer;
  634. begin
  635.    For I := 0 To (lstArchive.Items.Count - 1) do
  636.        lstArchive.Selected[I] := Not lstArchive.Selected[I];
  637. end;
  638.  
  639. procedure TQuikZip.mnuOptionsOnTopClick(Sender: TObject);
  640. begin
  641.     mnuOptionsOnTop.Checked := Not mnuOptionsOnTop.Checked;
  642.  
  643.     If mnuOptionsOnTop.Checked = True Then
  644.        SetWindowPos(QuikZip.Handle, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE))
  645.     Else
  646.        SetWindowPos(QuikZip.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE));
  647. end;
  648.  
  649. procedure TQuikZip.ProcessDroppedFiles(var MSG: Tmessage);
  650. var
  651.    I, iResult, iDotPos  : Integer;
  652.    {$IFDEF WIN32}
  653.    FileCount, wDrop : Integer;
  654.    {$ELSE}
  655.    FileCount, wDrop : Word;
  656.    {$ENDIF}
  657.    pFilename : PChar;
  658.    sTemp : String;
  659.    sExtension : String[4];
  660. Begin
  661.    pFileName := StrAlloc(g_iPathLen);
  662.  
  663.    {Retrieve the handle to the internal dropfiles structure}
  664.    wDrop := Msg.wParam;
  665.  
  666.    {Get the number of files}
  667.    {$IFDEF WIN32}
  668.    FileCount := DragQueryFile(wDrop, $FFFFFFFF, nil, 0);
  669.    {$ELSE}
  670.    FileCount := DragQueryFile(wDrop, $FFFF, nil, 0);
  671.    {$ENDIF}
  672.    For I := 0 To (FileCount - 1) do
  673.       begin
  674.          iResult := DragQueryFile(wDrop, I, pFilename, g_iPathLen);
  675.          If Copy(sTemp, Length(Trim(StrPas(pFilename))), 1) = '\' Then
  676.             StrCat(pFilename, '*.*');
  677.          {Make sure there is a '.' in the file name}
  678.          iDotPos := Pos('.', StrPas(pFilename));
  679.          If (iDotPos > 0) Then
  680.             begin
  681.                sExtension := ExtractFileExt(StrPas(pFilename));
  682.                If (FileCount = 1) And (LowerCase(sExtension) = '.zip') Then
  683.                   StrCopy(g_cArchiveName, pFilename)
  684.                Else
  685.                   AddFilesToArchive(pFilename);
  686.             end
  687.       end;
  688.    { Dispose of the wDrop structure}
  689.    DragFinish(wDrop);
  690.    ListArchiveContents;
  691.    StrDispose(pFileName);
  692.    inherited;
  693. end;
  694.  
  695. procedure TQuikZip.FormCreate(Sender: TObject);
  696. begin
  697.    DragAcceptFiles(Handle, True);
  698. end;
  699.  
  700. procedure TQuikZip.WMGetMinMaxInfo(var MSG: Tmessage);
  701. Begin
  702.    inherited;
  703.    with PMinMaxInfo(MSG.lparam)^ do
  704.    begin
  705.      with ptMinTrackSize do
  706.      begin
  707.        X := 560;
  708.        Y := 330;
  709.      end;
  710.    end;
  711. end;
  712.  
  713. procedure TQuikZip.DeleteFilesFromArchive;
  714. var
  715.    I, J, Button : Integer;
  716.    cMessage, cFilename : String;
  717.    pMessage, pFilename : PChar;
  718. begin
  719.    pMessage := StrAlloc(120);
  720.    pFileName := StrAlloc(g_iPathLen);
  721.    cMessage := 'Do you want to delete the ';
  722.    cMessage := cMessage + IntToStr(lstArchive.SelCount);
  723.    cMessage := cMessage + ' selected files from ';
  724.    cMessage := cMessage + StrPas(g_cArchiveName) + '?';
  725.    StrPCopy(pMessage, cMessage);
  726.    TopMostOff;
  727.    Button := Application.MessageBox(pMessage, 'Confirm', MB_YESNO + MB_ICONQUESTION +
  728.     mb_DefButton1);
  729.    if Button = IDYES then
  730.       begin
  731.          Screen.Cursor := crHourglass;
  732.          For J := 0 To (lstArchive.Items.Count - 1) do
  733.             If (lstArchive.Selected[J] <> False) Then
  734.                begin
  735.                   I := addZIP_ArchiveName(g_cArchiveName);
  736.                   cFilename := GetPiece((lstArchive.Items[J]), #9, 7);
  737.                   If (cFilename <> '') Then cFilename := cFilename + '/';
  738.                   cFilename := cFilename + GetPiece((lstArchive.Items[J]), #9, 1);
  739.                   StrPCopy(pFileName, cFileName);
  740.                   I := addZIP_Include(pFilename);
  741.                   I := addZIP_Delete(True);
  742.                   I := addZIP;
  743.                End;
  744.          Screen.Cursor := crDefault;
  745.       End;
  746.    TopMostOn;
  747.    ListArchiveContents;
  748.    StrDispose(pMessage);
  749.    StrDispose(pFileName);
  750. end;
  751.  
  752. procedure TQuikZip.mnuPopupDeleteClick(Sender: TObject);
  753. begin
  754.    DeleteFilesFromArchive;
  755. end;
  756.  
  757. procedure TQuikZip.btnDeleteClick(Sender: TObject);
  758. begin
  759.    DeleteFilesFromArchive;
  760. end;
  761.  
  762. procedure TQuikZip.TopMostOn;
  763. begin
  764.    If mnuOptionsOnTop.Checked = True Then
  765.       SetWindowPos(QuikZip.Handle, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE));
  766. end;
  767.  
  768. procedure TQuikZip.TopMostOff;
  769. begin
  770.    If mnuOptionsOnTop.Checked = True Then
  771.       SetWindowPos(QuikZip.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE));
  772. end;
  773.  
  774. procedure TQuikZip.ExtractFilesFromArchive;
  775. var
  776.    I, J, Button : Integer;
  777.    cMessage, cFilename : String;
  778.    pMessage, pFilename, pExtractTo : PChar;
  779. begin
  780.    pMessage := StrAlloc(120);
  781.    pFileName := StrAlloc(g_iPathLen);
  782.    pExtractTo := StrAlloc(g_iPathLen);
  783.    cMessage := 'Do you want to extract the ';
  784.    cMessage := cMessage + IntToStr(lstArchive.SelCount);
  785.    cMessage := cMessage + ' selected files from ';
  786.    cMessage := cMessage + StrPas(g_cArchiveName) + '?';
  787.    StrPCopy(pMessage, cMessage);
  788.    TopMostOff;
  789.    Button := Application.MessageBox(pMessage, 'Confirm', MB_YESNO + MB_ICONQUESTION +
  790.     mb_DefButton1);
  791.    if Button = IDYES then
  792.       begin
  793.          Screen.Cursor := crHourglass;
  794.          For J := 0 To (lstArchive.Items.Count - 1) do
  795.             If (lstArchive.Selected[J] <> False) Then
  796.                begin
  797.                   I := addUNZIP_ArchiveName(g_cArchiveName);
  798.                   cFilename := GetPiece((lstArchive.Items[J]), #9, 7);
  799.                   If (cFilename <> '') Then cFilename := cFilename + '/';
  800.                   cFilename := cFilename + GetPiece((lstArchive.Items[J]), #9, 1);
  801.                   StrPCopy(pFileName, cFileName);
  802.                   I := addUNZIP_Include(pFilename);
  803.                   StrPCopy(pExtractTo, g_cExtract);
  804.                   I := addUNZIP_ExtractTo(pExtractTo);
  805.                   I := addUNZIP;
  806.                End;
  807.          Screen.Cursor := crDefault;
  808.       End;
  809.    TopMostOn;
  810.    StrDispose(pMessage);
  811.    StrDispose(pFileName);
  812.    StrDispose(pExtractTo);
  813.    UpdateStatusBar;
  814. end;
  815.  
  816. procedure TQuikZip.mnuPopupExtractClick(Sender: TObject);
  817. begin
  818.    ExtractFilesFromArchive;
  819. end;
  820.  
  821. procedure TQuikZip.btnExtractClick(Sender: TObject);
  822. begin
  823.    ExtractFilesFromArchive;
  824. end;
  825.  
  826. procedure TQuikZip.ViewFiles;
  827. var
  828.    I, J, Button : Integer;
  829.    cFilename : String;
  830.    pFilename, pBuffer : PChar;
  831. begin
  832.    pFileName := StrAlloc(g_iPathLen);
  833.    pBuffer := StrAlloc(1000);
  834.    TopMostOff;
  835.    Screen.Cursor := crHourglass;
  836.    For J := 0 To (lstArchive.Items.Count - 1) do
  837.       If (lstArchive.Selected[J] <> False) Then
  838.          begin
  839.             I := addUNZIP_ArchiveName(g_cArchiveName);
  840.             cFilename := GetPiece((lstArchive.Items[J]), #9, 7);
  841.             If (cFilename <> '') Then cFilename := cFilename + '/';
  842.             cFilename := cFilename + GetPiece((lstArchive.Items[J]), #9, 1);
  843.             StrPCopy(pFileName, cFileName);
  844.             I := addUNZIP_Include(pFilename);
  845.             I := addUNZIP_ToMemory(pBuffer, 1000);
  846.             I := addUNZIP;
  847.             Button := Application.MessageBox(pBuffer, 'Viewing', MB_OK + MB_ICONINFORMATION +
  848.                    mb_DefButton1);
  849.          End;
  850.    Screen.Cursor := crDefault;
  851.    TopMostOn;
  852.    StrDispose(pFileName);
  853.    StrDispose(pBuffer);
  854.    UpdateStatusBar;
  855. end;
  856.  
  857. procedure TQuikZip.mnuPopupViewClick(Sender: TObject);
  858. begin
  859.    ViewFiles;
  860. end;
  861.  
  862. procedure TQuikZip.btnViewClick(Sender: TObject);
  863. begin
  864.    ViewFiles;
  865. end;
  866.  
  867. end.
  868.