Sign in to follow this  
Followers 0
sandman

Generic Program Updater

15 posts in this topic

Hi everybody,

I've written a fairly simple but useful program updater that you can make your program run every time it is executed. Feel free to use this as a base for a updater GUI, or anything of the sort.

Before I show the code, the logic of this.

Meet Bob. Bob just downloaded your program, which is currently at version 0.9. Once he runs the installer, there will be at least two files extracted into the program's directory: The main program EXE, and a file called 'settings.ini'. Inside 'settings.ini' is the section Version, and inside that is the key 'version'. The value of this key is... you guessed it. '0.9'.

Bob is enjoying your program a lot. A few weeks later, you release version 1.0 of the program. The very next time Bob runs his program after you release that, your program will download a file from your site called 'update.exe', like every other time your program starts up. Your program waits for update.exe to finish before continuing. So update.exe is running, and it notices that 'settings.ini' has a version of 0.9 still. It fixes this! This is the part that you need to customize, depending on what updates you need. It will close the running program, and replace all necessary files.

Otherwise, it exits and lets the program run on!

Remember, you need to compile these for it to work. Compile update.au3 as update.exe, and myprogram.au3 to myprogram.exe. Of course you can rename these and change the actions if you would like to.

myprogram.au3:

; myprogram.exe

; THIS MUST BE COMPILED TO WORK!! Otherwise it cannot find myprogram.exe

; Load the updater....
If INIRead("settings.ini", "Version", "version", "nocurrentversion") = "nocurrentversion" Then INIWrite("settings.ini", "Version", "version", "1.0") ; An example. If there's no INI file yet, put the version in.
InetGet("http://www.example.com/Your Update File.exe", "update.exe", 1)         ; Get the update file... force a reload from the site, no caching!
RunWait("update.exe")                                                           ; Run the updater

; My Program... blah blah blah.

Enjoy!

:):guitar::P


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites



Sweet! I am headed to work right now but look forward to testing this..

Share this post


Link to post
Share on other sites

Hello...

I am trying to implement this into one of my scripts to check it out and having dificulties.

Am I supposed to be using the two files i.e. myprogram.exe and update.exe along with my .exe file? Or do I work the code into my .exe to form only one file

Also, I cannot get update.au3 to compile, it cannot add the two FileInstalls.

Sorry for the confusion :)

Look forward to hearing from you

Share this post


Link to post
Share on other sites

I think you add myprogram.au3 into your program code and compile your program. Then compile update.exe.

Remember to change the names and such to your programs name.

Share this post


Link to post
Share on other sites

I think you add myprogram.au3 into your program code and compile your program. Then compile update.exe.

Remember to change the names and such to your programs name.

That's correct. You'll need to integrate the code from myprogram.au3 into somewhere in your script where it will constantly load, probably every time it starts. Then you just need to compile update.exe and your program, and make sure to edit update.au3 before compiling with whatever you want to update and the name of your compiled script (for example myprogram.exe). If the FileInstall isn't working, and you are certain the files are there and pointed to correctly, please post your modified update.exe and I will try to see what's wrong with it.

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

Ok, I am getting frustrated. LOL When I set this up and I have tried many variations of pathe and files in the below. I get a violent explosion of the same script repeatedly opening. Can ya tell me what I am doing wrong.. :)

Here is what I put into my existing script dandocr.exe:

;-------------------------------------------------------------------

If INIRead("settings.ini", "Version", "version", "nocurrentversion") = "nocurrentversion" Then INIWrite("settings.ini", "Version", "version", "1.0") ; An example. If there's no INI file yet, put the version in.
InetGet("http://www.gseller.com/danddocr.exe", "update.exe", 1)   ; Get the update file... force a reload from the site, no caching!
RunWait("update.exe")

;-------------------------------------------------------------------

Still not sure what the second FileInstall is for..

Share this post


Link to post
Share on other sites

Why are you downloading http://www.gseller.com/danddocr.exe when you compiled it as update.exe?

Unfortunately that's really the only problem that pops out to me.


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

Wow, the site is back up.. LOL I don't know why I am doing that. I thought I was having the program itself download I guess that is why it isn an endless loop opening the program when it is ran.. LOL

Share this post


Link to post
Share on other sites

So it works now?


[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

Regretfully No... Here is my code:

; update.au3

; This will update to 1.0

If INIRead("settings.ini", "Version", "version", "") <> "1.0" Then
    ; Customize actions here.
    TrayTip("Blah", "Currently updating to 1.2", 10)
    $PID = ProcessExists("update.exe")
    ProcessClose($PID)                              ; Close the running program so it doesn't mess anything up.
    FileInstall("danddocr.exe", "danddocr.exe")
    FileInstall("danddocr.au3", "danddocr.au3")
    Run("update.exe")                                                        ; Start it again.
EndIf
ExitoÝ÷ Øw«z+0«H«Þx"l¦bq«b¢v®¶­sdbä&VBgV÷C·6WGFæw2æægV÷C²ÂgV÷CµfW'6öâgV÷C²ÂgV÷C·fW'6öâgV÷C²ÂgV÷C¶æö7W'&VçGfW'6öâgV÷C²ÒgV÷C¶æö7W'&VçGfW'6öâgV÷C²FVâäw&FRgV÷C·6WGFæw2æægV÷C²ÂgV÷CµfW'6öâgV÷C²ÂgV÷C·fW'6öâgV÷C²ÂgV÷C³ãgV÷C²²âW×ÆRâbFW&Rb33·2æòäfÆRWBÂWBFRfW'6öââà¤æWDvWBgV÷C¶GG¢ò÷wwræw6VÆÆW"æ6öÒògV÷C²ÂgV÷C·WFFRæWRgV÷C²Â²vWBFRWFFRfÆRâââf÷&6R&VÆöBg&öÒFR6FRÂæò66ærb333°¥'VåvBgV÷C·WFFRæWRgV÷C²

I guess it is not meant to be.. :) Doyou see anything else I might try?

