Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i am new here i am trying to make an auto updater i have finished some parts but i am stuck at big part of program.

i want to make this program to get update through each old versions..like if launcher version is 1.0 and latest version is 3.0 so it should take update from 2.0 then take update from 3.0 is it possible?
thank you
here is my code
VB
Imports System
Imports System.IO
Imports System.Net

Public Class Form1

    Dim File = Application.StartupPath + "\launcher"
    Dim Section3 = "AutoUpdate"
    Dim AutoUpdateFunction = "AutoUpdateFunction"
    Dim Version = "Version"
    Dim Status = "Status"
    Dim Section4 = "Version"
    Dim Ver = "ver"
    Dim WithEvents WC As New WebClient
    Private WithEvents httpclient As WebClient
    Dim imageAddress As String = String.Empty
    Dim filename As String = String.Empty
    Dim Check As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        persent.Text = ""
    End Sub
    Private Sub WC_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
        ProgressBar1.Value = e.ProgressPercentage
    End Sub
    Private Sub dpc(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
        persent.Text = e.ProgressPercentage
    End Sub
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If ReadIni(File, Section3, AutoUpdateFunction, "") = "on" Then
            Try
                Dim web As New WebClient()
                Update.Text = "Checking for Update!"
                Dim response = web.DownloadString("http://107.170.123.131/ver.txt")
                Dim check = (ReadIni(File, Section4, Ver, "ver"))
                If check = response Then
                    Button3.Enabled = True
                    Update.Text = "Game Updated"
                Else
                    httpclient = New WebClient
                    imageAddress = "http://www.wratho.net/patch_31.dat.zip"
                    filename = imageAddress.Substring(imageAddress.LastIndexOf("/") + 1)
                    AddHandler httpclient.DownloadFileCompleted, AddressOf Downloaded
                    Try
                        httpclient.DownloadFileAsync(New Uri(imageAddress), (filename))
                        Update.Text = "Updating!"
                    Catch ex As HttpListenerException
                        MsgBox("SH*T!!!!!!")
                    Catch ex As Exception
                        Update.Text = "No Response From Server"
                    End Try
                End If
            Catch ex As HttpListenerException
                MsgBox("Error accessing " + imageAddress + " - " + ex.Message)
            Catch ex As Exception
                MsgBox("No Response From Server")
            End Try
        Else

        End If
    End Sub
    Private Sub Downloaded()
        If System.IO.File.Exists(filename) = True Then
            Button3.Enabled = "True"
            Update.Text = "Updates are done!"
        Else
            MsgBox("Doesn't exist", 64, "Open")
        End If
    End Sub
End Class
   
Module modINI

    Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
    Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As String, ByVal lpDefault As String, _
    ByVal lpReturnedString As String, ByVal nSize As Int32, _
    ByVal lpFileName As String) As Int32

    Public Function ReadIni(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As String
        Dim ParamVal As String = Space$(1024)
        Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)
        ReadIni = Left$(ParamVal, LenParamVal)
    End Function
End Module


and here is file that i link for updater
Auto Updater v1.0

[Settings]
Title=Auto Updater

[Website]
Notice=News link
Register=Register page link



[AutoUpdate]
AutoUpdateFunction=on
Status="Version link" (IMPORTANT)'i used this link <a href="http://107.170.123.131:80/ver.txt">http://107.170.123.131:80/ver.txt</a>

[Version]
Ver=1.0
Posted
Updated 5-Aug-14 20:24pm
v2
Comments
Sergey Alexandrovich Kryukov 5-Aug-14 19:42pm    
You have many problems here: no separation between UI and application code, doing it all in a form class; use if INI file format. But you did not explain your problem. What are you trying to achieve, more exactly? What is "get update"? What are you going to do with the update?
—SA
UttamRabadiya 6-Aug-14 1:11am    
hello,
first thank you for your reply,
it is auto updater for my game i am trying to make like if game have new version than everyone should get updates
i did success to match version and check for updates.. i want to make it like if client version is 1.0 and latest version 3.0 then client will get all updates in line for example first it will update 2.0 then 3.0.. thank you sir and sorry for bit bad english and coding because i am still learning it :)
Sergey Alexandrovich Kryukov 6-Aug-14 1:19am    
No need to apologize, it's natural when you are learning. You English is clear enough (only you need to add proper capitalization and punctuation), the problem is different: you don't explain enough detail. I still did not get how is it supposed to work and what is your problem.
—SA
UttamRabadiya 6-Aug-14 2:26am    
Hello,
i am trying to make this launcher that start my game. this launcher work as to check version and if version is up to date then it will start the game and if client version is old then it should download the new version. I have updated the code might it will be easy to understand
thank you
Sergey Alexandrovich Kryukov 6-Aug-14 2:42am    
Sorry... Who will read your code and understand it if you are not telling what is your problem?
—SA

