spSkinZip.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:6k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*******************************************************************}
  2. {                                                                   }
  3. {       Almediadev Visual Component Library                         }
  4. {       DynamicSkinForm                                             }
  5. {       Version 5.60                                                }
  6. {                                                                   }
  7. {       Copyright (c) 2000-2003 Almediadev                          }
  8. {       ALL RIGHTS RESERVED                                         }
  9. {                                                                   }
  10. {       Home:  http://www.almdev.com                                }
  11. {       Support: support@almdev.com                                 }
  12. {                                                                   }
  13. {*******************************************************************}
  14. unit spSkinZip;
  15. interface
  16. uses
  17.   Windows, Messages, SysUtils, Classes;
  18. type
  19.   TDllPrnt = function(Buffer: PChar; Size: ULONG): integer; stdcall;
  20.   TDllPassword = function(P: PChar; N: Integer; M, Name: PChar): integer; stdcall;
  21.   TDllComment = function(Buffer: PChar): PChar; stdcall;
  22.   TDllService = function(P: PChar; Size: ULONG): integer; stdcall;
  23.   TZPOpt = record
  24.     Date: PChar;
  25.     szRootDir: PChar;
  26.     szTempDir: PChar;
  27.     fTemp: Bool;
  28.     fSuffix: Bool;
  29.     fEncrypt: Bool;
  30.     fSystem: Bool;
  31.     fVolume: Bool;
  32.     fExtra: Bool;
  33.     fNoDirEntries: Bool;
  34.     fExcludeDate: Bool;
  35.     fIncludeDate: Bool;
  36.     fVerbose: Bool;
  37.     fQuiet: Bool;
  38.     fCRLF_LF: Bool;
  39.     fLF_CRLF: Bool;
  40.     fJunkDir: Bool;
  41.     fGrow: Bool;
  42.     fForce: Bool;
  43.     fMove: Bool;
  44.     fDeleteEntries: Bool;
  45.     fUpdate: Bool;
  46.     fFreshen: Bool;
  47.     fJunkSFX: Bool;
  48.     fLatestTime: Bool;
  49.     fComment: Bool;
  50.     fOffsets: Bool;
  51.     fPrivilege: Bool;
  52.     fEncryption: Bool;
  53.     fRecurse: Integer;
  54.     fRepair: Integer;
  55.     fLevel: Char;
  56.   end;
  57.   TPCharArray = array [0..0] of PChar;
  58.   PCharArray  = ^TPCharArray;
  59.   TZCL = record
  60.     argc       : Integer;
  61.     lpszZipFN  : PChar;
  62.     FNV        : PCharArray;     
  63.   end;
  64.   TZipUserFunctions = record
  65.     Print     : TDllPrnt;
  66.     Comment   : TDllComment;
  67.     Password  : TDllPassword;
  68.     Service   : TDllService;
  69.   end;
  70.   TspSkinZip = class(TComponent)
  71.   protected
  72.     procedure SetDummyInitFunctions(var Z: TZipUserFunctions);
  73.     procedure SetZipOptions(var Opt: TZPOpt);
  74.   public
  75.     procedure ZipFiles(FileName: String; FileList: TStrings);
  76.   end;
  77. function DummyPrint(Buffer: PChar; Size: ULONG): integer; stdcall ;
  78. function DummyPassword(P: PChar; N: Integer; M, Name: PChar): integer; stdcall ;
  79. function DummyComment(Buffer: PChar): PChar; stdcall ;
  80. function DummyService(Buffer: PChar; Size: ULONG): integer; stdcall;
  81. implementation
  82. uses ShellApi;
  83. const
  84.   ZIPDLLNAME = 'zip32.dll';
  85. function DummyPrint(Buffer: PChar; Size: ULONG): integer;
  86. begin
  87.   Result := Size;
  88. end;
  89. function DummyPassword(P: PChar; N: Integer; M, Name: PChar): integer;
  90. begin
  91.   Result := 1;
  92. end;
  93. function DummyComment(Buffer: PChar): PChar;
  94. begin
  95.   Result := Buffer;
  96. end;
  97. function DummyService(Buffer: PChar; Size: ULONG): integer;
  98. begin
  99.   Result := 0;
  100. end;
  101. procedure TspSkinZip.SetZipOptions;
  102. begin
  103.   with Opt do
  104.   begin
  105.     fJunkDir := True;
  106.   end;
  107. end;
  108. procedure TspSkinZip.SetDummyInitFunctions(var Z: TZipUserFunctions);
  109. begin
  110.   with Z do
  111.   begin
  112.     @Print := @DummyPrint;
  113.     @Comment := @DummyComment;
  114.     @Password := @DummyPassword;
  115.     @Service := @DummyService;
  116.   end;
  117. end;
  118. procedure TspSkinZip.ZipFiles(FileName: String; FileList: TStrings);
  119. var
  120.   Zip32: Cardinal;
  121.   Opt: TZPOpt;
  122.   ZpSetOptions: function (var Opts: TZPOpt): Bool; stdcall;
  123.   ZpGetOptions: function: TZPOpt; stdcall;
  124.   ZpInit: function(var lpZipUserFunc: TZipUserFunctions): Integer; stdcall;
  125.   ZpArchive: function(C: TZCL): Integer; stdcall;
  126. procedure Compress;
  127. var
  128.   i: integer;
  129.   ZipRec: TZCL;
  130.   ZUF: TZipUserFunctions;
  131.   FNVStart: PCharArray;
  132. begin
  133.   if FileName = '' then Exit;
  134.   if FileList.Count <= 0 then Exit;
  135.   SetDummyInitFunctions(ZUF);
  136.   ZpInit(ZUF);
  137.   ZipRec.argc := FileList.Count;
  138.   GetMem(ZipRec.lpszZipFN, Length(FileName) + 1 );
  139.   ZipRec.lpszZipFN := StrPCopy( ZipRec.lpszZipFN, FileName);
  140.   try
  141.     GetMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
  142.     FNVStart := ZipRec.FNV;
  143.     try
  144.       for i := 0 to ZipRec.argc - 1 do
  145.       begin
  146.         GetMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
  147.         StrPCopy(ZipRec.FNV^[i], FileList[i]);
  148.       end;
  149.       try
  150.         ZpArchive(ZipRec);
  151.       finally
  152.         ZipRec.FNV := FNVStart;
  153.         for i := (ZipRec.argc - 1) downto 0 do
  154.           FreeMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
  155.       end;
  156.     finally
  157.       ZipRec.FNV := FNVStart;
  158.       FreeMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
  159.     end;
  160.   finally
  161.     FreeMem(ZipRec.lpszZipFN, Length(FileName) + 1 );
  162.   end;
  163. end;
  164. begin
  165.   Zip32 := LoadLibrary(ZIPDLLNAME);
  166.   if Zip32 <> 0
  167.   then
  168.     begin
  169.       ZpGetOptions := GetProcAddress(Zip32, 'ZpGetOptions');
  170.       ZpSetOptions := GetProcAddress(Zip32, 'ZpSetOptions');
  171.       if (@ZpGetOptions <> nil) and (@ZpSetOptions <> nil)
  172.       then
  173.         begin
  174.           Opt := ZpGetOptions;
  175.           SetZipOptions(Opt);
  176.           ZpSetOptions(Opt);
  177.         end;
  178.       ZpInit := GetProcAddress(Zip32, 'ZpInit');
  179.       ZpArchive := GetProcAddress(Zip32, 'ZpArchive');
  180.       if (@ZpInit <> nil) and (@ZpArchive <> nil)
  181.       then Compress;
  182.       FreeLibrary(Zip32);
  183.     end;
  184.  end;
  185. end.