Question Struggling with Autoupdate

xXAlphaXx

New member
Joined
May 8, 2011
Messages
4
Programming Experience
1-3
Okay, I have tried a few other forums and looked through a lot of lines of code. I hope you guys can help me. :)


Okay, so basically I am developing an application that acts as a "game launcher." As it is we make many updates too our files so I need to include an auto updating function too this launcher.


For the sake of the question let's say that I have a file called "data1.dat" that we recently made a change too and now we need it to be downloaded whenever a user launches our game launcher.

I don't need any assistance of it setting it up server side because it is going to be all located through URLs of where to download. (I hope that makes sense.)


So, when the applications launches I want it too access the programs file called "config.ini" too check the version number, after that I would like it to check the "config.ini" on the server, if the number on the server is higher, the launcher proceeds to downloads the updated "data1.dat" and replaces the old "data1.dat" in the client.

Now, It doesn't need anything super complex as closing the launcher after the update because "data1.dat" is not being used in the launcher.

Honestly, I have been having a lot of problems with understanding how to do this so this is about how far I have gotten...

VB.NET:
    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated

        'check config.ini
        'check server config.ini
        'If server config.ini > config.ini Then 
        ' Download all files from "WEBADDRESS"
 End Sub

Any help would be much appreciated! :)
 
First up, you wouldn't use the Activated event of the form. Do you really want to update the application every time the form gets activated? If the user activates another app and then activates your app again, do you want to update the app again?

As for the question, you've pretty much answered your own question: download the INI file form the server, open it and compare the version information to the local file, if they are different then download the new file. Are you saying that you don't know how to download a file? If so, there's an easy way to fix that:

download file vb.net - Google Search
 
Hmm okay, I will start too look into those file downloads and play around with it abit.


As for the activate event - which event would I want? I am trying to have it start after the form loads so I can show the download progress in the progress bars on the launcher it self.

I am having trouble with reading the client version from the webserver, this is what I have so far:

VB.NET:
 Dim wc As New System.Net.WebClient()
        Dim ad As String = "127.0.0.1/updates/config.ini"
        Dim upVers As Double

        upVers = wc.DownloadString(ad)

        MsgBox(upVers)


This is what I keep getting:

VB.NET:
Could not find a part of the path 'C:\Users\Alpha\Desktop\Muz0r Launcher\Muz0r Launcher\bin\Debug\127.0.0.1\updates\config.ini'.
 
Last edited:
So read the documentation for the Form class and see which event is raised after the form loads.

If you want to download a fiel using HTTP then you have to specify that in the URL, otherwise it's assumed to be a local file in the current directory.
 
Okay, I'm getting closer to the solution here, this is what I am up too:


VB.NET:
 Dim verNum As Double = My.Computer.FileSystem.ReadAllText("config.ini")

        Dim wc As New System.Net.WebClient()
        Dim ad As String = "http://127.0.0.1/updates/config.ini"
        Dim upVers As Double
        Dim fileToDL As String
        Dim reader As System.IO.StreamReader

        upVers = wc.DownloadString(ad)

        If verNum < upVers Then
            'Disable start button
            My.Computer.Network.DownloadFile("http://127.0.0.1/updates/updatelist.txt", "updatelist.txt")
            reader = System.IO.File.OpenText("updatelist.txt")
            fileToDL = reader.ReadLine()

            Do Until fileToDL Is Nothing
                If System.IO.File.Exists(fileToDL) Then
                    My.Computer.FileSystem.DeleteFile(fileToDL)
                End If
                My.Computer.Network.DownloadFile("http://127.0.0.1/updates/" + fileToDL, fileToDL)
                fileToDL = reader.ReadLine()
            Loop
        End If

My updatelist.txt is just a list of files to update.

So far that is working 100% with downloading a single file at a time, how ever it is a totally diffrent story when I am working with files inside of folders. I can't seem to figure that one out. Any string modifying tricks or anything else that may help automate this process?

The way the text file is layed out, if I could OVERWRITE as opposed to deleting a file when it exists, then I can definitely make this work.

Thank you for all the help thus far. :)
 
Last edited:
I would suggest a file format like this:
VB.NET:
File1:v1.0
Folder1\File2:v1.1
You can then build a Dictionary from each file simply by looping and splitting. You can then compare each Dictionary to the other by keys. Any keys in the old list that aren't in the new list are files to delete. Any keys in the new list that aren't in the old list are new files. Any keys that match with different values are files to update and the rest are unchanged.
 
Feels like I am getting closer.


But still nothing inside of folders will download.

Here is what I got so far:

VB.NET:
        Dim verNum As Double = My.Computer.FileSystem.ReadAllText("config.ini")

        Dim wc As New System.Net.WebClient()
        Dim ad As String = "http://127.0.0.1/updates/config.ini"
        Dim upVers As Double
        Dim fileToDL As String
        Dim reader As System.IO.StreamReader
        Dim strArray() As String
        Dim fileLocation As String

        upVers = wc.DownloadString(ad)

        If verNum < upVers Then
            'Disable start button
            My.Computer.Network.DownloadFile("http://127.0.0.1/updates/updatelist.txt", "updatelist.txt")
            reader = System.IO.File.OpenText("updatelist.txt")
            fileToDL = reader.ReadLine()

            Do Until fileToDL Is Nothing
                strArray = fileToDL.Split(":")

                Dim fragment As String = Nothing
                For count = 0 To strArray.Length - 1
                    fragment = fragment + strArray(count)
                Next

                fileLocation = "http://127.0.0.1/updates/" + fragment

                If System.IO.File.Exists(strArray(strArray.Length - 1)) Then
                    My.Computer.FileSystem.DeleteFile(strArray(strArray.Length - 1))
                End If
                My.Computer.Network.DownloadFile(fileLocation, strArray(strArray.Length - 1))
                fileToDL = reader.ReadLine()
            Loop
            'My.Computer.FileSystem.DeleteFile("updatelist.txt")
        End If

Here is my updatelist.txt:

VB.NET:
:LOLIMCOOLDOWNLOADME.txt
:superdltst.txt
:test.html
:Foldertest\:loltestfolder.txt
:another cool update.txt
:config.ini

Yeah stupid file names, I know but it works.

I know I am missing something but I just can't see it. -.-

I double checked all the file names, they are correct.
 
Last edited:

Latest posts

Back
Top