Results 1 to 20 of 20

Thread: Help with Program Update?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Unhappy Help with Program Update?

    Code:
     Private Sub CheckForUpdate()
            'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{512D18C2-805F-4EEC-8D03-D90EBDFAEBD9}
            'Try
            Dim base As String = "http://lobsterproductions.x.gg/Products/HTML%20Easy%20Edit"
            Dim startup As String = Application.StartupPath
            If (My.Computer.FileSystem.FileExists(startup + "\version.txt")) Then
                My.Computer.FileSystem.DeleteFile(startup + "\version.txt")
            End If
            My.Computer.Network.DownloadFile(base + "\version.txt", startup + "\version.txt")
            Dim newversion As Double = Convert.ToDouble(My.Computer.FileSystem.ReadAllText(startup + "\version.txt"))
            If (newversion > Application.ProductVersion) Then
                If (MsgBox("New updates available, do you wish to download them? Please make sure you have an active internet connection before proceeding.", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
                    'download new version
                    If (My.Computer.FileSystem.FileExists(startup + "\files.txt")) Then
                        My.Computer.FileSystem.DeleteFile(startup + "\files.txt")
                    End If
                    My.Computer.Network.DownloadFile(base + "\files.txt", startup + "\files.txt")
                    Dim todownload As New TextBox
                    todownload.Multiline = True
                    todownload.Text = My.Computer.FileSystem.ReadAllText(startup + "\files.txt")
                    Dim line As String = ""
                    Dim exename As String = Application.ExecutablePath.Remove(0, Application.ExecutablePath.LastIndexOf("\") + 1)
                    For Each line In todownload.Lines
                        If (line = "html-setup.exe") Then
                            If (My.Computer.FileSystem.FileExists(startup + "\" + line)) Then
                                My.Computer.FileSystem.DeleteFile(startup + "\" + line)
                            End If
                            frmDownload.ShowDialog()
                            frmDownload.DownloadFile(base + line, startup + "\" + line)
                            My.Computer.Network.DownloadFile(base + line, startup + "\" + line)
                            Process.Start(startup + "\" + line)
                            Application.Exit()
                        Else
                            If (line = exename) Then
                                My.Computer.Network.DownloadFile(base + line, startup + "\" + line + ".new")
                            Else
                                If (My.Computer.FileSystem.FileExists(startup + "\" + line)) Then
                                    My.Computer.FileSystem.DeleteFile(startup + "\" + line)
                                End If
                                My.Computer.Network.DownloadFile(base + line, startup + "\" + line)
                            End If
                            MsgBox("Download successful! Application is now restarting.", MsgBoxStyle.Information)
                            If (My.Computer.FileSystem.FileExists(Application.ExecutablePath + ".old")) Then 'FIX IF YOU UPDATED IT AT LEAST ONCE
                                My.Computer.FileSystem.DeleteFile(Application.ExecutablePath + ".old")
                            End If
                            My.Computer.FileSystem.RenameFile(Application.ExecutablePath, exename + ".old")
                            My.Computer.FileSystem.RenameFile(startup + "\" + exename + ".new", exename)
                            'My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{512D18C2-805F-4EEC-8D03-D90EBDFAEBD9}", "DisplayVersion", Application.ProductVersion)
                            Application.Restart()
                        End If
                    Next
    
                Else
                    MsgBox("Updates must be downloaded since this is a beta version. Please make sure you have an active internet connection.", MsgBoxStyle.Information)
                End If
            Else
                MsgBox("No new updates are available.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information)
            End If
            'Catch ex As Exception
            'MsgBox(ex.Message)
            ' End Try
        End Sub
    Well i get an error trying to do this- i got this code from a youtube video and on the
    Code:
    Dim newversion As Double = Convert.ToDouble(My.Computer.FileSystem.ReadAllText(startup + "\version.txt"))
    line i get an error saying "Input string was not in a correct format."

    I cant figure out why this is not working- Thanks for Help!!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    You're reading the contents of a file and trying to convert it to a Double, but the contents of the file doesn't represent a valid Double value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Help with Program Update?

    the file's text is 1.0.0.1

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    That's obviously not a valid Double because a number can't have multiple decimal points. If you're going to use a 4-part version like that then you should use the Version class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Help with Program Update?

    well how can i convert string to version?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    Quote Originally Posted by reconrey View Post
    well how can i convert string to version?
    You should read the documentation for the Version class and you will find out.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Help with Program Update?


  8. #8
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    Re: Help with Program Update?

    VB.Net Code:
    1. Dim str as String = "1.0.0.1"   'string that is read from your TEXT FILE as string!!!
    2. Dim appVerNew as Version = New Version(str)  'string to version number (thats not double!)
    3. Dim appVer As Version = My.Application.Info.Version  'current app version
    4. If appVerNew > appVer Then
    5.    'update available
    6. End If
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2010
    Posts
    106

    Re: Help with Program Update?

    Thanks.

  10. #10
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    Re: Help with Program Update?

    np
    please mark the thread resolved...
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  11. #11
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Help with Program Update?

    There is a much easier way to accomplish this:

    vb.net Code:
    1. Dim GetRemoteValue As New WebClient()
    2. Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt")
    3. GetRemoteValue.Dispose()
    4.  
    5. If remoteValue > Application.ProductVersion Then
    6.     'do youre thing
    7. End if


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  12. #12
    Hyperactive Member Zeljko's Avatar
    Join Date
    Oct 2006
    Location
    Internet
    Posts
    441

    Re: Help with Program Update?

    Quote Originally Posted by Radjesh Klauke View Post
    There is a much easier way to accomplish this:

    vb.net Code:
    1. Dim GetRemoteValue As New WebClient()
    2. Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt")
    3. GetRemoteValue.Dispose()
    4.  
    5. If remoteValue > Application.ProductVersion Then
    6.     'do youre thing
    7. End if
    I don't think that you can compare if
    one String is bigger then another String. What did you expect from comparison String > String to happen?
    1. If this post helped you, please Rate it = That's You, saying Thanks, to Me ...Left side of this post: [Rate this post]
    2. Mark this Thread Resolved if your question has been answered That's You, saying Thanks, to Group ...Menu on top of your original Post: [Thread Tools]>[Mark Thread Resolved]
    3.
    Check my site: www.er-ef.netCheck my snippets: Get installed .NET versionsRegex extractingJoin hierarchically nested Datatables in one flattened Datatable


  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    Quote Originally Posted by Radjesh Klauke View Post
    There is a much easier way to accomplish this:

    vb.net Code:
    1. Dim GetRemoteValue As New WebClient()
    2. Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt")
    3. GetRemoteValue.Dispose()
    4.  
    5. If remoteValue > Application.ProductVersion Then
    6.     'do youre thing
    7. End if
    Doing that, version 1.10 will be considered earlier than version 1.2.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Help with Program Update?

    Don't see the problem. The programmer knows how to set the value, which means also the length. But perhaps you have a point there.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    Quote Originally Posted by Radjesh Klauke View Post
    Don't see the problem. The programmer knows how to set the value, which means also the length.
    You don't see the problem with 1.2 being less than 1.3 and greater than 1.10? I don't think I'll be using any of your software.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Help with Program Update?

    Like I said in my earlier post: The programmer knows how to set the value
    That is why I don;t see the issue. If a programmer doesn't know how to set the value...

    But I understand what you are saying. Personally I see 1.3 greater then 1.10. I read it as 1.30, otherwise it would be set it like: 1.03. But that is how I think about it.
    Last edited by Radjesh Klauke; Jun 29th, 2010 at 02:42 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    Quote Originally Posted by Radjesh Klauke View Post
    Like I said in my earlier post: The programmer knows how to set the value
    That is why I don;t see the issue. If a programmer doesn't know how to set the value...
    What does that even mean? You're saying that the programmer should use string comparisons to determine whether a version on the server is newer than the current version, right? So, you release version 1.0.0.0. You then fix a bug and release version 1.0.0.1. No worries, your comparison shows that "1.0.0.1" is greater than "1.0.0.0" so the new version is downloaded. This continues on for a while until the user has version 1.0.0.9 installed. Now, you fix another bug and you releases version 1.0.0.10. The application now checks the server but it determines that "1.0.0.10" is less than "1.0.0.9" so it doesn't download the new version. Do you see the problem now? Your code simply doesn't work. It will work some of the time but not all of the time and code that doesn't work all of the time is broken code.

    The Version class was created specifically for this purpose so the Version class should be used. You can compare two Version objects and each part of the two values will be compared numerically, as it should be. Numbers should NEVER be treated as text except for the purposes of display and persistence.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    Quote Originally Posted by Radjesh Klauke View Post
    Like I said in my earlier post: The programmer knows how to set the value
    That is why I don;t see the issue. If a programmer doesn't know how to set the value...

    But I understand what you are saying. Personally I see 1.3 greater then 1.10. I read it as 1.30, otherwise it would be set it like: 1.03. But that is how I think about it.
    And then what about when you get to version 10.0? Should you use version 01.00 for your initial release? If you just use the Version class that has been designed for this purpose then all these considerations go away and it just works.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  19. #19
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Help with Program Update?

    Aha!!! That's a very good point you have there.

    This is how I use it ath the moment:
    e.g.: 10.100.100 = the first "10" as a large version update, the first "100" for fixes and the last one for minor-fixes. So I never had any problems.

    Assuming this isn't the proper way as you are saying, and I want to code proper, I'll have a look into it. Thanks for the info. Much appreciated.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  20. #20
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help with Program Update?

    I've seen various ways of writing version numbers but there's really no need to do anything other than have four standard numbers separated by dots because the .NET Version class handles comparisons for you. You can create one from an appropriate string and compare it to another.
    vb.net Code:
    1. Dim v1 = "1.2.0.0"
    2. Dim v2 = "1.10.0.0"
    3.  
    4. If New Version(v2) > New Version(v1) Then
    5.     MessageBox.Show(v2 & " is later than " & v1)
    6. Else
    7.     MessageBox.Show(v1 & " is later than " & v2)
    8. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

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