Jump to content

How to create a a progress bar when downloading


Recommended Posts

Hello, I have tried to make a progress bar in autoit but it doesn't work properly

func _sync ()

ProgressOn("Download", "Downloading...", "0%")
$url = "http://somewebsite.com"
$folder = @DesktopCommonDir & "/"
$hInet = InetGet($url, $folder, 1,  1 )
; used to actually retrieve the file
$filesize = InetGetSize($url)
while Not InetGetInfo($hInet, 2) ; loop until download is finished
   sleep(500) ; sleep for half a second
   $BytesRecieved = InetGetInfo($hInet, 0)
   $Pct = Int($Bytesrecieved /$filesize *100)
   progressSet($Pct, $Pct & "%") ; set progress bar
wend

; destroy the progress bar once the download is complete
ProgressOff()


endfunc

its really weird and has like 0.8% then stops

Link to comment
Share on other sites

thanks for the reply FireFox

I actually do specify the filename I got rid of it when uploading (sorry I should have used a stub thats my fault.) I tried having putting the get file size function before the actual downloading but the problem still happens. It goes to -0.992871838 then stops and if its a large file to doesn't update the size at all during the download and destroys it self once the download is finished. 

Link to comment
Share on other sites

I had this problem too and found that some proxy servers will not return the file size to the program. They do however return the bytes received. I used a default file size that is close but not absolute for those situations where a proxy interferes with getting the true file size. A better approach would be to use a php call on the server to filesize( [filename] ) as this would return the file size if the AutoIT function fails to get it. That should get around the proxy issues.

Of course, someone else may have a comment on this as well.

You should also make sure your server sends headers that set the max-age of your download file to 0 so any proxy server doesn't cache the file and cause even more issues, like not notifying AutoIT of the bytes streamed. Once I did that via .htaccess it helped a lot for my downloadable zip files, etc.

Link to comment
Share on other sites

Thanks for the reply,  I do not have a proxy server at my house. I think maybe its an issue with the function. I am currently looking at WinHttp which can hopefully do a better job 

Link to comment
Share on other sites

I basically did the same kind of function for a program I wrote for my job. Mine was different in that I used a Do... Until loop using the the remote file size and the local file size. I have been using it for years with no trouble.

Basically, it looks something like this:

$remoteFile = "http://somewebsite.com/File.exe"
$remoteFileSize = InetGetSize($remoteFile)
$download = InetGet($remoteFile)
ProgressOn("blah blah blah")

Do
    $localFileSize = FileGetSize(@DesktopDir & "\File.exe")
    ProgressSet("blah blah blah")
Until $localFileSize = $remoteFileSize
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...