One last chance. I made an example for you with user interface.
Save the script below as MyApp.au3
Global Const $sDomain = 'https://your-domain.tld'
Global Const $sAppVersion = '1.0.0' ; Current app version
Global $hMain, $cCurrentVersion, $cNewestVersion, $cProgress, $iUpdateSize
; This will check if the application
; has been updated and delete the updater
DeleteUpdater()
; MyApp UI
$hMain = GUICreate('My app', 360, 130)
$cCVLabel = GUICtrlCreateLabel('Current version', 10, 10, 100, 30, 0x200)
$cCurrentVersion = GUICtrlCreateLabel($sAppVersion, 110, 10, 50, 30, 0x1201)
$cNVLabel = GUICtrlCreateLabel('Newest version', 10, 50, 100, 30, 0x200)
$cNewestVersion = GUICtrlCreateLabel('', 110, 50, 50, 30, 0x1201)
$cCheckForUpdate = GUICtrlCreateButton('Check for update', 200, 10, 150, 30)
$cUpdate = GUICtrlCreateButton('Update', 200, 50, 150, 30)
$cProgress = GUICtrlCreateProgress(10, 90, 340, 30)
GUICtrlSetFont($cCVLabel, 10, 500, 0, 'Tahoma')
GUICtrlSetFont($cCurrentVersion, 10, 500, 0, 'Tahoma')
GUICtrlSetFont($cNVLabel, 10, 500, 0, 'Tahoma')
GUICtrlSetFont($cNewestVersion, 10, 500, 0, 'Tahoma')
GUICtrlSetFont($cCheckForUpdate, 10, 500, 0, 'Tahoma')
GUICtrlSetFont($cUpdate, 10, 500, 0, 'Tahoma')
GUISetState(@SW_SHOW, $hMain)
While True
Switch GUIGetMsg()
Case $cCheckForUpdate
CheckForUpdate()
Case $cUpdate
UpdateApp()
Case -3
Exit
EndSwitch
WEnd
; This function check if there are new versions available
Func CheckForUpdate()
Local $sVersion = InetRead($sDomain & '/versions.txt')
If $sVersion Then
$sVersion = BinaryToString($sVersion)
Local $aSplit = StringSplit($sVersion, '|')
If IsArray($aSplit) Then
GUICtrlSetData($cNewestVersion, $aSplit[1])
$iUpdateSize = $aSplit[2]
EndIf
EndIf
EndFunc
; This function check if the current version is the newest version,
; otherwise will download the last version and apply the update
Func UpdateApp()
Local $sCurrentVersion = GUICtrlRead($cCurrentVersion)
Local $sNewestVersion = GUICtrlRead($cNewestVersion)
If $sCurrentVersion And $sNewestVersion Then
Local $fCompare = CompareVersions($sCurrentVersion, $sNewestVersion)
Switch $fCompare
Case -1, 0
MsgBox(0x40, 'Info', 'Current version is the last available.', 10)
Case 1
Local $sFileName = StringReplace($sNewestVersion, '.', '_') & '.dat'
Local $hRequest = InetGet($sDomain & '/versions/' & $sFileName, @ScriptDir & '\update.dat', 1, 1)
Do
$iRead = InetGetInfo($hRequest, 0)
GUICtrlSetData($cProgress, Int($iRead * 100 / $iUpdateSize))
Until InetGetInfo($hRequest, 2)
GUICtrlSetData($hRequest, 100)
If InetGetInfo($hRequest, 3) Then
FileMove(@ScriptDir & '\update.dat', @ScriptDir & '\update.exe')
ShellExecute(@ScriptDir & '\update.exe', ' --update')
Else
MsgBox(0x10, 'Error', 'Download error.', 10)
EndIf
EndSwitch
Else
MsgBox(0x10, 'Error', 'Please check first if a newer version is available.', 10)
EndIf
EndFunc
; This function compare current application version with the newest available
; as it is in versions.txt
Func CompareVersions($sCurrentVersion, $sNewestVersion)
Local $aCurrentVersion = StringSplit($sCurrentVersion, '.')
Local $aNewestVersion = StringSplit($sNewestVersion, '.')
If Not IsArray($aCurrentVersion) Or Not IsArray($aNewestVersion) Then Return 0
If $aCurrentVersion[0] <> $aNewestVersion[0] Then Return 0
For $Index = 1 To $aCurrentVersion[0]
If Number($aCurrentVersion[$Index]) > Number($aNewestVersion[$Index]) Then Return -1
If Number($aCurrentVersion[$Index]) < Number($aNewestVersion[$Index]) Then Return 1
Next
Return 0
EndFunc
; This function delete the updater
Func DeleteUpdater()
If IsArray($CmdLine) Then
If $CmdLine[0] = 1 Then
If StringLeft($CmdLine[1], 6) = '--del:' Then
Local $sProc = StringTrimLeft($CmdLine[1], 6)
Local $Timeout = 15000
Local $Timer = TimerInit()
While (ProcessExists($sProc))
ProcessClose($sProc)
Sleep(100)
If TimerDiff($Timer) > $Timeout Then ExitLoop
WEnd
FileDelete(@ScriptDir & '\' & $sProc)
EndIf
EndIf
EndIf
EndFunc
Assume that this script is your actual application. Create two directories: FirstBuild and LastBuild. Then build the script as executable and this will be your first application version (MyApp.exe). Move this executable in FirstBuild directory. To create a new version just change in the script above this line
Global Const $sAppVersion = '1.0.0' ; Current app version
with a new app version, for example
Global Const $sAppVersion = '1.1.0' ; Current app version
and build the script again (MyApp.exe). Move this executable in LastBuild directory.
Then prepare a versions.txt file that will contain the info about newest version of the application. This file should look like this:
1.1.0|918528
where first part (1.1.0) it's the latest app version and second part (918528) it's the size of MyApp.exe from LastBuild directory in bytes.
Before uploading this files to your host you have to build an updater. The updater code it's simple and will never change, just provide to FileInstall the full path to latest version of MyApp.exe from LastBuild directory (don't use variables for this, it has to be literal path).
If IsArray($CmdLine) Then
Switch $CmdLine[0]
Case 1
Switch $CmdLine[1]
Case '--update'
Deploy()
EndSwitch
EndSwitch
EndIf
Func Deploy()
Local $Timeout = 15000
Local $Timer = TimerInit()
While (ProcessExists('MyApp.exe'))
ProcessClose('MyApp.exe')
Sleep(100)
If TimerDiff($Timer) > $Timeout Then ExitLoop
WEnd
If Not ProcessExists('MyApp.exe') Then
FileInstall('<Full Path to latest version of MyApp.exe>', @ScriptDir & '\MyApp.exe', 1)
Run('MyApp.exe --del:update.exe', @ScriptDir, @SW_HIDE)
Else
MsgBox(0x10, 'Error', 'Update error!', 10)
EndIf
EndFunc
Build the updater script and rename the executable as 1_1_0.dat since hosts don't accept executable files to be uploaded on the servers. Upload version.txt in your root directory and for 1_1_0.dat create a directory named "versions" in root directory and upload the file. That's all.
Now go and run MyApp.exe from FirstBuild directory, press the button Check for updates and the app will display your latest available version, then you can press Update button and the application will be updated. The current application will be closed by the updater and restarted as latest version. When the latest application will start it will delete the updater.