Problem with version checker

MrLucky

Freshman
Joined
Mar 5, 2006
Messages
47
I'm trying to create a version checker in C#. But I have a little problem.

I have a webpage, containing only the version. (http://ircbot.aoe3capitol.nl/e107_plugins/ircbot_menu/version.php)

I want that version to a double in C# so I can compare it with the version of the program.

But the problem is, when I use Convert.ToDouble or double.Parse the dots disapear, so the version will become 35 instead of 0.3.5.

How can I fix this?

My Function:

C#:
		private void Checkversion()
		{
			System.Net.WebClient wClient = new System.Net.WebClient();
			byte[] buffer = wClient.DownloadData(@"http://ircbot.aoe3capitol.nl/e107_plugins/ircbot_menu/version.php");
			double latest_version =  double.Parse(System.Text.Encoding.Default.GetString(buffer, 0, buffer.Length));
			double current_version = double.Parse(settings.Version);
			wClient.Dispose();
			
			MessageBox.Show("Latest: " + latest_version.ToString() + "\nCurrent: " + current_version.ToString());
			
			if(current_version < latest_version)
			{
				DialogResult result = MessageBox.Show("Er is een nieuwe versie van Lucky Bot beschikbaar. Wil je deze nu downloaden?", "Nieuwe versie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
				if(result == DialogResult.Yes)
				{
					System.Diagnostics.Process.Start("http://sourceforge.net/project/showfiles.php?group_id=164639&package_id=186478");
					Application.Exit();
				}
			}
		}
 
Last edited:
0.3.5 isn't a valid number as a number can only have one decimal place. A version number should be either treated as a string. Or treated as seperate Major and Minor numbers (plus any addition divisions required). So for your example of 0.3.5 you could store it as a string, then use Split to seperate it at the dots. You could then parse each individual part as a number to compare the version.
 
That would certainly work for a simple comparison. I was just assuming that the application would perhaps act differently depending on if it is a major or minor version change.
 
You might want to take a quick look at the System.Version class. After you convert the data to a string, you can create a Version object to easily compare parts of the version number.
 
It's worth noting this Class isn't specific to .Net 2.0 and was included in .Net 1.1. I'd personally never heard of it, but I'll keep it in mind incase I ever have to do something like this. One thing I would say is that (certainly in 1.1) there appears to be no way to parse the information from a string. Whilst it will make comparing version numbers easier it seems to me like you will still have to manually parse the data read in. (Obviously this doesn't apply if your comparing with a server that can return an object).
 
It's cool. I only knew about it becuase I used it once. Otherwise, the version class is one of those obscure, single purpose classes that is really handy when you need it if you know about it and makes life difficult if you don't know about it.
 
Back
Top