Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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:

 

	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();
			}
		}
	}

Edited by MrLucky
Posted
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.
Anybody looking for a graduate programmer (Midlands, England)?
Posted
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.
Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]
Posted
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).
Anybody looking for a graduate programmer (Midlands, England)?
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...