Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Apr 27, 2017 2:15 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Update checker
PostPosted: Fri Oct 15, 2010 9:21 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
This code helps you to
Quote:
Check the internet connection
Check for a new version
Download the new version
Launch the new version

How it works?
Quote:
The idea is to compare Application.MajorVersion, Application.MinorVersion and Application.BugVersion with a text file on the server. The text file becomes for every new major release a new line. For example you release your application first time. Application.MajorVersion, Application.MinorVersion and Application.BugVersion have this values: 1.0.0, your text file have this values too. If there is a new update, you change only the second and third value in the text file and the values for Application.MinorVersion and Application.BugVersion and upload the new version to the server. If there is a new major release, you add a new line to the text file e.g. 2.0.0.

You just need to adjust DownloadPath, DownloadURL and VersionURL, the rest will work automatic. To test the code below without a internet connection, remove the code in IsUpdateAvailable and add only "return true". For test we download REAL Studio. Once the download is finished, the application will be closed and the installer launched.

1. Create a new text file and reanme it to version.txt and add 1.1.0 as the first line
2. Upload the text file version.txt to your server
3. Remove all Windows and add 2 new Windows: MainWindow and UpdateWindow
4. Uncheck the Visible property in the IDE for MainWindow and UpdateWindow
5. Add a TCPSocket to UpdateWindow and rename it to UpdateSocket and change the super to HTTPSocket
6. Add a ProgressBar to UpdateWindow and make the maximum value the same as the width value
7. Add a module and rename it to UpdateModule
8. Add this properties to UpdateModule
DownloadPath As String = REALStudioSetup.exe
DownloadURL As String = http://realsoftware.cachefly.net/REALStudio2010r32/REALStudioSetup.exe
VersionURL As String = http://www.yourdomain.com/version.txt

9. Add this function to UpdateModule
Function IsUpdateAvailable() As Boolean
// arr(0) is the first line, arr(1) the seconde line, etc.
// for every new major release add a new line to the text "version.txt"
// for every new minor or bug version change the line which are equal to the app.majorversion
dim major, minor, bug as integer
dim s, updateversion, arr(-1) as string
dim h as new httpsocket

updateversion = h.get(VersionURL, 5) // get the lines
arr = ReplaceLineEndings(updateversion, endofline).split(endofline) // add each line to the array arr()

if ubound(arr) < 0 then return false
s = arr(0) // assume this app.majorversion is 1, so we need to check the first line

major = val(NthField(s, ".", 1)) // add the first number before the first point
minor = val(NthField(s, ".", 2)) // add the second number after the first point
bug = val(NthField(s, ".", 3)) // add the third number after the second point

if major > app.majorversion or minor > app.minorversion or bug > app.bugversion then // check if any value is greater
return true
else
return false
end if
End Function

10. Add this to App.Open
dim f as folderitem = temporaryfolder.child(DownloadPath)
dim d as new messagedialog
dim b as messagedialogbutton

d.icon = messagedialog.graphicnote
d.alternateactionbutton.visible = true

d.title = "Update"
d.actionbutton.caption = "Yes"
d.alternateactionbutton.caption = "No"
d.message = "A new version is available."
d.Explanation = "Download?"

if IsUpdateAvailable = true then
b = d.showmodal
select case b
case d.actionbutton
updatewindow.updatesocket.get(DownloadURL, f)
else
mainwindow.show
end select
else
mainwindow.show
end if

11. Add this to UpdateWindow.UpdateSocket.DownloadComplete
dim f as folderitem = temporaryfolder.child(DownloadPath)

if f <> nil and f.exists = true then
f.launch
quit
end if

12. Add this to UpdateWindow.UpdateSocket.ReceiveProgress:
progressbar1.value = round( (bytesreceived/totalbytes) * progressbar1.maximum )


Last edited by serd83 on Sat Oct 16, 2010 7:41 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Fri Oct 15, 2010 9:41 pm 
Offline
User avatar

Joined: Fri Jan 29, 2010 12:39 pm
Posts: 880
Location: Virginia, USA
This is cool Serd I'll check it out. Thanks.

_________________
RS 2012 r2 Enterprise on Win 7


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Fri Oct 15, 2010 9:45 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
I upload a sample project:
http://www.file-upload.net/download-2893658/Update.rbp.html


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Sat Oct 16, 2010 7:43 am 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
I edit the code above and upload a new sample project:
http://www.file-upload.net/download-2894224/Update.rbp.html


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Sat Oct 16, 2010 4:57 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
What happens if:

//version running is 2.0.0
App.Majorversion = 2
App.Minorversion = 0
App.Bugversion = 0
//Version on the server is 1.9.9
Major=1
Minor=9
Bug=9

_________________
Boredom Software


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Sat Oct 16, 2010 9:44 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
Maybe you understand this not correct. You start the text file with the first line. This is 1.x.x. For every new major release you add a new line e.g. 2.x.x, 3.x.x etc. If the first major release is 1, you compare the first line: arr(0), for major release 2: arr(1) etc.
Assume this is major release 1:
//version running is 1.0.0
App.Majorversion = 1
App.Minorversion = 0
App.Bugversion = 0

You compare arr(0):
//Version on the server is 1.9.9
Major=1
Minor=9
Bug=9

Assume this is major release 2:
//version running is 2.0.0
App.Majorversion = 2
App.Minorversion = 0
App.Bugversion = 0

