Sign in to follow this  
Followers 0
Gimerly

How to create a a progress bar when downloading

8 posts in this topic

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

Share this post


Link to post
Share on other sites



Hi,

You need to specify a filename in your InetGet "filename" parameter.

Also, I advice you to call InetGetSize before InetGet.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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. 

Share this post


Link to post
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.

Share this post


Link to post
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 

Share this post


Link to post
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
1 person likes this

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

I just tried using a php file which uses filesize() to echo the file size in instances where the file size from InetGetSize() comes up 0.

It works great.

Still not sure this should be necessary though.

Share this post


Link to post
Share on other sites

Didnt think of using a Do loop, thanks for the assistance 

Share this post


Link to post
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
Sign in to follow this  
Followers 0