AUTO UPDATER?

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

AUTO UPDATER?

Post by Roberto Lopez »

Hi All,

As I've commented many times, my recent work is about HMG applications that get data through the Internet (NETIO).

The main issue with this scheme is the app update.

Currently I must send the '.exe' by email to each remote user with directions to replace the old one. The problem is that some users are not capable to handle that.

So, the solution is an auto-updater.

The obvious path is to have two '.exe'. The first one checks an FTP server for an update, and if there is one, it is downloaded and executed.

No problem, it is easy to do... but I don't like it :)

My wish is to have only one .exe doing all the job, but I'm afraid that, there is a lot of problems to solve to achieve that.

had someone tried this with success?

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: AUTO UPDATER?

Post by mol »

My main .exe file test if update is ready to download. If new version is present, it's downloaded, then executed.

Code: Select all


function CheckPresenceOfNewVersion
	param lSilent
	local cVersion:= "", lInstall := .f., cVersionTXT := ""
	if lSilent = NIL
		lSilent := .f.
	endif

	if !DownloadFromWWW("http://www.molsystemy.pl/faktury/f4wersja.txt",Kat_Roboczy+"f4wersja.txt", .t.)
		if !lSilent
			MsgBox("Error in connection")
		endif
		return
	endif
	cVersionTXT := Memoread(Kat_Roboczy+"f4wersja.txt")
	cVersion := alltrim(Memoline(cVersionTXT))

	if cVersion > cCurrentInstalledVersion

		load window Form_NewVersion
		center window Form_NewVersion
		Form_NewVersion.E_INFO.Value := cVersionTXT
		ON KEY ESCAPE OF Form_NewVersion ACTION Form_NewVersion.Release
		
 		define ACTIVEX Counter
			Parent Form_NewVersion
			ROW 1
			COL 1
			WIDTH 1  
			HEIGHT 1 
			PROGID "shell.explorer.2"  
		end ACTIVEX
		
		activate window Form_NewVersion
	else
		lInstall := .f.
		if !lSilent
			MsgBox("New version is absent...")
		endif
	endif
return
*---------------------------
function InstallNewVersion
	local lServerAnswer
	
	WAIT WINDOW  "Downloading new version..."  NOWAIT
	lServerAnswer := DownloadFromWWW("http://www.mol-systemy.com.pl/faktury/f4setup.exe",Kat_Roboczy+"f4setup.exe", .t.)
	WAIT CLEAR
	declare window MainForm
	if !lServerAnswer
		MsgBox("Error in connection")
	else
               // this line is for my statistic only
		cAddress := 'http://molsystemy.pl/faktury/licznikaktualizacjifaktury.php?nip=' + alltrim(DaneFirmy[8])+'&nazwa='+hb_strtoUTF8(alltrim(DaneFirmy[6]))
		GetProperty('Form_NewVersion','Counter','Object'):Navigate(cAddress)
		MsgBox("Close app on other workstations and press OK to install new version")
		cprog	:= Kat_Roboczy+'f4setup.exe'
		cParam	:= '/dir="' + left(sc_dost, len(sc_dost)-1)+'"'
		_Execute ( GetActiveWindow() ,, cProg , cparam ,, 5 )

		MainForm.release
	endif
return

Last edited by mol on Mon Aug 19, 2013 9:01 am, edited 1 time in total.
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: AUTO UPDATER?

Post by mol »

Code: Select all

