Here is a a code snippet of how you can use the Winrar DLL. This is only a simple example for those who dont understand and need a barebone. You may download the source code from below. I took out most of the junk that you would get in the examples included in installation so you can understand it easier.
This allows you to open an RAR file and extract it to a specified directory of your choice. Download WinRARDLL here.
Code:Imports RARNET Public Class Form1 Dim d As Decompressor Dim m_dll As String = Application.StartupPath & "\unrar.dll" Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try d.UnPackAll(GetPath()) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Public Sub Unpacked(ByVal r As Decompressor.RAREntry) StatusBar1.Panels.Item(0).Text = r.FileName & " Unpacked" End Sub Public Sub InProgress(ByVal TotalFileSize As Long, ByVal CurrentFileSize As Long) If TotalFileSize = 0 Then Exit Sub StatusBar1.Panels.Item(1).Text = Format(CurrentFileSize / TotalFileSize, "percent") End Sub Private Function GetFile() As String Dim f As New OpenFileDialog f.Title = "Unpack RAR Archive" f.CheckFileExists = True f.DefaultExt = "RAR" f.Filter = "RAR files (*.rar)|*.rar|All files (*.*)|*.*" f.RestoreDirectory = True If f.ShowDialog() = DialogResult.OK Then Return f.FileName End If Return "" End Function Private Function GetPath() As String Dim f As New FolderBrowserDialog f.Description = "Unpack RAR Archive" f.ShowNewFolderButton = True If f.ShowDialog() = DialogResult.OK Then Return f.SelectedPath End If Return "" End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim szFile As String = GetFile() d = New Decompressor(szFile, "khogarth") AddHandler d.OnUnpack, AddressOf Unpacked 'AddHandler d.Unpacking, AddressOf InProgress For Each r As Decompressor.RAREntry In d.RARFiles Dim lvitem As New ListViewItem(r.FileName) ' Place a check mark next to the item. lvitem.SubItems.Add(r.FileAttr) lvitem.SubItems.Add(r.PackSize) lvitem.SubItems.Add(r.UnpSize) lvitem.SubItems.Add(r.FileCRC) Lv.Items.Add(lvitem) Next End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If System.IO.File.Exists(m_dll) Then Else MsgBox(m_dll & " cannot be found.") Application.Exit() End If Lv.View = View.Details Lv.GridLines = True ' Create some columns Lv.Columns.Add("File", 200, HorizontalAlignment.Left) Lv.Columns.Add("Attr", 30, HorizontalAlignment.Left) Lv.Columns.Add("Packed Size", 100, HorizontalAlignment.Left) Lv.Columns.Add("Unpacked Size", 100, HorizontalAlignment.Center) Lv.Columns.Add("CRC", 120, HorizontalAlignment.Center) End Sub End Class





Reply With Quote