Real Software Forums
http://forums.realsoftware.com/

Update checker
http://forums.realsoftware.com/viewtopic.php?f=21&t=35893
Page 2 of 3

Author:  tadicboris [ Sun Feb 05, 2012 5:46 pm ]
Post subject:  Re: Update checker

Very usefull, thanks :-)

Author:  simberr [ Thu Mar 01, 2012 5:33 pm ]
Post subject:  Re: Update checker

I have taken serd83's solution and created a simple ons-step window that incorporates all of the coding he has made. It can be downloaded from here:

http://dl.dropbox.com/u/10747116/RealSt ... Window.rbw

Just drop this window onto your project tab. Double click it to open it in the editor and change the CheckForUpdate method with your reference pointers. This is shown in the code snippet below:

#if TargetMacOS then
DownloadPath = "YourDMG.dmg"
DownloadURL = "http://www.domain.com/YourDMG.dmg"
#else
DownloadPath = "YourDMG.zip"
DownloadURL = "http://www.domain.com/YourDMG.zip"
#endif

SoftwareName = "Your Cool Program Name"
VersionURL = "http://www.domain.com/YourDMG/version.txt"


As I have MacOS and Windows requirements I made the window generic for either.

Now, just add the following code in your App.Open event:

wUpdateWindow.CheckForUpdate


That's it. It works like a dream.

Thank you, serd83, for the start.

Simon.

Author:  Indy [ Thu Mar 01, 2012 9:19 pm ]
Post subject:  Re: Update checker

simberr wrote:
I have taken serd83's solution and created a simple ons-step window that incorporates all of the coding he has made. It can be downloaded from here:
Thanks to both of you.

I found one issue - the following line in the UpdateAvailable method,
LatestVersion = arr(UBound(arr))
fails if your text editor, like mine, puts a LF/CR at the end of the line. The array is created by splitting on end of lines - the extra end of line creates an extra, empty row in the array.

One fix is to use the existing information to construct the LatestVersion:
LatestVersion = s     //arr(MajorRelease)

Author:  Indy [ Thu Mar 01, 2012 9:48 pm ]
Post subject:  Re: Update checker

I also changed the following line in the UpdateAvailable method from
if ubound(arr) < 0 then return false
to
if ubound(arr) < MajorRelease then return false
Otherwise a newer version of the program would crash on an older (not updated) version.txt file.

Author:  timhare [ Thu Mar 01, 2012 10:00 pm ]
Post subject:  Re: Update checker

Indy wrote:
I found one issue - the following line in the UpdateAvailable method,
LatestVersion = arr(UBound(arr))
fails if your text editor, like mine, puts a LF/CR at the end of the line. The array is created by splitting on end of lines - the extra end of line creates an extra, empty row in the array.

Use Trim() before you Split(). It will remove the extra EOL.
updateversion = h.get(VersionURL, 5) // get the lines
arr = Trim(ReplaceLineEndings(updateversion, endofline)).split(endofline) // add each line to the array arr()

Author:  Indy [ Fri Mar 02, 2012 12:16 am ]
Post subject:  Re: Update checker

This was brought up earlier in the thread, if my version.txt file is as follows:

1.0.5
2.1.3
3.0.0

and my apps major/minor/bug versions are set to 2.1.3 the functions will indicate that no update is available.

It seems to only check for updates within the same major release number. (For my purposes I will have it check for any major or minor updates.)

Author:  simberr [ Sat Mar 03, 2012 9:27 am ]
Post subject:  Re: Update checker

The window now handles major updates. It now incorporates a major change method that will allow you to send the user elsewhere or make further decisions.

The new method is: MajorChangeUpgrade

The code has now been changed in UpdateAvailable to:

if major > app.majorversion or minor > app.minorversion or bug > app.bugversion then // check if any value is greater
LatestVersion = arr(UBound(arr))
Return True
elseif UBound(arr) > MajorRelease Then
' The Major Release has changed.
LatestVersion = arr(UBound(arr))
Return MajorChangeUpgrade
else
LatestVersion = CurrentVersion
Return False
end if

