; ; Configuration ↓ ; #NoTrayIcon ; Don't show an icon x64 := true ; Use 64 bit ; ; Configuration ↑ ; ; No sleep SetBatchLines -1 ; Check if running if (WinExist("ahk_exe " A_ScriptDir "\Code.exe")) { MsgBox 0x40024, Continue?, VSCode is running'', continue wit the update? IfMsgBox No ExitApp 1 } ; Get latest version information x64 := (x64 && A_Is64bitOS) url := "https://update.code.visualstudio.com/latest/win32" (x64 ? "-x64-" : "-") "archive/stable" whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") whr.Open("HEAD", url, false), whr.Send() headers := whr.GetAllResponseHeaders() Sort headers ; Extract relevant information regex := "is)(?[^""]+\.zip).*Length: (?\d+)" RegexMatch(headers, regex, file) if (!fileName || !fileSize) { MsgBox 0x40010, Error, Couldn't get the information from the link. ExitApp 1 } ; Check if already updated FileCreateDir % A_ScriptDir "\data" fileName := A_ScriptDir "\data\" fileName FileGetSize currSize, % filename if (FileExist(fileName) && !currSize) { MsgBox 0x40040, Updated, Already up-to-date. ExitApp } ; Remove last downloaded version FileDelete % A_ScriptDir "\data\VSCode-*.zip" ; Filesize mb := Round(fileSize / 1024 / 1024, 2) ; Progress Window Gui Download:New, +AlwaysOnTop +HWNDhGui -SysMenu +ToolWindow Gui Font, q5 s11, Consolas Gui Add, Text,, % "Downloading... " ; +4 Gui Show,, % "> Downloading " mb " MiB" Hotkey IfWinActive, % "ahk_id" hGui Hotkey !F4, WinExist ; Download SetTimer Percentage, 50 UrlDownloadToFile % url, % fileName if (ErrorLevel) { MsgBox 0x40010, Error, Error while downloading. FileDelete % A_ScriptDir "\data\VSCode-*.zip" ExitApp 1 } SetTimer Percentage, Delete Gui Download:Destroy ; Close if running WinKill % "ahk_exe " A_ScriptDir "\Code.exe" ; Extract shell := ComObjCreate("Shell.Application") items := shell.Namespace(fileName).Items shell.Namespace(A_ScriptDir).CopyHere(items, 16 | 256) ; Truncate the file FileOpen(fileName, 0x1).Length := 0 ; Empty temp files if (FileExist(A_ScriptDir "\data\tmp")) { FileRemoveDir % A_ScriptDir "\data\tmp", 1 FileCreateDir % A_ScriptDir "\data\tmp" } ; Run Run Code.exe, % A_ScriptDir ExitApp ; Finished ; Progress Percentage: FileGetSize size, % fileName GuiControl Download:, Static1, % "Downloaded: " Round(size / fileSize * 100, 2) "%" return