You compare arr(1):
//Version on the server is 2.9.9
Major=2
Minor=9
Bug=9


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Mon Oct 18, 2010 12:59 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
I add a new variable MajorRelease to the function IsUpdateAvailable. This way you must not write every time a number to arr() and the code is a bit clearer.
Function IsUpdateAvailable() As Boolean
// for every new major release add a new line to the text "version.txt"
// for every new minor or bug version change the line which are equal to the app.majorversion
dim major, minor, bug as integer
dim s, updateversion, arr(-1) as string
dim h as new httpsocket
dim MajorRelease as integer = app.majorversion-1 // see which line is equal to app.majorversion

updateversion = h.get(VersionURL, 5) // get the lines
arr = ReplaceLineEndings(updateversion, endofline).split(endofline) // add each line to the array arr()

if ubound(arr) < 0 then return false
s = arr(MajorRelease)

major = val(NthField(s, ".", 1)) // add the first number before the first point
minor = val(NthField(s, ".", 2)) // add the second number after the first point
bug = val(NthField(s, ".", 3)) // add the third number after the second point

if major > app.majorversion or minor > app.minorversion or bug > app.bugversion then // check if any value is greater
return true
else
return false
end if
End Function

http://www.file-upload.net/download-2900048/Update.rbp.html


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Mon Nov 15, 2010 9:12 am 
Offline

Joined: Sat Sep 22, 2007 8:11 am
Posts: 11
your example works great ! I only have one stupid question... where do I set the MajorVersion value ?
when I search for it I find : App.MajorVersio(nom de la propriete) Name :1
but when I double click on it, I don't have access to the value ...
thanks
jlc


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Mon Nov 15, 2010 9:21 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 189
Location: Belgium
dim f as folderitem = temporaryfolder.child(DownloadPath)

should be
dim f as folderitem = specialfolder.temporary.child(DownloadPath)

in 2010 r4 :D

For the rest perfect code, thanks for sharing!


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Wed Nov 17, 2010 7:34 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
Thanks for the correction Goofie.

jlcurty,

Once you select App in the project tab, you can change the values for MajorVersion, MinorVersion and BugVersion. The values are Read-Only, therefore you must set it this way:
Image


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Thu Dec 09, 2010 10:30 am 
Offline

Joined: Sat Nov 22, 2008 10:25 pm
Posts: 2
Is the sample project still available.

I can't seem to acces the link

http://www.file-upload.net/download-290 ... e.rbp.html

Nikolas


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Thu Dec 09, 2010 1:36 pm 
Offline

Joined: Sun Feb 19, 2006 4:00 pm
Posts: 1282
Location: Heidelberg, Germany
You can get it from here:

http://dl.dropbox.com/u/992591/REALbasic/Forum/Update.rbp.zip


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Tue Jan 10, 2012 8:44 am 
Offline

Joined: Tue Dec 27, 2011 8:54 am
Posts: 139
Location: India
Hi Serd,

Thanks for sharing this tip.

I have few questions on this.

Que #1
DownloadPath As String = REALStudioSetup.exe
DownloadURL As String = http://realsoftware.cachefly.net/REALSt ... oSetup.exe
VersionURL As String = http://www.yourdomain.com/version.txt

My Ques : I have a desktop app. I want to update my application from my client server where the latest "update.exe" is resides and which is inside a FTP folder. Then how to download the new version of that application to my machine because i don't have any "DownloadURL" as well as "DownloadPath". I have only the RemoteHost, RemoteUser and RemotePassword ?

Que #2
Dim f a folderitem = temporaryfolder.child(DownloadPath)

My Qus : Is there any way to get the Application.StartupPath using RB ? (I am VB.NET developer. In VB this is possible to get that path)

Thanks,
Prakash

_________________
PK Pothal
Software Developer in REAL STUDIO 2011r4.3, ASP.NET, VB.NET, C# AND SQL SERVER 2005/08
OS:WINDOWS N MAC


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Wed Jan 25, 2012 3:52 pm 
Offline

Joined: Thu Feb 22, 2007 7:08 pm
Posts: 1384
Hi prakashp,

DownloadPath is not important. You can name this as you want like "update.exe" or "something.exe". Just be sure that ".exe" is at the end.

DownloadURL is important because this is the file on the server which you want to download. Simple upload your "update.exe" to your server into any folder. For example if you have a folder "downloads" and upload your "update.exe" there, so DownloadURL should be:
DownloadURL As String = http://www.yourdomain.com/downloads/update.exe


For the start up change

temporaryfolder.child(DownloadPath)


to

StartupItemsFolder


Top
 Profile  
 
 Post subject: Re: Update checker
PostPosted: Fri Jan 27, 2012 1:17 am 
Offline

Joined: Tue Dec 27, 2011 8:54 am
Posts: 139
Location: India
Thanks Serd.

I got your point. I have a small doubt about this.

You pointed out that so DownloadURL should be

DownloadURL As String = http://www.yourdomain.com/downloads/update.exe


Can i change to :

DownloadURL As String = http://ftp.XXX.com/update.exe



Thanks,
Prakash

_________________
PK Pothal
Software Developer in REAL STUDIO 2011r4.3, ASP.NET, VB.NET, C# AND SQL SERVER 2005/08
OS:WINDOWS N MAC


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group