UnRAR is the official library from RARLabs for extracting WinRAR archives. This project implements UnRAR bindings for RealStudio and Xojo Win32 applications. Creating archives is not supported by the library.
The project consists of a module containing three classes: Iterator, IteratorEx, and ArchiveEntry.
The Iterator
class implements the basic, older UnRAR interface. It does not support Unicode filenames, archives with encrypted headers, or extracting into memory. For almost all archives you should prefer the IteratorEx
class.
Dim archive As FolderItem ' assume a valid RAR archive
Dim outputdir As FolderItem ' assume a valid directory
Dim rar As New UnRAR.IteratorEx(archive)
Do
If Not rar.MoveNext(UnRAR.RAR_EXTRACT, outputdir) Then Exit Do
Loop
rar.Close
- Download the RB-RAR project either in ZIP archive format or by cloning the repository with your Git client.
- Open the RB-RAR project in REALstudio or Xojo. Open your project in a separate window.
- Copy the UnRAR module into your project and save.
You will need to ship the UnRAR.dll file with your application and install it into the same directory as your app. A pre-built Win32 DLL is available here, or you can build it yourself from source.
Dim index As Integer = 2 ' the third file in the archive
Dim archive As FolderItem ' assume a valid RAR archive
Dim outputfile As FolderItem ' assume a valid, non-existing file
Dim rar As New UnRAR.IteratorEx(archive)
rar.Reset(index) ' move to the index
Call rar.MoveNext(UnRAR.RAR_EXTRACT, outputfile)
rar.Close
Dim archive As FolderItem ' assume a valid RAR archive
Dim rar As New UnRAR.IteratorEx(archive)
Do
If Not rar.MoveNext(UnRAR.RAR_TEST) Then Exit Do
Loop
If rar.LastError <> UnRAR.ErrorEndArchive Then
MsgBox("Test failed!")
End If
rar.Close
Dim index As Integer = 2 ' the third file in the archive
Dim archive As FolderItem ' assume a valid RAR archive
Dim rar As New UnRAR.IteratorEx(archive)
rar.Reset(index) ' move to the index
If Not rar.MoveNext(UnRAR.RAR_TEST) And rar.LastError <> UnRAR.ErrorEndArchive Then
MsgBox("Test failed!")
End If
rar.Close