Sign in to follow this  
Followers 0
EliTe_ThuT

Auto Upgrade my program

17 posts in this topic

Hi, I have made a program..but I would like to add a code at the beginning for auto-updating...

The problem is I don't even know from where to start...I have never done things like that.

Someone could point me in the right direction ?

Thx

Share this post


Link to post
Share on other sites



First let the script check if there is a new version, for example download a file named latest_version

If the version in the latest_version file is newer than the one installed then download new file (Also specified in latest_version), when done close the script and replace with new version. The simpliest way to do this would be with a batch file.

Using this you as a developer can update all client just by uploading a text file and the new version :D


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

First let the script check if there is a new version, for example download a file named latest_version

If the version in the latest_version file is newer than the one installed then download new file (Also specified in latest_version), when done close the script and replace with new version. The simpliest way to do this would be with a batch file.

Using this you as a developer can update all client just by uploading a text file and the new version :D

And how do I do that ? The batch file

Share this post


Link to post
Share on other sites

Here's an example of a batch file that will replace an old file with new:

@echo off
ping localhost
move "newlydownloadedexe.exe" "oldexe.exe" /Y

Note that I use ping at the beginning, this is so that your script will have time to close before overwriting begins.

1 person likes this

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

So I would have to have my autoit script check server to see if there is a new version...and then...download the file, then run a .bat file and exit , then the .bat file would run and replace the exe with the new one... and then..what If I want to .bat file open the newlydownloadedexe.exe after ?

Edit: I found "START C:\WINDOW\BLABLA" but does this work if I enter a relative path to ?

Edited by EliTe_ThuT

Share this post


Link to post
Share on other sites

Edit: I found "START C:\WINDOW\BLABLA" but does this work if I enter a relative path to ?

Yes, if you have the bat file in the same dir as your script.

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Not sure where I found this (help file, forum, wiki, one of them)...

The comment is mine, believe it. Your script will still be running after it deletes itself, that's your chance to put the new file in it's place.

Func _SelfDelete($iDelay = 0); - this is serious!  MAKE A BACKUP, OR YOU'LL REGRET IT.
  Local $sCmdFile
  FileDelete(@TempDir & "\scratch.bat")
  $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
    & ':loop' & @CRLF _
    & 'del "' & @ScriptFullPath & '"' & @CRLF _
    & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
    & 'del ' & @TempDir & '\scratch.bat'
  FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
  Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

Edit: found the original post: here.

Q12 - about half way down the page.

Edited by aGorilla
1 person likes this

Share this post


Link to post
Share on other sites

Not sure where I found this (help file, forum, wiki, one of them)...

The comment is mine, believe it. Your script will still be running after it deletes itself, that's your chance to put the new file in it's place.

Func _SelfDelete($iDelay = 0); - this is serious!  MAKE A BACKUP, OR YOU'LL REGRET IT.
  Local $sCmdFile
  FileDelete(@TempDir & "\scratch.bat")
  $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
    & ':loop' & @CRLF _
    & 'del "' & @ScriptFullPath & '"' & @CRLF _
    & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
    & 'del ' & @TempDir & '\scratch.bat'
  FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
  Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

Edit: found the original post: here.

Q12 - about half way down the page.

Wow so in fact, if I use this...I do not need a .bat file...

Share this post


Link to post
Share on other sites

Well, you won't 'need' one, but you'll use one. That creates the batch that deletes your script, then deletes itself. It's quite cool (and just a bit dangerous).

Share this post


Link to post
Share on other sites

Well, you won't 'need' one, but you'll use one. That creates the batch that deletes your script, then deletes itself. It's quite cool (and just a bit dangerous).

Oh yeah I see it (didn't saw the filewrite parth)

Anyway that's cool :D

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok, I took a shot at this (I needed one anyway), and here's a rough example.

Version 1 - this is what you run.

http://www.theholyfind.com/au3/upgrade/upgrade.au3

Version 2 - if it works, this is what you'll end up with.

http://www.theholyfind.com/au3/upgrade/upgrade-2.00.au3

This is how version 1 finds out there's a new (ie: different) version.

http://www.theholyfind.com/au3/upgrade/latest.html

All comments, criticisms, suggestions, etc. are welcome.

p.s.: I'd love to see a progress bar for it, if anyone has the time.

p.p.s.: It seems to work without the self-deletion code, somehow, I thought I would need that.

Edited by aGorilla

Share this post


Link to post
Share on other sites

I have made a updater, go a forum search for:

Global Updater

:D

Share this post


Link to post
Share on other sites

I was busy :D Source is provided :D But Congrats!

Share this post


Link to post
Share on other sites

No worries, and thanks. I had fun with it, and it'll probably suit me for what I'm working on now.

Scanning through your code now, maybe I'll learn something :D

Good thx everyone...I'll probably just look at both of your code and make my own updater with it.

Share this post


Link to post
Share on other sites

One final thought...

Any 'Auto Upgrade' program should include some form of 'Post Upgrade' function.

The first program to use it will probably just contain 'Return true', but it gives you a placeholder to call in the future.

You can use it to add any cleanup code (eg: deleting old files that are no longer used, etc. -- which Swift has in _Cleanup()), or for it to continue with the upgrade (downloading other files, etc.).

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