Jump to content

Generic Program Updater


sandman
 Share

Recommended Posts

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]

Link to comment
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

Link to comment
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]

Link to comment
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..

Link to comment
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]

Link to comment
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...

Link to comment
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]

Link to comment
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 ???

Link to comment
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)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
Link to comment
Share on other sites

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]

Link to comment
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
Link to comment
Share on other sites

  • 14 years later...

An updated of the update program itself over the internet:
In a '.dat' file (ini file) on your server, you need to have the FileGetTime() of your complied new prg with IniWrite()

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_After=start WriteTimeDatFile.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


$rootdir = @AppDataDir & '\MyApp'
$sFileIni = $rootdir & "\MyApp.ini"
$sFileLog = $rootdir & "\MyApp.log"
$sFileDat = $rootdir & "\MyApp.dat"
$sFileNew = $rootdir & "\new\MyApp.exe"
$sRootDwl = 'https://mywebsite.com/myfolder/'

If $Cmdline[0] And $Cmdline[1] = "-s" Then
    _Install()
    Run($rootdir & '\' & @ScriptName)
    Exit
EndIf

_Update()

If Not (FileExists($rootdir)) Then ; if the program is not there (first run)
    _Install()
    Run($rootdir & '\' & @ScriptName & ' -s')
EndIf

Func _Update()
    ;Check for update on the internet
    If Ping("www.google.com") Then
        InetGet(sRootDwl & 'myfile.dat', $sFileDat, 1)
        $FileTimeNew = IniRead($sFileDat, 'MyApp', 'Version', 'Error')
        $FileTimeOld = FileGetTime($rootdir & "\MyApp.exe", 0, 1)
        If $FileTimeNew <> 'Error' And $FileTimeNew > $FileTimeOld Then ; Newer version: connected to the network and have a newer version
            DirCreate($rootdir & "\new")
            InetGet(sRootDwl & 'MyApp.exe', $sFileNew, 1)
            Run($sFileNew & " -s")
            Exit
        EndIf
    EndIf
EndFunc   ;==>Update

Func _Install()
    ;Install (copy) the program in
    DirCreate($rootdir)
    FileCopy(@ScriptFullPath, $rootdir, 9)
EndFunc   ;==>Install

The WriteTimeDatFile.exe will have:

$sServerFile = '\\Server\intranetserver\folder\myfile.dat' ; UNC path

$sTime = FileGetTime(@ScriptDir & "\MyApp.exe", 0, 1)

$FileTimeNew = IniWrite($sServerFile, 'MyApp', 'Version', $sTime)

As simple as that !!!

Enjoy !

C.

EDIT. Typo

Edited by cramaboule
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...