⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 ziptv为delphi控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
Procedure TfrmMain.ListView1Click(Sender: TObject);
Begin
   DisplayTotals(Selected);
End;
//-------------------------------------------------------------
(* StatusBar's OnClick event -
   Display totals in the status bar for all files in list *)

Procedure TfrmMain.StatusBar1Click(Sender: TObject);
Begin
   DisplayTotals(TOTALS);
End;
//-------------------------------------------------------------
(* OnRead Event

  Shared by ZipTV1 and all compression components.

   * ZipTV1 fills List control with the compressed file info
   * The compression components access this OnRead event with
     compressed file info for each file 'added' to an archive.

*)

Procedure TfrmMain.ZipTV1Read(Sender: TObject; Offset, Filenum: Integer);
Var
   ZipCommon: TZipCommon;
   {$IFDEF ListView}
   NewItem: TListItem;
   {$ELSE}
   BuildString: AnsiString;             (* Long String *)
   {$ENDIF ListView}
Begin

   (* ZipCommon is the parent class to all ZipTV components.			*)
   (* Typecast the 'Sender' parameter as type TZipCommon to share		*)
   (* properties with all components.											*)
   ZipCommon := TZipCommon(Sender);

   {$IFDEF ListView}
   NewItem := ListView1.Items.Add;      (* Create a new row *)

   With NewItem Do
   Begin

      Data := Pointer(Offset);          (* for future use 		*)

      (* Add associated image to list.  The system image list  *)
      (* MUST first be initialized before using this property!	*)
      (* See method InitializeImageList.								*)
      ImageIndex := ztvSystemImageIndex(ZipCommon.FileName);

      Caption := ExtractFilename(ZipCommon.FileName); (* FileName property		*)
      With SubItems Do
      Begin

         Add(FormatDateTime('mm/dd/yy hh:mm am/pm', ZipCommon.Date));  (* Date property 			*)

         //one way...
       //Add( Format('%d kB', [ZipCommon.PackedSize]) );
         //...or another
         Add(IntToStr(ZipCommon.PackedSize)); (* PackedSize property 	*)

         //one way...
       //Add( Format('%d kB', [ZipCommon.UnpackedSize]) );
         //...or another
         Add(IntToStr(ZipCommon.UnpackedSize)); (* UnpackedSize property*)
         Add(IntToStr(ZipCommon.Ratio) + '%'); (* Ratio						*)

         Add(ZipCommon.sCompressionMethod); (* Method - string		*)
         //or
         //Add( IntToStr( ZipCommon.wCompressionMethod ) );		(* Method - word			*)

         Add(ZipCommon.FileAttrToString(ZipCommon.ExternalAttr, Byte('_')) +
            ' (' + IntToStr(ZipCommon.ExternalAttr) + ')');

         Add(ExtractFilePath(ZipCommon.FileName));
         Add(ZipCommon.GetFileType(ZipCommon.FileName)); (* Windows associated filetype *)
         Add(IntToHex(ZipCommon.CRC, 8)); (* CRC Property *)

         (* Beginning offset into*)
         (* compressed file		*)
         Add(IntToStr(Offset));
         If ZipCommon.Encrypted Then    (* Encrypted property	*)
            Add('Yes')
         Else
            Add('No');

         (* VolumeID's for multi-*)
         Add(ZipCommon.VolumeName);     (* volume archives.		*)
         Add(StrPas(ZipTV1.FileComment)); (* FileComment property	*)

      End;
   End;

   {$ELSE}

   (* Delimiter is a property of the ZipListBox *)

   With ZipView1 Do                     (* for the Delimiter variable *)
   Begin

      BuildString :=
         ExtractFilename(ZipCommon.FileName) + Delimiter +

      (* Date property 			*)
      FormatDateTime('mm/dd/yy hh:mm am/pm', ZipCommon.Date) + Delimiter +
         // ...or...
     //DateTimeToStr(ZipCommon.Date) + Delimiter +

      IntToStr(ZipCommon.PackedSize) + Delimiter +
         IntToStr(ZipCommon.UnpackedSize) + Delimiter +
         IntToStr(ZipCommon.Ratio) + '%' + Delimiter +
         ZipCommon.sCompressionMethod + Delimiter +

      //..or
      //IntToStr( ZipCommon.wCompressionMethod ) + Delimiter +

      ZipCommon.FileAttrToString(ZipCommon.ExternalAttr, Byte('_')) +
         ' (' + IntToStr(ZipCommon.ExternalAttr) + ')' + Delimiter +

      ExtractFilePath(ZipCommon.FileName) + Delimiter +
         ZipCommon.GetFileType(ZipCommon.FileName) + Delimiter +

      //IntToStr( ZipCommon.CRC ) + Delimiter +
      //..or

      IntToHex(ZipCommon.CRC, 8) + Delimiter +
         IntToStr(Offset) + Delimiter;

      If ZipCommon.Encrypted Then
         BuildString := BuildString + 'Yes' + Delimiter
      Else
         BuildString := BuildString + 'No' + Delimiter;

      BuildString := BuildString + ZipCommon.VolumeName + Delimiter;

      (* FileComment is NOT included in TZipCommon (as we typecast-ed using
      Sender previously in this procedure)... only TZipTV *)
      BuildString := BuildString + StrPas(ZipCommon.FileComment);

      ZipView1.Items.Add(BuildString);
   End;
   {$ENDIF ListView}
End;
//-------------------------------------------------------------
(*
   OnError Event -

  -All ZipTV components on dropped on this form share event.
  -See Err_Msgs.PAS & Err_Msgs.RC for error codes
*)

Procedure TfrmMain.ZipTV1Error(Sender: TObject; FileName, ExtendedMsg, VolumeID: String;
   ECode: Integer);
Var
   NewItem: TListItem;
Begin
   If frmErrorMsgs <> Nil Then          // has form been created?
   Begin
      NewItem := frmErrorMsgs.ListView1.Items.Insert(0); (* Create a new row *)
      With NewItem Do
      Begin
         Caption := LowerCase(Sender.Classname);
         With SubItems Do
         Begin
            Add(LowerCase(TZipCommon(Sender).ArchiveFile)); // archive FileName
            Add(LowerCase(ExtractFilename(FileName))); // FileName
            Add(IntToStr(ECode));       // convert error number to a string
            Add(LoadStr(ECode)); // Load error string from err_msgs.rc & err_msgs.pas
            Add(ExtendedMsg);           // Extended message such as required event params
         End;
      End;
   End;
End;
//-------------------------------------------------------------

(* OnProgress Event -

  -This event is shared by all compression and decompression components.

  -TZipCommon is the parent class for compression and decompression
   components.  TUnBase & TCompBase inherit Cancel from TZipCommon.
   'Sender' is typecast as type TZipCommon to check the value of the
   Cancel property for the current component in use.

  -When Cancel is True, compression / decompression is not interrupted
   until the current file is completed.  Accordingly, the active
   component will trigger their OnProgress events until the process
   on the current file is completed.
*)

Procedure TfrmMain.UnZIP1Progress(Sender: TObject; ByFile, ByArchive: Byte);
Begin
   ProgressBar1.Position := ByFile;
   ProgressBar2.Position := ByArchive;
   ProgressBar1.Update();
   ProgressBar2.Update();
End;
//-------------------------------------------------------------

(* OnExcludeFile Event

  -This event is shared by TZipTV, all compression, and decompression
  components.

  Activated when a diskfile matches a string in the ExcludeSpec
  property during a disk file scan is in operation.

  In this demo event, all files found which matched the ExcludeSpec
  are sent to the Error form for review.

*)

Procedure TfrmMain.Zip1ExcludeFile(Sender: TObject; FileName: String);
Var
   NewItem: TListItem;
Begin
   If frmErrorMsgs <> Nil Then          // has form been created?
   Begin
      NewItem := frmErrorMsgs.ListView1.Items.Insert(0); (* Create a new row *)
      With NewItem Do
      Begin
   		Caption := LowerCase(Sender.Classname);
         //Caption := 'Excluded file: ';
         With SubItems Do
         Begin
            Add(LowerCase(TZipCommon(Sender).ArchiveFile)); // archive FileName
            Add(LowerCase(FileName)); // FileName
            Add(''{IntToStr(ECode)});       // convert error number to a string
            Add('File Excluded'{LoadStr(ECode)}); // Load error string from err_msgs.rc & err_msgs.pas
            Add(''{ExtendedMsg});           // Extended message such as required event params
         End;
      End;
   End;
End;
//-------------------------------------------------------------

(* OnFileExists Event -
   -All decompression components share this event.

   -Triggered prior to extracting a file that was found to already
    exist on disk.

   -See ztvZip.pas header for usage notes in that components usage of
    this event.*)

Procedure TfrmMain.UnZIP1FileExists(Sender: TObject; FileName: String;
   Var NewFileName: String; Var OverwriteMode: TOverwriteMode);
Var
   FormResult: TModalResult;
   FindData: TWin32FindData;
   Handle: Integer;
   ReplaceFileSize: DWord;
   ReplaceFileDate: TDateTime;
   WithFileSize: Integer;
   WithFileDate: TDateTime;
Begin

   // get Date / and filesize of FileName
   Handle := Windows.FindFirstFile(Pchar(FileName), FindData);
   ReplaceFileSize := FindData.nFileSizeLow;
   ReplaceFileDate := ztvConvertDate(FileTimeToInt(FindData.ftLastWriteTime));
   Windows.FindClose(Handle);

   If ReplaceFileDate <> 0 Then
      ;                                 // satisfy compiler
   //ShowMessage(DateTimeToStr(ReplaceFileDate));

   (* defaults *)
   WithFileDate := 29221;               (* 01/01/80 *)
   WithFileSize := 0;

   With TZipCommon(Sender) Do
      Case ArcType Of
         atAce:
            Begin
               WithFileSize := AceFHeader.PSize;
               WithFileDate := ztvConvertDate(AceFHeader.FTime);
            End;
         atArc,
            atArcExe:
            Begin
               WithFileSize := ArcHeader.UnpackedSize;
               WithFileDate := ztvConvertDate(ArcHeader.FileDate);
            End;
         atArj,
            atArjExe:
            Begin
               WithFileSize := ArjHeader.UnpackedSize;
               WithFileDate := ztvConvertDate(ArjHeader.FileDate);
            End;
         atBh,
            atBhExe:
            Begin
               WithFileSize := BhHeader.UnpackedSize;
               WithFileDate := ztvConvertDate(BhHeader.FileDate);
            End;
         atCab:
            Begin
               WithFileSize := CFFile.UnpackedSize;
               WithFileDate := ztvConvertDate(CFFile.FileDate);
            End;
         atGZip:
            Begin
               // gzip files are single file archives.  Obtain the packed and
                 // unpacked size using the actual disk file (FileName parameter).
               WithFileSize := ReplaceFileSize;
               WithFileDate := ztvConvertDate(GZipHeader.FileDate);
            End;
         atJar:
            Begin
               // jar archives uses zip headers... there is only a minor
               // variation between a jar and zip arhive format.
               // in version 4, these properties are located in a "zc" structure
               // as in CentralZipHeader.zc.UnpackedSize.
               If Not (htCentral In HeaderTypeState) Then
               Begin
                  WithFileSize := LocalZipHeader.zc.UnpackedSize;
                  WithFileDate := ztvConvertDate(LocalZipHeader.zc.FileDate);
               End
               Else
               Begin
                  WithFileSize := CentralZipHeader.zc.UnpackedSize;
                  WithFileDate := ztvConvertDate(CentralZipHeader.zc.FileDate);
               End;
            End;
         atLha,
            atLhaExe,
            atLzh,
            atLzhExe:
            Begin
               WithFileSize := LzhHeader.UnpackedSize;
               If LzhHeader.OS = ztvConsts.LHA_UNIXOS Then
                  WithFileDate := UnixDateToDos(LzhHeader.FileDate)
               Else
                  WithFileDate := ztvConvertDate(LzhHeader.FileDate);
            End;
         atRar,
            atRarExe:
            Begin
               WithFileSize := RarHeaderDataEx.UnpackedSize;
               WithFileDate := ztvConvertDate(RarHeaderDataEx.FileDate);
            End;
         atTar:
            Begin
               WithFileSize := OctStrToInt(TarHeader.Size);
               Try
                  WithFileDate := UnixDateToDos(OctStrToInt(TarHeader.MTime));
               Except
                  WithFileDate := 29221; (* 01/01/80 *)
               End;
            End;
         atZip,                         // normal zip archive
         atZipMV,                       // multi-volume zip archive
         atZipExe:                      // self extracting zip archive

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -