Delphi 7-zip 单元文件 sevenzip.pas

7-zip Delphi API

This API use the 7-zip dll (7z.dll) to read and write all 7-zip supported archive formats.

- Autor: Henri Gourvest <hgourvest@progdigy.com>
- Licence: MPL1.1
- Date: 15/04/2009
- Version: 1.1

Reading archive:

Extract to path:

 with CreateInArchive(CLSID_CFormatZip) do begin   OpenFile('c:\test.zip');   ExtractTo('c:\test'); end;

Get file list:

 with CreateInArchive(CLSID_CFormat7z) do begin   OpenFile('c:\test.7z');   for i := 0 to NumberOfItems - 1 do    if not ItemIsFolder[i] then      Writeln(ItemPath[i]); end;

Extract to stream

 with CreateInArchive(CLSID_CFormat7z) do begin   OpenFile('c:\test.7z');   for i := 0 to NumberOfItems - 1 do     if not ItemIsFolder[i] then       ExtractItem(i, stream, false); end;

Extract "n" Items

function GetStreamCallBack(sender: Pointer; index: Cardinal;
var outStream: ISequentialOutStream): HRESULT; stdcall;
begin
case index of ...
outStream := T7zStream.Create(aStream, soReference);
Result := S_OK;
end;

procedure TMainForm.ExtractClick(Sender: TObject);
var
i: integer;
items: array[0..2] of Cardinal;
begin
with CreateInArchive(CLSID_CFormat7z) do
begin
OpenFile('c:\test.7z');
// items must be sorted by index!
 items[0] := 0;
items[1] := 1;
items[2] := 2;
ExtractItems(@items, Length(items), false, nil, GetStreamCallBack);
end;
end;

Open stream

 with CreateInArchive(CLSID_CFormatZip) do begin   OpenStream(T7zStream.Create(TFileStream.Create('c:\test.zip', fmOpenRead), soOwned));   OpenStream(aStream, soReference);   ... end;

Progress bar

 function ProgressCallback(sender: Pointer; total: boolean; value: int64): HRESULT; stdcall; begin   if total then     Mainform.ProgressBar.Max := value else     Mainform.ProgressBar.Position := value;   Result := S_OK; end; procedure TMainForm.ExtractClick(Sender: TObject); begin   with CreateInArchive(CLSID_CFormatZip) do   begin     OpenFile('c:\test.zip');     SetProgressCallback(nil, ProgressCallback);     ...   end; end;

Password

 function PasswordCallback(sender: Pointer; var password: WideString): HRESULT; stdcall;
begin
// call a dialog box ...
  password := 'password';
Result := S_OK;
end;

procedure TMainForm.ExtractClick(Sender: TObject);
begin
with CreateInArchive(CLSID_CFormatZip) do
begin
// using callback
SetPasswordCallback(nil, PasswordCallback);
// or setting password directly
SetPassword('password');
OpenFile('c:\test.zip');
...
end;
end;

Writing archive

 procedure TMainForm.ExtractAllClick(Sender: TObject); var   Arch: I7zOutArchive; begin   Arch := CreateOutArchive(CLSID_CFormat7z);   // add a file   Arch.AddFile('c:\test.bin', 'folder\test.bin');   // add files using willcards and recursive search   Arch.AddFiles('c:\test', 'folder', '*.pas;*.dfm', true);   // add a stream   Arch.AddStream(aStream, soReference, faArchive, CurrentFileTime, CurrentFileTime, 'folder\test.bin', false, false);   // compression level   SetCompressionLevel(Arch, 5);   // compression method if <> LZMA   SevenZipSetCompressionMethod(Arch, m7BZip2);   // add a progress bar ...   Arch.SetProgressCallback(...);   // set a password if necessary   Arch.SetPassword('password');   // Save to file   Arch.SaveToFile('c:\test.zip');   // or a stream   Arch.SaveToStream(aStream); end;

发表回复

登录... 后才能评论

本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。

最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。 若排除这种情况,可在对应资源底部留言,或联络我们。

对于会员专享、整站源码、程序插件、网站模板、网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。

如果您已经成功付款但是网站没有弹出成功提示,请联系站长提供付款信息为您处理

源码素材属于虚拟商品,具有可复制性,可传播性,一旦授予,不接受任何形式的退款、换货要求。请您在购买获取之前确认好 是您所需要的资源