Create one level of indirection.

Right now, you have separate URLs for v.1, v.2, v.3.0, v3.1, etc. No wonder, you cannot guarantee that your application can find the latest URL, or any other URL with the update except the one which comes with your application. This problems is solved in a really simple way.

Add one more URL, a fixed one, which you never modify. At this URL you should place some file which gives you the URL of the latest update or, if you want your application to choose from a set of updates, all the URLs of all the updates. The best way to do so would be put this information in some XML file. For example:
XML
<?xml version="1.0"?>
<MyApplicationUpdates>
    <versions>
        <version verisionid="1" url="http://www.mySite.net/myApplication/updates/v.1" />
        <version verisionid="2.0" url="http://www.mySite.net/myApplication/updates/v.2.0" />
        <version verisionid="3.0" url="http://www.mySite.net/myApplication/updates/v.3.0" />
        <version verisionid="3.1" url="http://www.mySite.net/myApplication/updates/v.3.1" />    
    </versions>
    <!-- whatever else you may need need -->
</MyApplicationUpdates>


As you can see, the format of versions and respective URLs can be different, but your XML file would provide all the information. It can be any other kind of file with the same information, but XML is the most convenient; it is standardized; and .NET FCL provides different classes to parse it.

Now, the procedure for publishing updates will be this: first, you develop a new version of the product under the new version of its assembly (assemblies) and put on your site. If at this moment someone initiate update from your application, the XML will still provide the previous version as the latest accessible to the user. Then you need to update the XML by adding one <version> element to it. Then your application will get it: it will first access XML, parse it, find the latest version and then will download the required version of the product using URL obtained from your XML.

—SA
 
Share this answer
 
v3
Comments
UttamRabadiya 6-Aug-14 3:38am    
Hello,
thank you sir i was just looking for something like this :)
so can i link this xml file as the fixed link?
and it will take every update?
i still have some questions :3
If i will link this xml file at Version check file, then will it work?
for example for now i did link one ver.txt file that check update if i make new version there then it will update.. so if i will link this XML file and it will check if version = 1.0 then this link and if version = 2.0 then link will be new one. will it work like that? thank you :))
Sergey Alexandrovich Kryukov 6-Aug-14 3:53am    
You just put some XML file on some fixed location on some site.
And then your application would need to download this file to stream using, say HttpWebRequest. It's better to use stream without saving the file, because XML parser can parse from stream.

I don't understand what is "link XML file". I just explained what to do above. In your application, you will parse XML into some data structure with the collection of versions. The it reads own version, compares with update versions and select the one you need for update. Use the type System.Version. This is really simple.

—SA
Assuming your update function itself works, then you are asking how to get updates from 2.0 through to 3.0 assuming the current version is 1.0 and the latest version is 3.0?

If you only ever release whole number releases, then it's not too hard to iterate from current release to latest release - so I'm asusming you need to update all of

1.1, 1.2, 1.3 ... 1.23, 2.0, 2.1 etc

here you will need to store a list of all version in the text file you are downloading, then iterate through that, using each version number higher than your current version to trigger the update- so instead of the file containing just the latest release number, it contains the latest and all previous.

3.0
2.21
2.20
2.19
2.18
...
2.0
1.4
1.3
1.2
1.1
1.0

So you read through it, from the bottom up, until you reach your current release, then keep reading and install the update from that version, until you hot the end...
 
Share this answer
 
