Just some changes I made..
In the CheckForUpdate Routine:
TargetFile = SpecialFolder.UserHome.Child("Downloads").child(DownloadPath)
if TargetFile.Exists then
TargetFile.Delete
if TargetFile.LastErrorCode <> 0 then
// there is an error
An example is the case that you have downloaded the installer file and it has opened but not yet installed. You then restart the program and restart the download you have a locked existing file which can not be deleted nor overwritten. Without checking for an error, the software will hang unless a cancel download is implemented.
I modified the check for version:
// now check for updates being available:
if major> app.MajorVersion then
// major update available
canupdate = true
else
// no major update, so check that at least major version is the same before checking for minor version
if major > app.majorversion then
// check for minor version is valid
canupdate = true
else
// no minor update, so check that at least minor version is the same before checking for bug fix version
if minor = app.minorversion then
// check for bug fix version is valid
if bug > app.bugversion then
canupdate = true
end if
end if
end if
end if
This is not necessary, but useful if you are developing: for example if your development version is 3.1.0 and the version on the web server is 3.0.6, then the old code would indicate that 3.0.6 is newer than 3.1.0.
I did not disable the Cancel button when a download was started and changed the Action method to the following:
This terminates the download and closes the socket first to prevent an exception.
For UpdateSocket.DownloadDone I changed the following:
//dim f as FolderItem = SpecialFolder.UserHome.Child("Downloads").child(DownloadPath)
dim msg as MessageDialog
dim b as MessageDialogButton
if httpStatus = 200 then
// download successful
if file <> nil and file.exists then
file.Launch
Quit
end if
else
msg = New MessageDialog
msg.Icon = msg.GraphicCaution
msg.ActionButton.Caption = mDownloadFailedActionButton
msg.ActionButton.Visible = true
msg.Message = mDownloadFailedActionMessage
msg.Explanation= mDownloadFailedActionExplanation1
b = msg.ShowModal
wUpdateWindow.Close
end
First, I use the "file" folder item as it is safer. Secondly, I check for HttpStatus = 200, which means download successful. A wrong filename for example will complete the download with HTTPStatus = 404 and an empty targetfile.