<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Process ED2K links</Title>
            <Shortcut>processed2k</Shortcut>
            <Description>Process ED2K links</Description>
            <Author>Luca Mauri, www.lucamauri.com</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
            </SnippetTypes>
            <Keywords>
                <Keyword>ed2k</Keyword>
                <Keyword>ed2k link</Keyword>
                <Keyword>ed2k link</Keyword>
                <Keyword>ed2k</Keyword>
            </Keywords>
        </Header>
        <Snippet>
            <Code Language="VB">
<![CDATA[Imports System.Text.RegularExpressions

Public Class clsLink
    'See also:
    'http://www.amule.org/wiki/index.php/Ed2k_link
    'http://en.wikipedia.org/wiki/Ed2k_link

    Public Enum linkError
        noError = 0
        tryError = 1
        tooShort = 2
        invalidLink = 4
    End Enum
    Private mED2K As String
    Private mType As String
    Private mName As String
    Private mSize As Integer
    Private mHash As String
    Private mErrorCode As linkError
    Public ReadOnly Property ed2k() As String
        Get
            Return mED2K
        End Get
    End Property
    Public ReadOnly Property type() As String
        Get
            Return mType
        End Get
    End Property
    Public ReadOnly Property name() As String
        Get
            Return mName
        End Get
    End Property
    Public ReadOnly Property size() As String
        Get
            Return String.Format("{0:n}", (mSize / 1024))
        End Get
    End Property
    Public ReadOnly Property md4hash() As String
        Get
            Return mHash
        End Get
    End Property
    Public ReadOnly Property errorCode() As linkError
        Get
            Return mErrorCode
        End Get
    End Property
    Sub New(ByVal sourceED2K As String)
        Dim parts() As String

        Try
            mED2K = sourceED2K
            parts = mED2K.Split("|")

            If parts.GetUpperBound(0) < 4 Then
                mErrorCode = linkError.tooShort
            Else
                If parts(0).ToLower <> "ed2k://" OrElse parts(1).ToLower <> "file" Then
                    mErrorCode = linkError.invalidLink
                Else
                    mType = "file"
                    mName = parts(2)
                    mSize = Integer.Parse(parts(3))
                    mHash = parts(4)
                    mErrorCode = linkError.noerror
                End If
            End If
        Catch ex As Exception
            mErrorCode = linkError.tryError
        End Try
    End Sub
End Class]]>
</Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>