|
-
Jun 28th, 2010, 11:41 PM
#1
Thread Starter
Lively Member
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!!!!
-
Jun 28th, 2010, 11:43 PM
#2
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.
-
Jun 29th, 2010, 12:08 AM
#3
Thread Starter
Lively Member
Re: Help with Program Update?
the file's text is 1.0.0.1
-
Jun 29th, 2010, 12:12 AM
#4
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.
-
Jun 29th, 2010, 12:22 AM
#5
Thread Starter
Lively Member
Re: Help with Program Update?
well how can i convert string to version?
-
Jun 29th, 2010, 12:26 AM
#6
Re: Help with Program Update?
 Originally Posted by reconrey
well how can i convert string to version?
You should read the documentation for the Version class and you will find out.
-
Jun 29th, 2010, 12:28 AM
#7
Thread Starter
Lively Member
Re: Help with Program Update?
-
Jun 29th, 2010, 12:34 AM
#8
Hyperactive Member
Re: Help with Program Update?
VB.Net Code:
Dim str as String = "1.0.0.1" 'string that is read from your TEXT FILE as string!!!
Dim appVerNew as Version = New Version(str) 'string to version number (thats not double!)
Dim appVer As Version = My.Application.Info.Version 'current app version
If appVerNew > appVer Then
'update available
End If
-
Jun 29th, 2010, 01:03 AM
#9
Thread Starter
Lively Member
Re: Help with Program Update?
-
Jun 29th, 2010, 01:07 AM
#10
Hyperactive Member
Re: Help with Program Update?
np
please mark the thread resolved...
-
Jun 29th, 2010, 01:36 AM
#11
Re: Help with Program Update?
There is a much easier way to accomplish this:
vb.net Code:
Dim GetRemoteValue As New WebClient() Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt") GetRemoteValue.Dispose() If remoteValue > Application.ProductVersion Then 'do youre thing End if
-
Jun 29th, 2010, 01:40 AM
#12
Hyperactive Member
Re: Help with Program Update?
 Originally Posted by Radjesh Klauke
There is a much easier way to accomplish this:
vb.net Code:
Dim GetRemoteValue As New WebClient()
Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt")
GetRemoteValue.Dispose()
If remoteValue > Application.ProductVersion Then
'do youre thing
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?
-
Jun 29th, 2010, 01:45 AM
#13
Re: Help with Program Update?
 Originally Posted by Radjesh Klauke
There is a much easier way to accomplish this:
vb.net Code:
Dim GetRemoteValue As New WebClient()
Dim remoteValue As String = GetRemoteValue.DownloadString("http://yoururl.com/version.txt")
GetRemoteValue.Dispose()
If remoteValue > Application.ProductVersion Then
'do youre thing
End if
Doing that, version 1.10 will be considered earlier than version 1.2.
-
Jun 29th, 2010, 01:49 AM
#14
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.
-
Jun 29th, 2010, 01:51 AM
#15
Re: Help with Program Update?
 Originally Posted by Radjesh Klauke
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.
-
Jun 29th, 2010, 02:35 AM
#16
-
Jun 29th, 2010, 02:44 AM
#17
Re: Help with Program Update?
 Originally Posted by Radjesh Klauke
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.
-
Jun 29th, 2010, 02:50 AM
#18
Re: Help with Program Update?
 Originally Posted by Radjesh Klauke
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.
-
Jun 29th, 2010, 03:04 AM
#19
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.
-
Jun 29th, 2010, 05:16 AM
#20
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:
Dim v1 = "1.2.0.0" Dim v2 = "1.10.0.0" If New Version(v2) > New Version(v1) Then MessageBox.Show(v2 & " is later than " & v1) Else MessageBox.Show(v1 & " is later than " & v2) End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|