Comments
UttamRabadiya 6-Aug-14 2:54am    
Hi mate,
can you explain it with any example i didnt understand it fully sorry
and one more thing is it possible to set link on each version.. like if it will download 1.1 then link should be this? thank you for reply :)
_Maxxx_ 6-Aug-14 7:38am    
You would need to have a version file that contains all of the version numbers that have been released.
You would compare the current running version against the highest of these versions.
If the current version < highest version then you need to update.
Take the next version higher and download the patch, apply it, and re-run the update process.

e.g. Your version is 1.1
latest version is 2.0
In between you have released 1.2, 1.3 and 1.4

program runs, downloads file with
1.0
1.1
1.2
1.3
1.4
2.0
say you put them in an array.
Now, compare 1.1 (current version) with 2.0 (highest version) - not the same so you need to update
start at beginning of array
Is 1.0 > 1.1 - no, go to next element
Is 1.1 > 1.1 - no, go to next element
id 1.2 > 1.1 - YES
Get the update at http://www.wratho.net/patch_1.2.dat.zip and apply it
Your current version is now 1.2, so repeat the process
is 1.0 > 1.2 - no
is 1.1 > 1.2 - no
is 1.2 > 1.2 - no
is 1.3 > 1.2 - YES
Get the update at http://www.wratho.net/patch_1.3.dat.zip and apply it
Your current version is now 1.2, so repeat the process

so, each time you perform the update you have to build the url ("http://www.wratho.net/patch_" + arrayOfAvalableVersions[currentIndex] + ".dat.zip")

You could also do the same sort of process on an XML file like SAK proposed - where the file would take the place of the text file and you would have the complete URL defined for each release - but the process of checking the release number against the collection of all release numbers would remain the same
Sergey Alexandrovich Kryukov 6-Aug-14 3:27am    
You did not address the problem OP has. I don't even know why Uttam is interested in your answer.
I don't want to blame you: he never clearly explained the problem until the last moment, so it was hard to understand. However, his latest comment shades some light. Please see this comment to the question and my comment and my answer.
—SA
_Maxxx_ 6-Aug-14 7:27am    
The problem the OP had was "if launcher version is 1.0 and latest version is 3.0 so it should take update from 2.0 then take update from 3.0 is it possible?"
I think he was interested in my answer because I was addressing the problem rather than being arrogant.
Your answer insists he has a different url for each version which he doesn't state anywhere - his existing code he has a single hard-coded url - which is obviously not going to work!
I was trying to explain the logic with which he could address the problem. Whether he uses an XML file with separate URLs as you suggest (although your solution provides separate urls...) or a simple text file (which he is obviously familiar with) or a text file with just the version numbers and combines version number with URL to provide the updates doesn't really matter.

you told him to "add one more URL, a fixed one" - this he already does - it's in the code - "http://107.170.123.131/ver.txt"

The fact that in your example the versionid matches the url suffix is merely adding redundancy; I suppose it does give the advantage of potentially storing updates at entirely different locations, or calling the patch for version 7 'hoppy version' rather than v.7.0 - but it's unlikely that would be required.
Finally you explain to him the process, but this isn't the process he is after.

He wants a user running version 1.2 to download every version from 1.3 through tot he latest version, and not just get the latest version, thus missing out the patches.

while I can see, and I am sure you can too, that it would be easy to modify your solution to provide that functionality - the OP evidently had not thought about the logic behind doing so - which was what I was trying to explain, and what you failed to explain.

I rarely come to Q&A - and it is because of you, frankly, that i often stay away, because, rather than trying to help the OP and just getting on with that help, you insist on posting comments like that above, with an absolute arrogance that astounds me.

I would appreciate it if you did not respond to any of my posts here in future.
Sergey Alexandrovich Kryukov 6-Aug-14 10:00am    
I cannot promise you that. I just don't want to remember claims like that. In response to quite neutral comment you allowed yourself to jump into personal characteristic, blaming my attitude (having no idea of it) and to personal accusation, totally baseless.

Let me comment what I find appropriate. Remember, this is done to help OP and help you. If anyone sees any mistake of others, even potential, it must be noted, to help others avoid being mislead. So, if you want to discuss my or your solution, let's do it without all those personal characteristics. Care to start over?

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900