Tuesday, September 25, 2007

A simple 'Check for updates'

My brother asks when I'll post something interesting on here, but it hasn't happened yet so I doubt it will anytime soon... Anyway it seems the most boring posts are the most popular so I'll keep on posting crap.

Back to the point of this post. Lots of applications these days will check for an update when they start or when you press a 'Check for updates' button or menu item. Some really annoying applications have some little helper process that runs continuously and checks on a regular basis then throws up a big dialog telling you that there's an update (that's you Apple).

Not wanting to be left out, I thought I'd do the same. But being incredibly lazy, I couldn't be bothered to implement it completely. So this little bit of code will read a text file stored on the web server and tell the user that an update is available. It won't do anything fancy like download it for them or install it but I might add that at some point. Usage is simple, set the Url property to tell the component where the text file is stored, then call CheckLatestVersion() to show a message saying there is a new version available.

 

using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows.Forms;

namespace FreeFlowAdministrator
{
    /// <summary>
    /// Component to check for updates for an application.
    /// </summary>
    public class UpdateChecker : System.ComponentModel.Component
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public UpdateChecker(System.ComponentModel.IContainer container)
    {
      ///
      /// Required for Windows.Forms Class Composition Designer support
      ///
      container.Add(this);
      InitializeComponent();
    }

    public UpdateChecker()
    {
      ///
      /// Required for Windows.Forms Class Composition Designer support
      ///
      InitializeComponent();
    }

    /// <summary> 
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }


    #region Component Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      components = new System.ComponentModel.Container();
    }
    #endregion

    private string url;
    public string Url
    {
      get
      {
        return url;
      }
      set
      {
        url = value;
      }
    }

    public string GetLatestVersion()
    {
      HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);

      // Sends the HttpWebRequest and waits for the response.
      HttpWebResponse myHttpWebResponse = myReq.GetResponse() as HttpWebResponse;
      try
      {
        Stream response = myHttpWebResponse.GetResponseStream();
        StreamReader readStream = new StreamReader(response, System.Text.Encoding.GetEncoding("utf-8"));
        return readStream.ReadToEnd();
      }
      finally
      {
        // Releases the resources of the response.
        myHttpWebResponse.Close();
      }
    }

    public void CheckLatestVersion()
    {
      string latestVersion = GetLatestVersion();
      string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
      if (latestVersion == currentVersion)
        MessageBox.Show("You are using the latest version");
      else
        MessageBox.Show(string.Format("The latest available version is {0}\nYou are using version {1}", latestVersion, currentVersion));
    }
  }
}

Thursday, September 20, 2007

Getting directions using Google Maps

I'm not sure when this feature was added but Google Maps now lets you drag your route around, if you want to go via a particular place. I'm not sure how useful this will be for me, but it's certainly cool to play with. Saying that I have asked for a web app to create Google Maps routes previously, and this is certainly heading in the right direction. It's possible to embed the map in a web page via an IFrame pretty easily, but I can't add markers and images, so not quite there yet. I was going to embed the route of my bike ride today but of course it doesn't understand about going off road or, erm, going through pedestrianised areas so I didn't have any luck with that.

Another great new feature is the information about bus departures, although weirdly I'm only seeing these in my local area, Kingston. It seems to be getting its information from Transport Direct, a website I've never seen before, but that looks like it goes some way to fulfilling my request for a site with complete knowledge of all the different transport options. It seems to be missing some pricing information but it knows about trains, buses and cars. Depressingly enough, cars are always cheaper than the more environmentally friendly option. Saying that, it claims a 200 mile journey by car is more environmentally friendly than the train, if the car has 4 occupants. But the train will be running anyway and using just the same amount of CO2, so what to do?

Some time ago I complained that Google Maps' directions to Heathrow from my house were completely ludicrous. Well it looks like they've fixed that as well, I'm sure they must have read my post...

Wednesday, September 19, 2007

Buy a people carrier

PeopleCarrier It got us to Spain and back in one piece with not a hiccup, but now it's time to pass our trusty vehicle on to someone else. If you're interested then check it out. All reasonable offers will be considered.

Monday, September 17, 2007

More reliable wireless

When I set up our wireless router, I initially set it up as an unsecured network and restricted access to certain MAC addresses. This worked fine but when we had visitors who wanted to use our wireless connection, it was a bit of a pain to allow access to their laptop. So I changed the router's configuration so it used WPA security and it all seemed to be working fine.

But then a couple of things happened which I didn't realise were related to this seemingly simple change I'd made. First, the wireless connection would stop working every few hours. This affected any computer connected to the network and would typically last a few minutes and then everything would be fine again. This was particularly annoying when I was connected to somebody's VPN and would have to re-establish a connection. The second problem was my Vista PC started to lock up completely. This was less frequent, about once a day.

I put the first problem down to the number of wireless networks in close proximity to our house. I guessed that they were just interfering with each other and causing the connection to drop every so often. Either that or our router was just getting on a bit. Then the other day I thought I'd give Vista's wireless diagnostics a spin and it told me the wireless security key was incorrect. What the...? This kicked my befuddled brain into action and realised these connection problems had started at the same time as the switch to WPA. So I switched back to an insecure network and lo and behold, the wireless connection is working a treat. Not only that but I haven't (fingers crossed) had a Vista freeze since the switch back.

