Code: Select all
SetWorkingDir, %A_ScriptDir%
Url := "http://fincs.ahk4.net/scite4ahk/dl/s4ahk-install.exe"
SplitPath, Url, File
MsgBox, 308, Update, Are you sure you want to QUIT SciTE and update?
IfMsgBox, No
ExitApp
if !(hWnd := ComObjActive("SciTE4AHK.Application").SciTEHandle)
ExitApp
WinClose, ahk_id %hWnd%
FileDelete, %File%
Gui, -SysMenu
Gui, Add, Progress, w200 vProgress
Gui, Add, Text, w200 vText Center, 0`%
Gui, Show,, Downloading Installer
Http :=ComObjCreate("WinHttp.WinHttpRequest.5.1")
Http.Open("HEAD", Url), Http.Send()
FileSize := Http.GetResponseHeader("Content-Length")
SetTimer, CheckDownload, 100
UrlDownloadToFile, %Url%, %File%
SetTimer, CheckDownload, Off
GuiControl,, Text, Running installer
if WinExist("ahk_id" hWnd)
{
WinGet, PID, PID, ahk_id %hWnd%
Process, Close, %PID%
Process, WaitClose, %PID%, 2
if WinExist("ahk_id" hWnd)
{
MsgBox, Can't get SciTE to close
ExitApp
}
}
Run, %File%,,, PID
WinWait, ahk_pid %PID%,, 10
ExitApp
return
CheckDownload:
if (LastFile != File)
FObj := FileOpen(LastFile := File, "r")
Percent := Floor(FObj.Length / FileSize * 100)
GuiControl,, Progress, %Percent%
GuiControl,, Text, %Percent%`%
return