Online version check
This snippet realizes a quick version check. It may come handy when realizing actual Windows applications in Perl.
In its current form it requires threads, Win32, Win32::GUI, Win32::TieRegistry and LWP::Simple . If you decide against the use of one or more of these modules, the general idea remains the same:
You need to upload a file called "yourappversion.txt" which is a 1-liner containing the numeric number of the latest program version (eg. "0.1" or "1.4").
The code below checks for the latest version by downloading the version text file. If the program is outdated, it will open the download page in your Windows default browser and exit.
This should work for Firefox, Mozilla and Opera users in the same way.
#!C:/Perl/bin/Perl
use Win32::GUI;
use Win32 ();
use Win32::TieRegistry;
use LWP::Simple;
use threads;
use vars qw($version);
$version=0.02;
checkversion();
#topictracer.com
sub checkversion {
my $url = 'http://www.site.com/yourappversion.txt';
#yourappversion.txt contains your program version, eg. "1.2". nothing else to keep it simple.
my $document = get($url);
#receive version file
return unless defined $document;
#just give up and return if site is down or file cannot be found
chomp($document);
if ($document>$version) {
my $answer=Win32::GUI::MessageBox(0, "New version available: v$document", "Title",64);
#announce the availability of a new version in a Win32 pop-up messagebox
my $childproc = threads->new(\&openurl, 'http://site.com/yourapp'); $childproc->detach;
#call "openurl" with the URL of your application's download page
exit;
#we're not gentle and simply quit. something more graceful might be appropriate
}
}
sub openurl {
my $url = shift(@_);
#get passed-on URL
$browser= $Registry->{'HKEY_CLASSES_ROOT\\http\\shell\\open\\command\\\\'};
#get windows default browser for opening "HTTP files", ergo websites
system($browser . " " . $url);
#open website using the browser we found in our registry
}