In addition, I have changed the loading routine to allow for CRLF etc.
updateversion = h.get(VersionURL, 5) // get the lines
updateversion = Trim(updateversion)
updateversion = ReplaceAll(updateversion, Chr(10), "|")
updateversion = ReplaceAll(updateversion, Chr(13), "|")
updateversion = ReplaceAll(updateversion, "||", "|")

arr = Split(updateversion, "|")


The download URL is as follows:
http://dl.dropbox.com/u/10747116/RealSt ... Window.rbw

Thank you for the feedback.

Author:  prakashp [ Mon Mar 05, 2012 9:03 am ]
Post subject:  Re: Update checker

Hi All,

Thanks for your time.

I have one doubt about the "Launch the new version" .

I run/lunch my old desktop application after that i clicked a button for check the new version of that software is exists or not. If i am getting any new version then i want to replace the old one with new one and invoke the latest exe for open the App.

So how could i run the newer version and delete/replace the old one ?
Note : Old exe is running.

Thanks,
Prakash

Author:  simberr [ Wed Mar 07, 2012 12:45 pm ]
Post subject:  Re: Update checker

In the implementation that I have posted here following the download the current running program quits and the downloaded file is launched.

On the Mac there are two types of downloadable files, the DMG and a PKG. A DMG will open and allow the user to drag and drop the latest version where he wants and the PKG will run an installer similar in use to the Windows installer.

On the Windows platform there are ZIP and EXE files. Typically an EXE file is an installer that will run and install the program over the last version.

I assume your question is coming from the Windows area. If you are deploying an app on that platform you should be using either an executable zip file that will place the files in the right places automatically or an installer. I assume that you don't want your users to manually install the application. This means that you should invest some time (and maybe some money) in a good installer. The best free installer that I used to use when I worked on the Windows platform was Inno Setup. Do a web search for this.

Hope this helps.

Simon.

Author:  prakashp [ Thu Mar 08, 2012 12:46 am ]
Post subject:  Re: Update checker

Hi Simon,

Thank you for responding my issue.

Quote:
In the implementation that I have posted here following the download the current running program quits and the downloaded file is launched.


I used the above or same logic for software updation. I used the monkeyrealsoftware for download the zip file from the ftp server and Unzip that file and quit the old exe and launch the new one. But My problem is while i Unzipping the file using the monkeyrealsoftware component, it's unzip the file after that the below line of code is not executed.

Could you please tell me what is the problems behind this.

Note : In Run time its working fine but when create a exe then run that app its not working :(


Thanks,
Prakash

Author:  simberr [ Tue Mar 13, 2012 2:22 pm ]
Post subject:  Re: Update checker

Quote:
I used the above or same logic for software updation. I used the monkeyrealsoftware for download the zip file from the ftp server and Unzip that file and quit the old exe and launch the new one. But My problem is while i Unzipping the file using the monkeyrealsoftware component, it's unzip the file after that the below line of code is not executed.


I do not use the monkeybread components so I would suggest that you contact them.

Simon.

Author:  prakashp [ Thu Mar 15, 2012 1:54 am ]
Post subject:  Re: Update checker

Hi Simon,

Thanks for your time.

Is there any other component present for communicate with Ftp server. If YES please send me some link.


Thanks,
Prakash

Author:  AngMoh [ Thu Mar 15, 2012 8:26 am ]
Post subject:  Re: Update checker

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:
UpdateSocket.Close

Close

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.

Author:  simberr [ Tue Apr 03, 2012 11:59 am ]
Post subject:  Re: Update checker

Thank you, major help.

I have incorporated these changes.

Author:  NaNdummy [ Wed Apr 04, 2012 1:14 am ]
Post subject:  Re: Update checker

I have a new update of simberrs one - with more mac compatibility. I will upload it soon.

Page 2 of 3 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/