CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2008
    Posts
    5

    Update function help

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lbl1.Text = ("Parsing file...")
            Dim baseDir As New DirectoryInfo(Application.ExecutablePath)
            Dim update As ugen.Update = ugen.Update.Parse("linkhere")
            For Each file As ugen.UpdateFile In update.Files
                Dim fi As New FileInfo(baseDir.FullName + file.FilePath)
                If (fi.Exists) Then ' its supposed to be if it exists check if it doesnt exist just update it
                    Dim size As Integer = fi.Length
                    Dim hash As String = makeHash(fi)
                    If size <> file.Size Or hash <> file.Hash Then
                        update(file)
    
                    End If
                Else
                    update(file)
                End If
    
            Next
        End Sub
    End Class
    
    Namespace ugen
        Public Class Update
            Public Files As New List(Of UpdateFile)()
    
            Public Sub New()
            End Sub
            Public Shared Function Parse(ByVal url As String) As Update
                Dim data As String = New WebClient().DownloadString(url)
                Dim update As New Update()
                Dim lines As String() = data.Split(New String() {vbCr & vbLf}, StringSplitOptions.RemoveEmptyEntries)
                For Each line As String In lines
                    Try
                        Dim infos As String() = line.Split(New Char() {"|"c})
                        Dim name As String = infos(0)
                        Dim size As Integer = Integer.Parse(infos(1))
                        Dim hash As String = infos(2)
                        update.Files.Add(New UpdateFile(name, size, hash))
                    Catch
                    End Try
                Next
                Return update
            End Function
        End Class
        Public Class UpdateFile
            Private _filepath As String, _hash As String
            Private _size As Integer = -1
            Public Sub New(ByVal filepath As String, ByVal size As Integer, ByVal hash As String)
                _filepath = filepath
                _size = size
                _hash = hash
            End Sub
            Public Property FilePath() As String
                Get
                    Return _filepath
                End Get
                Set(ByVal value As String)
                    _filepath = value
                End Set
            End Property
            Public Property Hash() As String
                Get
                    Return _hash
                End Get
                Set(ByVal value As String)
                    _hash = value
                End Set
            End Property
            Public Property Size() As Integer
                Get
                    Return _size
                End Get
                Set(ByVal value As Integer)
                    _size = value
                End Set
            End Property
        End Class
    End Namespace
    i need a little help coding the update function and makehash function.
    Last edited by raulh; November 3rd, 2008 at 04:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured