Using External Components

RobinTibbs

Member
Joined
Nov 8, 2006
Messages
18
Programming Experience
Beginner
Ive gotten hold of a zip component so can unzip files in my app I'm making, but I'm wondering how to utilise this, is there a certain place I need to put it? Very sorry for simple questions, I'll be out of your hair soon enough :)
 
We'll need to know a bit more. Which/What component is it that you have?

Are you looking to include the component for a reason? (So that others useing the app don't need external applications?) In your case specifically (WoW related) I'd asusme most of your users have WinZip already from extracting all their other mods, I might reccomend just firing off an instance of that to unzip it.

VB.NET:
Dim p As New Process
        With p.StartInfo
            .UseShellExecute = True
            .FileName = "PATHTOWINZIP\Winzip.exe"
            .Arguments = "ZIPFILE.ZIP"
        End With        p.Start()
        p.WaitForExit() 'Only if you actually want the program to wait until that file is closed.
        p.Dispose()
 
Not familiar with that particular component. I'll try to give it a look tonight unless someone else can answer before then how they've implemented it.
 
First add reference to the library, main menu Project > Add Reference (or use the context menu at the appropriate place to get this dialog). In that dialog browse to the dll file and click ok. While I'm at it, here is a snippet that use that library to extract an entire zip archive:
VB.NET:
Sub unzip()
    Dim filename As String = "Test.zip"
    Dim zip As New ICSharpCode.SharpZipLib.Zip.ZipFile(filename)
    Dim ze As ICSharpCode.SharpZipLib.Zip.ZipEntry
    'create directories
    For Each ze In zip
        If ze.IsDirectory Then
            If Not IO.Directory.Exists(ze.Name) Then IO.Directory.CreateDirectory(ze.Name)
        End If
    Next
    'extract files
    For Each ze In zip
        If ze.IsFile Then
            Dim stream As IO.Stream = zip.GetInputStream(ze)
            Dim fs As New IO.FileStream(ze.Name, FileMode.Create, FileAccess.Write, FileShare.None)
            Dim buffer(2047) As Byte, read As Integer
            Do
                read = stream.Read(buffer, 0, buffer.Length)
                If read > 0 Then
                    fs.Write(buffer, 0, read)
                Else : Exit Do
                End If
            Loop
            fs.Close()
        End If
    Next
End Sub
 
perfect, that works a treat!

ok noticed something, probably me going mad though :)

the file has been downloaded to the correct directory, but unziped to the debug directory, is this normal? or have I missed something?
 
Last edited:
If you look at the names (ze.name) you'll see that they are relative paths, so if you extract like my simple example you will extract to current directory (which usually is the application startup path initially). You should take care of this and provide an explicit target directory. You can use the IO.Path.Combine method to combine the target path and relative file path.
 
Back
Top