AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Very Simple Auto-Update to Push New Script Versions

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Rhys



Joined: 17 Apr 2007
Posts: 730
Location: Florida

PostPosted: Fri Jun 13, 2008 2:25 pm    Post subject: Very Simple Auto-Update to Push New Script Versions Reply with quote

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
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Fri Jun 13, 2008 2:41 pm    Post subject: Reply with quote

cool i love the ping part Laughing
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2605
Location: Australia, Qld

PostPosted: Fri Jun 13, 2008 10:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
majkinetor!
Guest





PostPosted: Fri Jun 13, 2008 11:20 pm    Post subject: Reply with quote

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

PostPosted: Sun Jun 15, 2008 12:18 am    Post subject: Reply with quote

A batch can delete itself by
Code:
del %0
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 730
Location: Florida

PostPosted: Sun Jun 15, 2008 6:42 am    Post subject: Reply with quote

@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
View user's profile Send private message
Guest






PostPosted: Sun Jun 15, 2008 9:02 am    Post subject: Reply with quote

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:
Code:
choice /n /t:y,02
Wink
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group