Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, Force
  2. #NoEnv
  3. SetBatchLines, -1
  4.  
  5. #Include, Gdip.ahk
  6.  
  7. If !pToken := Gdip_Startup() {
  8.     MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
  9.     ExitApp
  10. }
  11.  
  12. DownloadFile("http://download-installer.cdn.mozilla.net/pub/firefox/releases/26.0/win32/en-US/Firefox%20Setup%2026.0.exe", "firefox_setup.exe")
  13.  
  14. Gdip_Shutdown(pToken)
  15. ExitApp
  16.  
  17. DownloadFile(UrlToFile, SaveFileAs, Overwrite := True, UseProgressBar := True) {
  18.     ;Check if the file already exists and if we must not overwrite it
  19.       If (!Overwrite && FileExist(SaveFileAs))
  20.           Return
  21.     ;Check if the user wants a progressbar
  22.       If (UseProgressBar) {
  23.           ;Initialize the WinHttpRequest Object
  24.             WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  25.           ;Download the headers
  26.             WebRequest.Open("HEAD", UrlToFile)
  27.             WebRequest.Send()
  28.           ;Store the header which holds the file size in a variable:
  29.             FinalSize := WebRequest.GetResponseHeader("Content-Length")
  30.           ;Create the progressbar and the timer
  31.             Progress, H80, , Downloading..., %UrlToFile%
  32.             circleObj := CreateCircleProgress(450,60)
  33.             SetTimer, __UpdateProgressBar, 100
  34.       }
  35.     ;Download the file
  36.       UrlDownloadToFile, %UrlToFile%, %SaveFileAs%
  37.     ;Remove the timer and the progressbar because the download has finished
  38.       If (UseProgressBar) {
  39.           Progress, Off
  40.           SetTimer, __UpdateProgressBar, Off
  41.           DestroyCircleProgress(circleObj)
  42.       }
  43.     Return
  44.    
  45.     ;The label that updates the progressbar
  46.       __UpdateProgressBar:
  47.          ;Get the current filesize and tick
  48.             CurrentSize := FileOpen(SaveFileAs, "r").Length ;FileGetSize wouldn't return reliable results
  49.             CurrentSizeTick := A_TickCount
  50.           ;Calculate the downloadspeed
  51.             Speed := Round((CurrentSize/1024-LastSize/1024)/((CurrentSizeTick-LastSizeTick)/1000)) . " Kb/s"
  52.           ;Save the current filesize and tick for the next time
  53.             LastSizeTick := CurrentSizeTick
  54.             LastSize := FileOpen(SaveFileAs, "r").Length
  55.           ;Calculate percent done
  56.             PercentDone := Round(CurrentSize/FinalSize*100)
  57.           ;Update the ProgressBar
  58.             Progress, %PercentDone%, %PercentDone%`% Done, Downloading...  (%Speed%), Downloading %SaveFileAs% (%PercentDone%`%)
  59.             UpdateCircleProgress(circleObj,percentDone)
  60.       Return
  61. }
  62.  
  63. CreateCircleProgress(diameter:=50,thickness:=5,color:=0x99009933,xPos:="center",yPos:="center",guiId:=1) {
  64.     width := height := diameter+thickness*2
  65.     xPos := (xPos=="center" ? A_ScreenWidth/2-diameter/2-thickness : xPos)
  66.     yPos := (yPos=="center" ? A_ScreenHeight/2-diameter/2-thickness : yPos)
  67.     Gui, %guiId%: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  68.     Gui, %guiId%: Show, NA
  69.    
  70.     hwnd := WinExist()
  71.     hbm := CreateDIBSection(width, height)
  72.     hdc := CreateCompatibleDC()
  73.     obm := SelectObject(hdc, hbm)
  74.     G := Gdip_GraphicsFromHDC(hdc)
  75.     Gdip_SetSmoothingMode(G, 4)
  76.    
  77.     pen:=Gdip_CreatePen(color, thickness)
  78.     Gdip_SetCompositingMode(G, 1)
  79.     Return {hwnd:hwnd, hdc:hdc, obm:obm, hbm:hbm, pen:pen, G:G, diameter: diameter, thickness:thickness, xPos:xPos, yPos:yPos, width:width, height:height}
  80. }
  81. UpdateCircleProgress(circleObj,percent) {
  82.     Gdip_Drawarc(circleObj.G, circleObj.pen, circleObj.thickness, circleObj.thickness, circleObj.diameter, circleObj.diameter, 270, 360/100*percent)
  83.     UpdateLayeredWindow(circleObj.hwnd, circleObj.hdc, circleObj.xPos, circleObj.yPos, circleObj.width, circleObj.height)
  84. }
  85. DestroyCircleProgress(circleObj) {
  86.     Gui % circleObj.hwnd ":Destroy"
  87.     SelectObject(circleObj.hdc, circleObj.obm)
  88.     DeleteObject(circleObj.hbm)
  89.     DeleteDC(circleObj.hdc)
  90.     Gdip_DeleteGraphics(circleObj.G)
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement