AutoHotkey Community

It is currently May 27th, 2012, 10:11 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Download Progress Bar
PostPosted: July 28th, 2006, 7:18 am 
Offline

Joined: July 20th, 2006, 6:41 pm
Posts: 144
Location: Los Angeles
This is functions will download and put up a progress bar for your download. This may have been done before, but I couldn't find a clean example of it with a progress bar (there were other progress methods that were used - some for tranfering files, some for downloading)

Thanks to Rajat for his example and Gre and Ranomore for their example

Code:
;dLocation = URL of download, path = where to download to and what name
Download(path, dLocation, FullFileName)
{
   Progress, H80, , Downloading..., %FullFileName% Download
   SetTimer, GetSize, 1000   
   UrlDownloadToFile, %dLocation%, %path%
   Progress, Off
   SetTimer, GetSize, Off
   Return
}

GetSize:
   FullSize := HttpQueryInfo(dLocation, 5) ; get download file size in bytes
   FileGetSize, FSize, %path%, K ; Get file size in kb
   FullSize := FullSize / 1000 ; Make in to kb
   UpdateSize := FSize / FullSize ; get percentage
   UpdateSize := UpdateSize * 100 ; take out of decimal form
   UpdateSize := Floor(UpdateSize)
   IfEqual, FSize, FullSize, Return
   IfNotEqual, ErrorLevel, 1
      Progress, %UpdateSize%, %UpdateSize%`% Complete, Downloading..., %FullFileName% Download - %UpdateSize%`% Complete
Return


Note: FullFileName, Path and dLocation need to be declared earlier in the script for GetSize: to pick up
where:
dLocation is the URL of the downloaded file
FullFileName can be anything, I name it the full name of the file (for example, "TUGZip 3.4")
path is the location you want the file to be downloaded to on the disk (which includes the file name, could be %A_ScriptDir%\tugzip34.exe)

Also, HttpQueryInfo is used, which can be found here

EDIT: There was a slight error where the Progress window didn't close. That's corrected. Also made the timer interval less.

-Kerry

Other keywords: status box


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 31st, 2006, 12:35 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for posting this. It's good to see all the info summarized in one place so concisely.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2006, 12:33 pm 
Offline

Joined: March 21st, 2006, 8:31 pm
Posts: 49
Location: Slovakia, Europe :)
hmm, this is nice but have some flaws.
1) i cant call function like this
Download("e:\dk\dotakeys.exe", "http://www.longmark.sk/access/dotakeys1.3/dotakeys.exe", "dotakeys.exe") and this is really bad about it :( ( but it can be fixed very easy )

2) it dont work with smaller files ( like <500 kb or so ). It only shows me 0% and then disappear. ( and i dont have so fast conection it can be dl-ed in 1 sec :) ) it stay there on 0% for 8 sec and dont update.

_________________
RegExReplace("C:\Program Files\AutoHotkey", "(^C)(?=\W).{4}((?i)[GOD])\w{1,4}\s(\D)(?:\w+)*\\(?3)(u|o).*?(k).*" , "$3$4$l1$5$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2006, 9:21 pm 
Offline

Joined: March 21st, 2006, 8:31 pm
Posts: 49
Location: Slovakia, Europe :)
now i modified it a bit and u can call it with download(this, from ther, name) and donot need to set them before

Code:
Download(path_p, dLocation_p, FullFileName_p)
{
   global path, dLocation, FullFileName,   ;NEW
   path = %path_p%                             ;NEW
   dLocation = %dLocation_p%               ;NEW
   FullFileName = %FullFileName_p%      ;NEW 
   Progress, H80, , Downloading..., %FullFileName% Download
   SetTimer, GetSize, 500
   UrlDownloadToFile, %dLocation%, %path%
   Progress, Off
   SetTimer, GetSize, Off
   Progress, Off
   Return
}

