Simple updater

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
Contact:

Simple updater

18 Oct 2018, 11:01

I made a simple updater to integrate into your scripts. It checks against a version number locally and one online wherever the update file is stored (my example is github).

Code: Select all

/*
AutoHotkey Version 1.1.30.00
Windows 10
AutoHotkey updater. Used for various programs. 
You can change the URL/ file name to whatever you want. It will download to whatever the current folder is. 
You also need to change line 22 to where the update version file is located.
*/

#Warn
#NoEnv
SendMode, Input 
SetWorkingDir %A_ScriptDir% ;set to script directory to see files

; below is the URL name you would like to download. Filename is the name of the filename
url = https://github.com/MattAHK/programname/archive/master.zip
Filename = Update.zip

FileReadLine, VNum, %A_WorkingDir%\version.txt, 1 ;looks for local version text and stores as vnum
	if ErrorLevel = 1
	Vnum = 0
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://raw.githubusercontent.com/MattAHK/programname/Matt's-working-branch/programnamefolder/version.txt", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse() ;this is taken from the installer. Can also be located as an example on the urldownloadtofile page of the quick reference guide.
version := whr.ResponseText
MsgBox, 1, Press OK to download, Your current version is %Vnum%. This latest is %version%.
	IfMsgBox OK
		UrlDownloadToFile, *0 %url%, %A_WorkingDir%\%Filename%
		if ErrorLevel = 1
			MsgBox, There was some error updating the file. You may have the latest version, or it is blocked.
		else if ErrorLevel = 0
			MsgBox, The update/ download appears to have been successful or you clicked cancel. Please check the update folder. 
		else 
			MsgBox, some other crazy error occured. 
Return
My programs usually have an info button, and I'll ask something like, do you want to check for updates and allow the user to compare both version numbers.

Things I would change or update:
-Make it compare strings
-Extract and replace the current folder
-Close and reopen the new GUI/ program.

For sharing though, I think this base is good because not everyone wants that. This idea comes from the IRC.
User avatar
Chunjee
Posts: 1419
Joined: 18 Apr 2014, 19:05
Contact:

Re: Simple updater

18 Oct 2018, 11:34

I have a similar routine I use in one of my apps: https://github.com/Chunjee/LoneIRC/blob ... pp.ahk#L73

The concept is basically the same. Check a separate file online that stores the latest version number and download the new version if the numbers don't match.


Might try to streamline this a bit as mine relies on some #include functions.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: Simple updater

18 Oct 2018, 19:19

You might also want to look at AutoHotkey's installer.ahk, in the default program directory of AutoHotkey.exe. As that might be of some help too.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Simple updater

18 Oct 2018, 19:32

Nice thanks for sharing was thinking about that just today! :D

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 156 guests