Jump to content

"linking" a download progress to a status bar?


Recommended Posts

Hi there, I'm using InetGet to download files off of my vps (will use this script to make my own patcher).

I have tried doing this:

Func downloadFile($fUrl, $fDir, $fName)
    Local $hDownload = InetGet($fUrl, $fDir&"\"&$fName, 1, 1)
    $dlPrc=(InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100
    Do
        $dlPrc=(InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100
        _GUICtrlStatusBar_SetText("Status: retrieving index file... ("&$dlPrc&"%)")
        Sleep(10)
        $dlPrc=(InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100
    Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
    Local $nBytes = InetGetInfo($hDownload, 0)
    InetClose($hDownload) ; Close the handle to release resources.
    Return InetGetInfo($hDownload, 2)
EndFunc
;note, I modified the code from the help file to suit my needs

And then called the function to download the file in my @TempDir. The problem is that the statusbar isn't being updated.

I have previously set the text to "Status: idle", and even after I call the downloadFile function, it doesn't change. I know the file is downloaded because I can see it. How can I get it to display $dlPrc in my StatusBar?

Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

Oh okay, I tried running the example script, and that's definitely not what I'm trying to do.

What I am trying to do, is to download a file from my VPS and display the progress of the download (in text format) on the Status Bar.

For example, if the progress of the download was 47%, the Status Bar would say:

"Status: retrieving index file... (47%)"

But it only goes

"Status: retrieiving index file... (100%)" (once it's finished, of course)

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

Try using INetGetSize() instead of INetGetInfo() to get the size of the download - and just call that once and assign to a variable you can use for calculations. Not sure if that will make a difference or not, but now I'm actually curious what the difference could be between the two.

Edit: Nevermind...I guess...didn't help for me. Still want to know what the difference is though!

Edited by MrMitchell
Link to comment
Share on other sites

Monitor $dlPrc using temporary alternate means like a ConsoleWrite(). Increase the sleep from 10 to something like 250 or even a half a second. How big is the file? Also trying monitoring

InetGetInfo($hDownload, 1) to see what number is getting returned.

You say your status bar eventually says 100% so there doesn't seem to be any problem setting the text. The problem seems to lie in the numbers and calculations...

Link to comment
Share on other sites

Hi MrMitchell,

I've been monitoring $dlPrc as you asked, and I found out this:

-1.#IND
-1.#IND
-1.#IND
-1.#IND
-1.#IND
1.21944593509338
1.21944593509338
5.56372207886356
5.56372207886356
16.996027720364
16.996027720364
29.3429178131845
29.3429178131845
41.6135925350617
41.6135925350617
53.5794057731655
53.5794057731655
65.926295865986
65.926295865986
77.9683244750331
77.9683244750331
90.2389991969103
90.2389991969103
100

So I decided to fix the -1.#IND by adding an if statement after each change.

$dlPrc=(InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100
        If $dlPrc=="-1.#IND" Then
            $dlPrc=0
        EndIf

And it doesn't output -1.#IND now. Still, no text change.

P.S: The file is 1.28mb

Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

OH, WOW.

I just noticed, I didn't add in which StatusBar's text had to change...

Thanks for the support ;)

lol!

Changed this

_GUICtrlStatusBar_SetText("Status: retrieving index file... ("&$dlPrc&"%)")

To this

_GUICtrlStatusBar_SetText($StatusBar1, "Status: retrieving index file... ("&StringMid($dlPrc, 1, 5)&"%)")
Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

Link to comment
Share on other sites

Oh okay, I tried running the example script, and that's definitely not what I'm trying to do.

What I am trying to do, is to download a file from my VPS and display the progress of the download (in text format) on the Status Bar.

For example, if the progress of the download was 47%, the Status Bar would say:

"Status: retrieving index file... (47%)"

But it only goes

"Status: retrieiving index file... (100%)" (once it's finished, of course)

So how did it change as per your post #4? ;)

Link to comment
Share on other sites

It changed because I had another

_GUICtrlStatusBar_SetText("Status: retrieving index file... ("&$dlPrc&"%)")

To read the $dlPrc out of the loop, and this one had the $StatusBar variable. Read the other reply ;)

Edited by megablox

"The story of a blade is linked in Blood." 

―Yasuo

 

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...