_________________
RegExReplace("C:\Program Files\AutoHotkey", "(^C)(?=\W).{4}((?i)[GOD])\w{1,4}\s(\D)(?:\w+)*\\(?3)(u|o).*?(k).*" , "$3$4$l1$5$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2006, 11:19 pm 
Offline

Joined: July 20th, 2006, 6:41 pm
Posts: 144
Location: Los Angeles
Thank you for those notes and corrections.

I also noted you put a Progress, Off after the SetTimer, GetSize, Off, is there any reason for this?

As far as the progress bar not working on that... I think its under 1mb because I had a similar problem, but I figured that it was just because the download hadn't actually installed (it lasted for like 2 seconds) and I figured it connection just dl'ed it that fast. I will look into it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2006, 12:23 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
This is a very useful technique, I'll be using it a lot. I modified your function a little bit so everything is done within the function:
Code:
Download(url, save, msg = 0x1100, sleep = 250) {
   total := HttpQueryInfo(url, 5)
   SetTimer, _dlprocess, %sleep%
   UrlDownloadToFile, %url%, %save%
   SetTimer, _dlprocess, Off
   Return, ErrorLevel
   _dlprocess:
   FileGetSize, current, %save%, K
   Process, Exist
   PostMessage, msg, current * 1024, total, , ahk_pid %ErrorLevel%
   Exit
}

url: the URL of the file to download
save: where the downloaded file should be saved to
msg: [0x1100] the message the script should send itself (see below)
sleep: [250] how often to send the message in ms

Download can be monitored with OnMessage(), wParam is the current progress of the download and lParam is the total size of the remote file, both in bytes. Here is an uncommented GUI script example (you'll need to include HttpQueryInfo and the above function):
Code:
url = http://dl.google.com/earth/GoogleEarth.exe
save = %A_Temp%\earth.exe
FileDelete, %save%
message = 0x1100

Gui, Add, Progress, Section vProgressBar w500 -Smooth
Gui, Font, bold
Gui, Add, Text, vProgressN ys, ..........
Gui, Add, Text, xm Section, Downloading:
Gui, Font
Gui, Add, Text, ys, %url%
Gui, Add, Text, vKB ys w200

Gui, Show, , Downloading...
OnMessage(message, "SetCounter")
Download(url, save, message, 50)
GuiControl, , ProgressBar, 100
GuiControl, , ProgressN, 100`%
GuiControl, , KB
Gui, Show, , Downloaded
Return

GuiEscape:
GuiClose:
ExitApp

SetCounter(wParam, lParam) {
   progress := Round(wParam / lParam * 100)
   GuiControl, , ProgressBar, %progress%
   GuiControl, , ProgressN, %progress%`%
   wParam := wParam // 1024
   lParam := lParam // 1024
   GuiControl, , KB, (%wParam%kb of %lParam%kb)
   Gui, Show, , %progress%`% - Downloading...
}


Ofcourse if you prefer the simpler Progress instead of a GUI:
Code:
url = http://dl.google.com/earth/GoogleEarth.exe
save = %A_Temp%\earth.exe
FileDelete, %save%
message = 0x1100
Progress, M h80 w500, , .
OnMessage(message, "SetCounter")
Download(url, save, message, 50)
ExitApp

SetCounter(wParam, lParam) {
   global url
   progress := Round(wParam / lParam * 100)
   wParam := wParam // 1024
   lParam := lParam // 1024
   Progress, %progress%, %url%, Downloading %wParam%kb of %lParam%kb..., %progress%`% - Downloading...
}


Thanks again :)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 6th, 2006, 6:58 am 
Offline

Joined: July 20th, 2006, 6:41 pm
Posts: 144
Location: Los Angeles
Hi Titan, thanks!

Didn't realize this has been updated. I was wondering, though, because I like to make functions inclusive (so no other code has to be placed elsewhere). Would you be able to do that with your code?

I've made a mod of HttpQueryInfo that works as a sub. It can be found here.

I'm a bit tired of recently and you're a better programmer than I... and I'm not sure if I could make a working version of your code. I also know that while using a function you can't make a gui with global variables, and that's what I ran into before when I tried to do it, and I'm not sure how to work around it or I would have tried :)

-Kerry

_________________
String Manipulator - GrabIco


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 10:35 pm 
Offline

Joined: May 18th, 2007, 9:37 pm
Posts: 33
What's a decent way to incorporate creating the GUI, updating the GUI, and downloading the item all in a few functions...

All I want is to be able to input the URL and it would create a standardized download progress dialog.

The reason I ask is that this is a mere portion of what my script does all the download GUI would do is download an update.

I have been messing around with everything and I can't seem to figure it out :?

Can someone lend me a hand?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2007, 6:17 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Athfar wrote:
All I want is to be able to input the URL and it would create a standardized download progress dialog.


You may try this: http://www.autohotkey.com/forum/viewtop ... 074#118074

:roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 2:33 am 
Can someone please show an example on how this can be implemented?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 26th, 2008, 3:46 am 
Put that & HttpQueryInfo() in a file, use like this:
Code:
Download("C:\google.html","http://www.google.com","google.html")


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2008, 1:49 am 
Offline

Joined: August 16th, 2008, 7:04 am
Posts: 27
Titan,
I've incorporated your code in my script. The files are downloaded. The progress bar works but the text indicating the file downloading (url) is missing.
Code:
Progress, %progress%, %url%, Downloading %wParam%kb of %lParam%kb..., %progress%`% - Downloading...


So, the SubText is missing from my progress control. I check in
Code:
SetCounter(wParam, lParam) {
   global url


url == blank

Basically, I added both functions you gave and added the following where I needed to download a file:
Code:
save = Banner.jpg
message = 0x1100
Progress, M h80 w500, , .
OnMessage(message, "SetCounter")
Download(url, save, message, 50)


Any thoughts on my issue?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2008, 2:01 am 
Offline

Joined: August 16th, 2008, 7:04 am
Posts: 27
bixtool wrote:
Titan,
Code:
SetCounter(wParam, lParam) {
   global url


url == blank


Sorry, ignore this request. I saw my answer after I posted a snipped of your code.

I had to declare url as a global variable in all my procedures/functions.

BTW: great script. Thanks for posting


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2008, 5:26 pm 
Offline

Joined: August 16th, 2008, 7:04 am
Posts: 27
I'm using titan's functions to download several file types. I've noticed that the file size for html files is being reported as zero.
ex.
Downloading 28Kb of 0kb

Could ths be my mistake?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2008, 6:42 am 
Offline

Joined: August 20th, 2008, 4:25 pm
Posts: 256
Oh very nice, with this you could make a downloader for a specific program or game (like I've seen in 9Dragons).

Thanks again!

_________________
-Chavez.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: specter333, XX0 and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group