Rolling Out Your Own HTML Application Version Control [con't]
As mentioned earlier, the Window_OnLoad()
subroutine calls CheckforUpdates()
and sets the app name and version in the page footer:
CheckForUpdates
retrieves the latest version number from the website using
the ParseTextFromHTML()
function. The appropriate update message is displayed
depending on the version numbers. No message is displayed at all if the current
and latest versions are the same:
CreateObject()
function. It
takes an object class name, which is often in the format of <application
name>.Application
. It can throw an error if the object doesn't exist, but
we aren't too concerned because the HTA won't run at all without IE:
Error Handling
On the subject of errors, the ParseTextFromHTML()
function returns something
whether or not the Navigate()
function manages to fetch the requested resource
because the IE object does not have direct access to HTTP status codes. For
that reason, the above code does not check for errors other than validating
the length of the return string. More thorough error checking could easily be
implemented by using a RegExp
object to validate the format of the innerText
string. It is also possible to get the status code from the page source as the
Internet Explorer browser displays an error page when it can't find the requested
resource. In this updated snippet from the ParseTextFromHTML()
function, the
404
status code is parsed from the Microsoft "Page Not Found" web
page. The Err
object is populated with our relevant information so that the
CheckForUpdates()
sub can catch the error:
It's better practice to use errors when something goes wrong, rather than to
simply check for some occurrence. In the CheckForUpdates()
code below, we can't
trap an error in the traditional sense because the error handling is set to
"Resume Next
". That means that it proceeds whether a line throws
an error or not (on the positive side, we can always be sure that errors won't
cause any code to be skipped). That's why the Err.Number
is tested immediately
after the call to ParseTextFromHTML()
. If the version number file is not found,
an error message is displayed and the Error object is reset for later use:
That concludes our look at version checking. The next step from here will be to look at some ways to update the HTA to the newer version. There are a few ways to go about it, as we'll see shortly.
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. In 2007, Rob recorded the KNIGHTFALL CD in collaboration with the former Ivory Knight vocalist and legendary guitarist/producer, Jeff Waters of Annihilator fame. A completely FREE high quality MP3 download of his "Ultraviolence" intrumental, is availalable from his website, www.robgravelle.com. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: November 16, 2009