C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[75462] Re:압축해제 코드 구현을 위한 라이브러리나 컴포넌트는 어떤걸 사용하나요?
[] 2709 읽음    2019-06-26 22:29
어디선가 7zip 을 이용하는 방법을 스크랩 해놓은건데.. 올려드립니다.
델파이 코드이고 제가 직접 해보진 않았습니다.



7zip plugin Api

This API use the 7-zip dll (7z.dll) to read and write all 7-zip supported archive formats..
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_CFormatZip) 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!
   A 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;


해 님이 쓰신 글 :
:
: builder 2007을 사용하고 있습니다.
:
: 압축해제와 관련되서 자료실에 있는 zipbuilder 글을 보았는데, 설치가 안되서요..
:
: 혹시, 압축 해제와 관련된 라이브러리나 컴포넌트 어디서 구할 수 있는지 여쭤봅니다.
:
: 파일을 올려주실 수 있으시면, 너무 감사드립니다..
:
:

+ -

관련 글 리스트
75461 압축해제 코드 구현을 위한 라이브러리나 컴포넌트는 어떤걸 사용하나요? 2394 2019/06/26
75466     Re: OS에서 제공해주는 compression 기능 이용. 빌더(TWx) 2420 2019/06/27
75462     Re:압축해제 코드 구현을 위한 라이브러리나 컴포넌트는 어떤걸 사용하나요? 2709 2019/06/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.