7z Compression class progress bar callback function

Source: Internet
Author: User

First go to the 7z official website to download the code 7z source or Lzma can, but recommended 7z source code, the contents of a relatively full

7z.dll works through COM interfaces. However, it does not use a standard COM interface. It would be easier to see his code if there was a COM base.

The simple example is that/cpp/7zip/ui/client7z has a simple compression decompression and a view of the compressed package file. 7z.dll's source code is inside BUNDLES/7ZFORMATF.

Where the code for clinet7z and file Manager looks better, you can follow your own step-by-step. Update later in the evening

7z.dll works with COM interfaces, but it does not use a standard COM interface.

Unzip the file mainly by the following two callback classes

/Archive Open Callback Class

ZIP File Open Callback class Carchiveopencallback:

Public Iarchiveopencallback,

Public Icryptogettextpassword,

Public Cmyunknownimp

Decompression Callback class Carchiveextractcallback:

Public Iarchiveextractcallback,

Public Icryptogettextpassword,

Public Cmyunknownimp

Unzip the callback class

IProgress

STDMETHOD (settotal) (UInt64 size); Get the total number of compressed files bytes

STDMETHOD (setcompleted) (const UInt64 *completevalue); Gets the current uncompressed file size byte number you can then calculate the current decompression progress in this callback function.

Iarchiveextractcallback

STDMETHOD (GetStream) (UInt32 index, Isequentialoutstream **outstream,int32 askextractmode); Gets the file stream,

LRESULT Myreleasesteam (); When you cancel the decompression, release the file stream control reason to cancel the decompression and not go to the Setoperationresult () callback function, and release the file stream is in this function, so to release itself.

Get interface functions

Createobjectfunc Createobjectfunc = (Createobjectfunc) lib. Getproc ("CreateObject");

Cmycomptr<iinarchive> Archive;

ErrorCode = Createobjectfunc (&clsid_cformat7z, &iid_iinarchive, (void * *) &archive);

Cinfilestream *filespec = new Cinfilestream;

cmycomptr<iinstream> file = FileSpec;

Ustring archivename = getunicodestring (inFile);

if (!filespec->open (archivename))

{

Unable to open the compressed file (the file cannot be found)

return;

}

Carchiveopencallback *opencallbackspec = new Carchiveopencallback;

Cmycomptr<iarchiveopencallback> Opencallback (OPENCALLBACKSPEC);

opencallbackspec->passwordisdefined = false;

ErrorCode = archive->open (file, 0, opencallback);

if (errorcode! = S_OK)

Return

Extract command

Carchiveextractcallback *extractcallbackspec = new Carchiveextractcallback;

Cmycomptr<iarchiveextractcallback> Extractcallback (EXTRACTCALLBACKSPEC);

Extractcallbackspec->init (archive, OutFile); Second parameter is output folder path

extractcallbackspec->passwordisdefined = false;

Extractcallbackspec->setfileinfo (info);

Extractcallbackspec->passwordisdefined = true;

Extractcallbackspec->password = L "1";

ErrorCode = Archive->extract (NULL, (UInt32) (Int32) ( -1), false, Extractcallback);

if (errorcode! = S_OK)

Return

7z Compression class progress bar callback function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.