PROCEDURE DownloadFromWWW
	param cURL, cLocalFileName, lSilent
	LOCAL oCon, oUrl, i, cResponse
	local ret := .f.
	local oOldErrorHandle
	
	oOldErrorHandle:= ErrorBlock({|e| break(e)})
	
	BEGIN SEQUENCE
	cLocalFileName := alltrim(cLocalFileName)
	if lSilent = NIL
		lSilent := .f.
	endif
	oUrl := tURL():New( cUrl )
	IF Empty( oUrl )
		if !lSilent
			MsgBox("Wrong url: " + cUrl)
		endif
		BREAK
	ENDIF

	IF oUrl:cProto != "http"
		if !lSilent
			MsgBox('Wrong http address')
		endif
		BREAK
	END
   
	oCon := TipClientHttp():New( oUrl )
	oCon:nConnTimeout := 20000
	if !lSilent
		MsgBox("Connecting with "+ oUrl:cServer)
	endif
	IF oCon:Open( cUrl )
		if !lSilent
			MsgBox("Connected." +chr(10)+"Press OK to download " + oUrl:cPath +oUrl:cFile)
		endif
		oCon:WriteAll(cLocalFileName)
		if !lSilent
			MsgBox("Downloaded and saved as: "+cLocalFileName)
		endif
		oCon:Close()
		ret := .t.
	ELSE
		IF oCon:SocketCon == NIL
			cResponse := "uninitialized connection"
		ELSEIF hb_InetErrorCode( oCon:SocketCon ) == 0
			cResponse := oCon:cReply
		ELSE
			if !lSilent
				cResponse := "Error in connection: " + hb_InetErrorDesc( oCon:SocketCon )
			endif
		ENDIF
		if !lSilent
			MsgBox("Can't connect with: "+ oUrl:cServer+chr(10)+"Host answer: "+cResponse)
		endif
		ret := .f.
	END
	RECOVER
		if !lSilent
			MSGSTOP("Connection with server couldn't be completed")
		endif
	END SEQUENCE
	ErrorBlock(oOldErrorHandle)
RETURN ret
Last edited by mol on Mon Aug 19, 2013 8:58 am, edited 1 time in total.
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: AUTO UPDATER?

Post by Rathinagiri »

Really useful Marek. Thanks a lot. I will try in my system.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

AUTO UPDATER?

Post by Pablo César »

Seems to usefull !!!

Thanks Marek for sharing with us ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: AUTO UPDATER?

Post by Roberto Lopez »

mol wrote:My main .exe file test if update is ready to download. If new version is present, it's downloaded, then executed.
Looks great. I'll try it, Thanks.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
serge_girard
Posts: 3420
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: AUTO UPDATER?

Post by serge_girard »

Roberto,

I have the same "problem" which I resolved as follows:

On startup (a batchjob) I first do TSKILL of the main.exe, then start my INIT.EXE which will check on mysql database if there is a new version.
If there is download it, rename main.exe to main-date-time.exe and the rename the downloadfile to main.exe

After the INIT.exe I do START MAIN.EXE (with a new version or unchanged version). This is working since 5 years without problems.

If interested I can send you the programs + SQL structures.

Greetings,

Serge
There's nothing you can do that can't be done...
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: AUTO UPDATER?

Post by Roberto Lopez »

serge_girard wrote:Roberto,

I have the same "problem" which I resolved as follows:

On startup (a batchjob) I first do TSKILL of the main.exe, then start my INIT.EXE which will check on mysql database if there is a new version.
If there is download it, rename main.exe to main-date-time.exe and the rename the downloadfile to main.exe

After the INIT.exe I do START MAIN.EXE (with a new version or unchanged version). This is working since 5 years without problems.

If interested I can send you the programs + SQL structures.

Greetings,

Serge
I'm working with NETIO, so, my plan is to transfer the updated EXE via NETIO, to avoid the set up of an additional server (FTP or HTTP) and keep the things simple.

And, of course, the idea of a batch file controlling things, is nice, clean and simple.

My problem is that sometimes, I miss the simple solutions.

Thanks for your answer.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Nascimento
Posts: 13
Joined: Sun Jan 11, 2015 1:33 pm

Re: AUTO UPDATER?

Post by Nascimento »

hi mol I could post the Form_NewVersion sorry I could not compile

att: Nascimento
User avatar
dragancesu
Posts: 931
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: AUTO UPDATER?

Post by dragancesu »

I recently watched this can be done

I think the solution is simply a program that serves to install HMG is installforge.net when you go to make the installation there is an option update and should specify the internet site where the new version
Post Reply