| View previous topic :: View next topic |
| Author |
Message |
Rhys
Joined: 17 Apr 2007 Posts: 730 Location: Florida
|
Posted: Fri Jun 13, 2008 2:25 pm Post subject: Very Simple Auto-Update to Push New Script Versions |
|
|
This may have been done before and someone else suggested the idea of a self-deleting batch file for the task. Someone else in IRC suggested pinging 127.0.0.1 as a poor-man's sleep in the batch. So, I take no credit and wish to thank the generous individuals whose contributions led to this script: | Code: | ;AutoUpdate Example - Name this file as Update.ahk
;I plan on having a version # set in a variable in the script that will be checked against a remote
;File with another version number - If the remote version # is greater, this will run.
FileDelete,Update2.ahk ;Housecleaning for this example only
FileAppend,MsgBox Version 2,Update2.ahk ;Create the 'new version'
;In a real script this would be copied from a remote location with FileCopy or UrlDownloadToFile
MsgBox Version 1 ;Identify this script as version 1
BatchFile=
(
Ping 127.0.0.1
Del Update1.ahk
Rename Update2.ahk Update1.ahk
%A_ScriptFullPath%
Del Update.bat
)
/*
Design a batch file to:
ping to give time for script to exit for...
delete version 1
rename version 2 to version 1
run the new version
delete the batch file
*/
FileDelete,update.bat ;Housecleaning
FileAppend,%BatchFile%,update.bat ;Create the bat
MsgBox, Preparing to update - Please stand by! ;Alert the user that the app will be down for a few seconds
Run,update.bat,,hide ;Run it (hidden)
ExitApp ;Get out of Dodge so this script can be deleted |
_________________ [Join IRC!]
 |
|
| Back to top |
|
 |
heresy
Joined: 11 Mar 2008 Posts: 291
|
Posted: Fri Jun 13, 2008 2:41 pm Post subject: |
|
|
cool i love the ping part  _________________ Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2605 Location: Australia, Qld
|
Posted: Fri Jun 13, 2008 10:44 pm Post subject: |
|
|
| Assuming it isn't compiled, you can delete the script while it is running. AutoHotkey closes the file once it has loaded the script. |
|
| Back to top |
|
 |
majkinetor! Guest
|
Posted: Fri Jun 13, 2008 11:20 pm Post subject: |
|
|
| Quote: | | Someone else in IRC suggested pinging 127.0.0.1 as a poor-man's sleep in the batch. |
Actually, it is the only way to sleep in the batch without having external.
You can sleep m seconds by specifying ping -n m-1 127.0.0.1 |
|
| Back to top |
|
 |
haichen
Joined: 05 Feb 2007 Posts: 125 Location: Osnabrück, Germany
|
Posted: Sun Jun 15, 2008 12:18 am Post subject: |
|
|
| A batch can delete itself by |
|
| Back to top |
|
 |
Rhys
Joined: 17 Apr 2007 Posts: 730 Location: Florida
|
Posted: Sun Jun 15, 2008 6:42 am Post subject: |
|
|
@Lexikos: Thanks for that info - It makes sense that Autohotkey.exe would only need to read the .ahk file once. The app I did this for requires compiled, though.
@Haichen: Cool, that is very slick!
A couple of warnings to anyone who might decide to implement this on any app, take great care when updating that the 'new' remote version that replaces the 'old' local version always has a matching (or greater) 'version' variable than the remote version.txt (or whatever).
Otherwise, update loop of death will occur and we don't want that. I suppose there are ways to get around that like a check for update frequency and confirmation dialog if too often.
Lastly, if pulling the version.txt from a website, please do a sanity check on the remote_version_number variable (if is not number, :=0) - When I tested on a bad remote version.txt, the 404 HTML code the server returned evaluated to > than the current version number. That would also be nasty if unchecked. _________________ [Join IRC!]
 |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Jun 15, 2008 9:02 am Post subject: |
|
|
| majkinetor! wrote: | | Quote: | | Someone else in IRC suggested pinging 127.0.0.1 as a poor-man's sleep in the batch. |
Actually, it is the only way to sleep in the batch without having external.
You can sleep m seconds by specifying ping -n m-1 127.0.0.1 |
Am I missing something here or could not a "poor-man's" sleep in a batch file be implemented using the "choice" command? For example to sleep for 2 seconds:  |
|
| Back to top |
|
 |
|