I have been looking for a way to extract Rar files automatically, in a similar way as is done by WinRar. The article CUnrarDLL 1.0 by rich.w. was cool; however, it does not meet all of my expectations.
In this article, I have offered an MFC class to unpack Rar files using unrar.dll (from RARLIB).
Some of its features include:
- It is an MFC based class and very handy to use.
For instance, the following snippet performs the simplest file extraction task:
CUnrarObject m_UnrarObject; m_UnrarObject.SetInputPath("C:\\Test.rar"); m_UnrarObject.SetOutputPath("D:\\Output"); m_UnrarObject.Unpack();
It supports multiple volume Rar files.
You can extract A.rar, A.r00, A.r01,...
Support GUI update to reflect the unpack process.
At the same time the files are being unpacked, you can display the file extraction results in a
Support multithread file unpacking.
CListBox, CStatic, or other GUI controls. This might be useful when you are dealing with a bulky archive, say a 10M to 20M file, or if the archive contains, say, 10,000 files. It notifies the users that it is still in process and alive...
This allows you to carry out other tasks simultaneously when the files are extracted, and your interface can still respond well.
Support automatic archive cleaning.
After successful file unpacking, you might want to delete the original input archives, as is usually done manually. This class allows you to automatically delete them (e.g., A.rar, A.r00, A.r01,...) on task accomplishment.
The class is expected to be simple in use, for instance:
That is it.
void SetInputPath(CString InputPath): This function inputs the *.rar file to be unpacked.
void SetOutputPath(CString OutputPath): This function specifies where to unpack the input *.rar files.
CString GetInputPath(): Returns the input archive to be unpacked.
CString GetOutputPath(): Returns the output folder where to extract the archives.
void SetCleanArchiveOption(bool bRemove);: Sets the option if the input archives will be automatically deleted on task finish. For instance, the input files test.rar, test.r00, test.r01 ... etc. will be deleted if
void SetListBox(CListBox *pBox): This function hooks the input listbox with the file unpacking operations; the current file unpacking results are displayed to the listbox so that the users can monitor the dynamic process.
void SetStaticControl(CStatic *pStatic): Similar to
SetListBox(), this function hooks the
CStatic control with the file unpacking operations; the current file unpacking results are displayed to the static control so that the users can monitor the dynamic process.
void Unpack(bool bMultiThread=TRUE): This function executes the file unpacking operation. If
TRUE, then a new thread will be created to extract the archives, else the main thread in the current process will be used, i.e., sequential executions.
- I would like to thank RARLAB for providing such a neat and handy API interface.
- In the demo program, the article "How to Browse for a Folder" by Nitron was adapted in an MFC flavor, I hereby thank him for his efforts.
- I would also like to draw your attention to the fact that one of my freewares, FlashUnpack, is based on the above MFC class. You can download it at http://flashunpack.3322.org/. I welcome your feedback.
- Jul 27, 2006, minor help update.
- Jul 26, 2006, initial release to the public.