zoukankan      html  css  js  c++  java
  • 7-zip Delphi API

    官网已经找不到了。
    这个地址比较新
    https://github.com/zedalaye/d7zip
    在这个基础上 融合了
    SevenZip.pas BUG修改版 - 20160613 - 堕落恶魔 - 博客园
    https://www.cnblogs.com/hs-kill/p/3876160.html
    然后再加了一些小的修改。
    
    最后,提供一个比较全面的 例子。
    Delphi】从内存读取或解压压缩文件(RARZIPTARGZIP等)(一) - 峋山隐修会 - 博客园
    http://www.cnblogs.com/caibirdy1985/archive/2013/05/13/4232949.html
    Delphi】从内存读取或解压压缩文件(RARZIPTARGZIP等)(二) - 峋山隐修会 - 博客园
    http://www.cnblogs.com/caibirdy1985/archive/2013/05/14/4232948.html
    
    
    
    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.2
    
    Reading archive:
    
    Extract to path:
    解压到目录:
    with CreateInArchive(CLSID_CFormatZip) do
    begin
       OpenFile('c:	est.zip');
       ExtractTo('c:	est');
    end;
    
    Get file list:
    获取文件列表:
    with CreateInArchive(CLSID_CFormat7z, 'Formats7z.dll') do
    begin
       OpenFile('c:	est.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:	est.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:	est.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:	est.zip', fmOpenRead), soOwned));
       OpenStream(aStream, soReference);
       ...
    end;
    
    Progress bar
    进度条回调:
    function ProgressCallback(sender: Pointer; total:boolean; value: int64): HRESULT; stdcall;beginif total thenMainform.ProgressBar.Max:= value elseMainform.ProgressBar.Position:= value;Result:= S_OK;end;
    
    procedure TMainForm.ExtractClick(Sender:TObject);beginwithCreateInArchive(CLSID_CFormatZip)dobeginOpenFile('c:	est.zip');SetProgressCallback(nil,ProgressCallback);...end;end;Password打开含有密码的文件:functionPasswordCallback(sender:Pointer;var password:WideString): HRESULT; stdcall;begin// call a dialog box ...
       password :='password';Result:= S_OK;end;
    procedure TMainForm.ExtractClick(Sender:TObject);beginwithCreateInArchive(CLSID_CFormatZip)dobegin// using callbackSetPasswordCallback(nil,PasswordCallback);// or setting password directlySetPassword('password');OpenFile('c:	est.zip');...end;end;Writing archive
    压缩存档:
    procedure TMainForm.ExtractAllClick(Sender:TObject);varArch: I7zOutArchive;beginArch:=CreateOutArchive(CLSID_CFormat7z);// add a fileArch.AddFile('c:	est.bin','folder	est.bin');// add files using willcards and recursive searchArch.AddFiles('c:	est','folder','*.pas;*.dfm',true,true);// add a streamArch.AddStream(aStream, soReference, faArchive,CurrentFileTime,CurrentFileTime,'folder	est.bin',false,false);// compression levelSetCompressionLevel(Arch,5);// compression method if <> LZMASevenZipSetCompressionMethod(Arch, m7BZip2);// add a progress bar ...Arch.SetProgressCallback(...);// set a password if necessaryArch.SetPassword('password');// Save to fileArch.SaveToFile('c:	est.zip');// or a streamArch.SaveToStream(aStream);end;
  • 相关阅读:
    hdu 1588 求f(b) +f(k+b) +f(2k+b) +f((n-1)k +b) 之和 (矩阵快速幂)
    poj 3233 S = A + A^2 + A^3 + … + A^k A是一个n X n矩阵 (矩阵快速幂)
    hdu 1757 和1005差不多 (矩阵快速幂)
    D 矩阵快速幂
    poj 3734 方块涂色 求红色 绿色方块都为偶数的方案数 (矩阵快速幂)
    hdu 1005 根据递推公式构造矩阵 ( 矩阵快速幂)
    hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
    UVa 1643 Angle and Squares (计算几何)
    UVa 11040 Add bricks in the wall (水题递推)
    UVa 1336 Fixing the Great Wall (区间DP)
  • 原文地址:https://www.cnblogs.com/h2zZhou/p/12503965.html
Copyright © 2011-2022 走看看