Thanks for your support so far...

Share this post


Link to post
Share on other sites

How do you download http://www.gseller.com? :)

Do something like this, and (obviously) upload the file to correspond:

InetGet("http://www.gseller.com/update.exe", "update.exe", 1)

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

If $Cmdline[0] And $Cmdline[1] = "-s" Then
    ProgressOn($head, "Install in progress", "10 percent")
    ProgressSet( 10, "10 percent")
    Call("Install")
    ProgressSet(100 , "Done", "Complete")
    sleep(1000)
    ProgressOff()
    Exit
EndIf

Call("Update")
Call("Install")

Func Update()
    ;Check for update on the network
    If StringInStr(@IPAddress1,"192.168")=1 And Ping("192.168.1.1",1000)>=1 Then
        $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
        $FileTimeNew=FileGetTime ( "\\server\share\myprog.exe", 0, 1)
        $FileTimeOld=FileGetTime ( $path&"\myprog.exe", 0, 1)
        If $FileTimeNew<>0 And $FileTimeNew > $FileTimeOld Then; connected to the network and have a newer version
            MsgBox(0,$head&" Update", "A newer version has been detected and will be installed." & _
            @CRLF & "Please wait until the end of the installation and restart again!")
            Run("\\server\share\myprog.exe -s")
            Exit
        EndIf
    EndIf
EndFunc

Func Install()
    ;Install (copy) the program in
    $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
    $pathstart=@ProgramsCommonDir&"\myprog\"; ..\All Users\start menu\program\myprog\
    FileCopy ( @ScriptFullPath, $path , 9)
    FileCreateShortcut ( $path&"myprog.exe", $path&"myprog")
    DirCreate($pathstart)
    FileCreateShortcut ( $path&"myprog.exe", $pathstart&"myprog")
    DirCreate ( @AppDataDir&"\myprog\" )
EndFunc

I did that for one or two programs that I have on my newtwok.

Every time someone start the program, it check itself on the server if a newer exists...

easy isn't it ???

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

How do you download http://www.gseller.com? :)

Do something like this, and (obviously) upload the file to correspond:

InetGet("http://www.gseller.com/update.exe", "update.exe", 1)oÝ÷ Ûú®¢×qÊ+v)à¶az¥¥ø¥z«z+-ç^~)â¶*'¡ü¨ºX§{­Þ´W­jëh×6InetGet ( "URL" [,"filename" [, reload [, background]]]  )oÝ÷ ÙDK¶§~)^©N¬Ì!ȦºÈ§«­¢+Ù%¹ÑÐ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹͱ±È¹½´¼ÅÕ½Ðì°ÅÕ½ÐíÕÁѹáÅÕ½Ðì°Ä¤ìÐÑ¡ÕÁÑ¥±¸¸¸½Éɱ½É½´Ñ¡Í¥Ñ°¹¼¡¥¹ÌÌ

Is this what I am doing wrong?

Edited by gesller

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Yes, by "filename" they mean the filename to download the file to. You need to include the full URL in the URL parameter, and what you want it to be named locally after it is downloaded.

Oh, another forum bug..

Edited by sandman

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Share this post


Link to post
Share on other sites

If $Cmdline[0] And $Cmdline[1] = "-s" Then
    ProgressOn($head, "Install in progress", "10 percent")
    ProgressSet( 10, "10 percent")
    Call("Install")
    ProgressSet(100 , "Done", "Complete")
    sleep(1000)
    ProgressOff()
    Exit
EndIf

Call("Update")
Call("Install")

Func Update()
    ;Check for update on the network
    If StringInStr(@IPAddress1,"192.168")=1 And Ping("192.168.1.1",1000)>=1 Then
        $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
        $FileTimeNew=FileGetTime ( "\\server\share\myprog.exe", 0, 1)
        $FileTimeOld=FileGetTime ( $path&"\myprog.exe", 0, 1)
        If $FileTimeNew<>0 And $FileTimeNew > $FileTimeOld Then; connected to the network and have a newer version
            MsgBox(0,$head&" Update", "A newer version has been detected and will be installed." & _
            @CRLF & "Please wait until the end of the installation and restart again!")
            Run("\\server\share\myprog.exe -s")
            Exit
        EndIf
    EndIf
EndFunc

Func Install()
    ;Install (copy) the program in
    $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
    $pathstart=@ProgramsCommonDir&"\myprog\"; ..\All Users\start menu\program\myprog\
    FileCopy ( @ScriptFullPath, $path , 9)
    FileCreateShortcut ( $path&"myprog.exe", $path&"myprog")
    DirCreate($pathstart)
    FileCreateShortcut ( $path&"myprog.exe", $pathstart&"myprog")
    DirCreate ( @AppDataDir&"\myprog\" )
EndFunc

I did that for one or two programs that I have on my newtwok.

Every time someone start the program, it check itself on the server if a newer exists...

easy isn't it ???

This works great for me. Thanx for your help Sandman, I just cannot get the updater to update for me.. LOL

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0