Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[VB.NET] Patcher, Downloader

Experienced Elementalist
Joined
Apr 9, 2007
Messages
211
Reaction score
1
Hi guys im trying to make a patcher for my game, but i forgot the logic how to do it, right now i found this code on the internet

first it will download the patchlist, after that save it

if you click the button it will read the patchlist and get the 3rd on the list, and download all what will show on the patchlist

but the problem is, i can only download one time, after that i forgot the logic how to do the next one


Code:
Imports System.Net
Imports System.IO

Public Class Form1

    Dim client As WebClient = New WebClient
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Try
            If File.Exists(Application.StartupPath & "\patchlist.txt") = True Then
                File.Delete(Application.StartupPath & "\patchlist.txt")
                My.Computer.Network.DownloadFile("http://fileso2jam.ucoz.com/patch/patchlist.txt", Application.StartupPath & "\patchlist.txt")
            Else
                My.Computer.Network.DownloadFile("http://fileso2jam.ucoz.com/patch/patchlist.txt", Application.StartupPath & "\patchlist.txt")
            End If
        Catch ex As Exception
            MessageBox.Show("Can't Download Patchlist", "Network Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
        End Try
    End Sub
    Public Sub client_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percentage As Double = bytesIn / totalBytes * 100
        ProgressBar1.Value = Integer.Parse(Math.Truncate(percentage).ToString())
        Label1.Text = BytesToMegabytes(bytesIn) & "/" & BytesToMegabytes(totalBytes)
    End Sub
    Function BytesToMegabytes(ByVal Bytes As String) As String
        Dim SetBytes As String
        SetBytes = ""
        If Bytes >= 1099511627776 Then
            SetBytes = Format(Bytes / 1024 / 1024 / 1024 / 1024, "#0.00") & " TB"
        ElseIf Bytes >= 1073741824 Then
            SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") & " GB"
        ElseIf Bytes >= 1048576 Then
            SetBytes = Format(Bytes / 1024 / 1024, "#0.00") & " MB"
        ElseIf Bytes >= 1024 Then
            SetBytes = Format(Bytes / 1024, "#0.00") & " KB"
        ElseIf Bytes < 1024 Then
            SetBytes = Fix(Bytes) & " Bytes"
        End If
        Return SetBytes
    End Function
    Private Sub client_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        If e.Error.ToString = "" Then
            Label1.Text = "Patch Completed!"
            Button1.Text = "Game On!"
            Button1.Enabled = True
            Button2.Text = "Close"
        Else
            Button1.Text = "Patch"
            MsgBox(e.Error.Message)
            Button1.Enabled = True
            Button2.Text = "Close"
        End If

    End Sub
    Public Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click



        Try
            AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
            AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
            Dim strEmpRecord As String
            Dim astrEmpFields() As String
            Dim strFileName As String = Application.StartupPath & "\patchlist.txt"
            Dim objFS As New FileStream(strFileName, FileMode.Open, FileAccess.Read)
            Dim objSR As New StreamReader(objFS)
            Do While (objSR.Peek <> -1)
                strEmpRecord = objSR.ReadLine
                astrEmpFields = strEmpRecord.Split(" ")
                client.DownloadFileAsync(New Uri("http://fileso2jam.ucoz.com/patch/" & astrEmpFields(2)), Application.StartupPath & "\" & astrEmpFields(2))

            Loop

            objFS.Close()
            objSR.Close()
            Button1.Text = "Downloading Patch"
            Button1.Enabled = False
            Button2.Text = "Cancel"
            Label1.Text = "Connecting...."
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
   
    End Sub
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        If Button2.Text.ToLower = "close" Then
            Application.Exit()
        Else
            client.CancelAsync()
            Button2.Text = "Close"
        End If
    End Sub
End Class
 
Back
Top