So, if you're having wireless troubles, consider switching to an insecure network. I guess it may well be specific to my router but it may just work. Yeh, hackers can probably read my email, but frankly I hope they have more interesting things to do with their time.

Sunday, September 16, 2007

Are we in a fast moving industry?

It's virtually taken for granted that we work in a fast moving industry and the facts would appear to back up this theory. Just look at the new programming tools coming out of Microsoft (I'm just going to talk about them since I don't really even try and keep up with technology coming out of other companies). In no particular order, some of them are: WPF, WCF, WF, Silverlight, Linq, CardSpace, Virtual Earth, ASP.NET AJAX, Vista...

But hang on a second, who is using this stuff and how much of it will be relevant in five years time? Myself, the only new technology I'm looking at is Windows Workflow, since it may well be useful in my job. The rest may become relevant at some point and if and when it does I'll start looking at it then. And I'm a  geek who likes to fiddle around with new technology. What about the normal people out there who aren't obsessed with software?

Well, it doesn't look so good there either. Take IE7, which has been out for almost a year. Usage stats on the sites I maintain suggest just over 30% of IE users have upgraded to version 7. This is a free bit of software, but still almost 70% of users haven't upgraded. Admittedly some of these will be corporate users who have probably decided not to roll it out yet, but why not? Probably because IE6 is good enough, thank you very much.

And what about Vista? Well I'm seeing just short of 5% of Windows users are on Vista, which makes it somewhat more popular than Server 2003 (and who browses the internet from Server 2003 anyway?) but still less popular than Windows 2000 which, as the name suggests, is about 7 years old.

Here's something else to illustrate my point. I was up the loft the other day and found the notes for a C++ course I went on about 10 years ago. Flicking through them I realised I should probably keep hold of them, since they were still relevant today. Not only were they useful to C++ programming, but also to C#. The basic ideas behind object-oriented programming still apply. And you know what, if I still had the notes for my university C++ course from 17 years ago, they would probably still be relevant as well*

So yes, it's certainly possible to think we work in a fast-moving industry and it's certainly possible to work as if everything is in a constant state of flux. But it's also possible to move into a slower lane and just watch the shenanigans going on from a distance, wait for the dust to settle and learn the stuff that actually becomes important.

 

*You may be wondering why I needed to go on a C++ course when I was working if I'd already been taught it at university. Well I never paid much attention at uni, I was more interested in getting drunk and trying to pull young ladies...

Tuesday, September 11, 2007

Handling 404 errors in PHP

If you're running a PHP site on your own server, you can find out what 404 errors have occurred by viewing the log files. If, like me, you're running your PHP site on a cheap and cheerful host, you're probably not going to have access to the log files. But you can probably still do something to find out about them.

The first thing to do is ensure your users see a useful error message, rather than the default provided by your host, which will probably be some page advertising their services. This can be achieved via the .htaccess file, if your site is running on Apache. IIS has similar features, available through its admin tool (although I can't believe there are many people using PHP on IIS). Add something like the following to the .htaccess file to tell Apache to show your custom error page.

  ErrorDocument 404 /error.php

The next thing to do is to make sure you get notified if somebody ends up on a non-existent page on your site, so just add the following code to error.php somewhere.

  
  $message = "URL: " . $_SERVER["REQUEST_URI"] . "\n" . "Referrer: " . $_SERVER["HTTP_REFERER"] . 
    "\n" . "Browser: " . $_SERVER["HTTP_USER_AGENT"];
  mail("you@wherever.com", "404 error", $message);

And that's that. Well except the referrer doesn't seem to work for me... But it's already been useful, I've found one spurious bit of CSS trying to load an non-existent image, although I've also had quite a few false positives.

Friday, September 07, 2007

Yet more tick mark fun

I've written about this three times now. Read my previous posts here

But it turns out it's not as simple as the browser somebody is using. The other day I noticed that my tick marks weren't displaying on a computer that had IE7 installed. After more fiddling around I realised the fonts installed on that particular PC must be different to the ones installed on other PCs I'd tested and IE7 was unable to find the tick mark. I'm not sure whether IE7 only uses the current font or if it tries other fonts in an attempt to find the correct symbol but in any case it just displayed a square block.

Because of this I'm thinking perhaps the only 100% reliable solution is to either use an image or to display a checkbox in all situations, not just for IE6. In a desperate attempt to avoid either of those solutions, I've started using the 'Arial Unicode MS' font for my document. I guess this is fairly unlikely to work on Macs and Linux boxes, but they aren't particularly high on my list of required supported environments and they will fall back to more conventional fonts anyway, which hopefully work for these computers.

Update: Even the ‘Arial Unicode MS’ font won’t always work, even on Windows. This font is not installed by default on Windows systems, but it does come with Office, which I guess most Windows users will have installed.

Sunday, September 02, 2007

Road trip map

After some fiddling around with Google Maps I've managed to come up with a little map of our journey through France and Spain. It would be way cool if somebody came up with a web app that could be used by normal people to do this kind of thing...