PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/res/ahk/updater.ahk

http://github.com/Skiouros/Macro
AutoHotKey | 40 lines | 36 code | 3 blank | 1 comment | 2 complexity | 8ac5530c6a77470674481ad2874e8327 MD5 | raw file
 1url      := "http://www.autohotkey.net/~zzzooo11/Macro/macro.exe"
 2baseDir  := SubStr(A_ScriptDir, 1, -7)
 3fileName := "macro.exe"
 4
 5Download(url, baseDir . fileName)
 6Run % baseDir . fileName " /install"
 7Exitapp
 8
 9
10; Based on code by Sean and SKAN @ http://www.autohotkey.com/forum/viewtopic.php?p=184468#184468
11Download(url, file)
12{
13    static vt
14    if !VarSetCapacity(vt)
15    {
16        VarSetCapacity(vt, A_PtrSize*11), nPar := "31132253353"
17        Loop Parse, nPar
18            NumPut(RegisterCallback("DL_Progress", "F", A_LoopField, A_Index-1), vt, A_PtrSize*(A_Index-1))
19    }
20    global _cu
21    SplitPath file, dFile
22    SysGet m, MonitorWorkArea, 1
23    y := mBottom-52-2, x := mRight-330-2, VarSetCapacity(_cu, 100)
24    , DllCall("shlwapi\PathCompactPathEx", "str", _cu, "str", url, "uint", 50, "uint", 0)
25    Progress Hide CWFAFAF7 CT000020 CB445566 x%x% y%y% w330 h52 B1 FS8 WM700 WS700 FM8 ZH12 ZY3 C11,, %_cu%, AutoHotkeyProgress, Tahoma
26    WinSet Transparent, 192, AutoHotkeyProgress
27    re := DllCall("urlmon\URLDownloadToFile", "ptr", 0, "str", url, "str", file, "uint", 0, "ptr*", &vt)
28    Progress Off
29    return re=0 ? 1 : 0
30}
31DL_Progress( pthis, nP=0, nPMax=0, nSC=0, pST=0 )
32{
33    global _cu
34    if A_EventInfo = 6
35    {
36        Progress Show
37        Progress % P := 100*nP//nPMax, % "Downloading:     " Round(np/1024,1) " KB / " Round(npmax/1024) " KB    [ " P "`% ]", %_cu%
38    }
39    return 0
40}