/res/ahk/updater.ahk

http://github.com/Skiouros/Macro · AutoHotKey · 40 lines · 36 code · 3 blank · 1 comment · 2 complexity · 8ac5530c6a77470674481ad2874e8327 MD5 · raw file

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