Shoutbox

[Help] Download progress? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] Download progress? (/showthread.php?tid=84618)

[Help] Download progress? by SmokingCookie on 07-01-2008 at 02:12 PM

Hi,

I am wondering if there is a way to monitor a file's download progress.
Since MsgPlus.DownloadFile() can't do this, I am looking for other ways to download a file, perhaps even with an XMLHTTP request (but there's probably some function in the Windows API, that's unknown to me :S ).

So, is there any way to monitor download progresses as IE and FireFox do?

Thanks in advance.


RE: [Help] Download progress? by Basilis on 07-01-2008 at 02:15 PM

There is a control that displays a bar in the window which is like downloading but not like displaying a progress.

Here it is:

<Control xsi:type="ProgressControl" Id="Example">
        <Position Top="5" Width="100" Left="0" Height="10"/>
                <Marquee/>
</Control>


RE: [Help] Download progress? by mynetx on 07-01-2008 at 02:18 PM

Call the MsgPlus.DownloadFile with a OutFile parameter that you know, and then check the filesize of the OutFile, based on a timer (FSO object, GetFile method, Size property).


RE: [Help] Download progress? by SmokingCookie on 07-01-2008 at 02:19 PM

Okay, that's an option for a known file.. But it won;t be possible for unknown OutFile's..

EDIT::

Here's what I'd like to do:

[Image: screenieyd3.th.jpg]


quote:
Originally posted by Basilis
There is a control that displays a bar in the window which is like downloading but not like displaying a progress.

Here it is:

<Control xsi:type="ProgressControl" Id="Example">
        <Position Top="5" Width="100" Left="0" Height="10"/>
                <Marquee/>
</Control>


Yes, that's that nice progress bar in IE which makes my PC freeze up :P

However, Microsoft has been so nice not to write an easy function to detect progresses :S .
RE: [Help] Download progress? by CookieRevised on 07-01-2008 at 09:33 PM

quote:
Originally posted by SmokingCookie
However, Microsoft has been so nice not to write an easy function to detect progresses :S .

just some quick thoughts without checking things first:

I very much doubt that there is an API like that which shows how much percent/ratio is completed. What maybe might exist is a callback function which reports back how many bytes have been saved so far or something.

But:
- You can't use such callbacks in Messenger Plus! anyways since they will be more than likely asynchronous callbacks.
- You still need to know the size of the complete file in order to be able to show a progress bar (which is always in the form of a ratio: x out of y, or x green/blue bars out of a total of y bars).

What you could do instead is showing a 'busy' indicator to the user. In that way the user still wont be able to see how much longer it will take, but he would be able to see that the script is still busy downloading. As a bonus you could also show the amount of bytes already downloaded, which is another good indication that the script is still busy doing usefull stuff instead of being in a dead-loop or been froozen.
RE: [Help] Download progress? by SmokingCookie on 07-02-2008 at 07:42 AM

Okay, then I'll do that.

However, one CAN make a progress bar indicating the readyState of an XMLHTTP request. Example:

Debug.Trace("> " + (25 * XMLHTTP.readyState));

This will go no further than 100%, so it's possible to indicate what the script is doing (sending request, receiving headers etc.)


RE: [Help] Download progress? by CookieRevised on 07-02-2008 at 06:08 PM

quote:
Originally posted by SmokingCookie
Okay, then I'll do that.

However, one CAN make a progress bar indicating the readyState of an XMLHTTP request. Example:

Debug.Trace("> " + (25 * XMLHTTP.readyState));

This will go no further than 100%, so it's possible to indicate what the script is doing (sending request, receiving headers etc.)
yep, but that is of course not really a progress bar either. The user usually wants to see the progress of the actual downloading (readyState 3), not the usually very fast initializing....

But it is way better than nothing of course....

(Do I smell a suggestion for the MsgPlus.DownloadFile() function here? :P)
RE: [Help] Download progress? by Matti on 07-02-2008 at 06:16 PM

quote:
Originally posted by CookieRevised
(Do I smell a suggestion for the MsgPlus.DownloadFile() function here? :P)
Something like a OnEvent_DownloadFileProgress(Url, OutFile, BytesDownloaded, BytesTotal) would be nice, yes. Go and bug Patchou about it! :P
RE: [Help] Download progress? by SmokingCookie on 07-02-2008 at 07:26 PM

That certainly is a good idea :P .. But at high download speeds, this event would be triggerd.. Many times :P (like an infinite loop). And I'm not even talking about big files being dowloaded at high speed..


RE: [Help] Download progress? by CookieRevised on 07-02-2008 at 07:39 PM

Timers can be triggered extremely quickly to though....

Then again, it could be solved a bit by adding a packet size parameter to DownloadFile() (or new downloadfile function) to tell Plus! to trigger DownloadFileProgress() each x bytes.

-------

Anyways, can't you just make something with some kind of ActiveX object or whatever. I mean, when you download a file with your browser, it usually tells you also how big the file is and thus being able to show you a progress dialog. So, find out how they do that (probably sending some kind of request first) and do the same in your script.


RE: [Help] Download progress? by SmokingCookie on 07-02-2008 at 07:46 PM

I've been considering this too, but I haven't seen any possibility (yet).

Anyway, I'm off now, I'll think of it tomorrow |-)


RE: [Help] Download progress? by Eljay on 07-02-2008 at 07:53 PM

quote:
Originally posted by CookieRevised
when you download a file with your browser, it usually tells you also how big the file is and thus being able to show you a progress dialog. So, find out how they do that (probably sending some kind of request first) and do the same in your script.

code:
var url  = 'http://www.google.co.uk/intl/en_uk/images/logo.gif';
var http = new ActiveXObject('Microsoft.XMLHTTP');
http.open('HEAD', url, true);
http.onreadystatechange = function(){
   if(http.readyState == 4){
      if(http.status == 200){
         Debug.Trace(http.getResponseHeader('Content-Length'));
      }
   }
}
http.send(null);


Doesn't always work though, depends if the header is sent (only seems to be sent on static files). No other way of getting the size before downloading that I know of...
RE: [Help] Download progress? by CookieRevised on 07-02-2008 at 08:11 PM

I just was looking around too, and found roughly the same thing. However, it should be done with readyState 3, not with 4.... (as 4 is triggered when done)?

http://www.sitepoint.com/blogs/2004/05/26/xmlhttp...vascript-closures/

code:
86                // Called multiple while downloading in progress
87                case 3:
88                    // Notify user handler of download progress
89                    try {
90                        // Get the total content length
91                        // -useful to work out how much has been downloaded
92                        try {
93                            var contentLength = client.xmlhttp.getResponseHeader("Content-Length");
95                        } catch ( e) {
96                            var contentLength = NaN;
97                        } 
98     
99                        // Call the progress handler with what we've got
100                        client.userhandler.onProgress(
101                            client.xmlhttp.responseText,
102                            contentLength
103                        );
104     
105                    } catch ( e) { /* Handler method not defined */ }
106                break;

...

131        onProgress: function(responseText, length) {
132            echo("Downloaded "+responseText.length+" of "+length+"<br>");
133        },

RE: [Help] Download progress? by Eljay on 07-02-2008 at 08:16 PM

quote:
Originally posted by CookieRevised
I just was looking around too, and found roughly the same thing. However, it should be done with readyState 3, not with 4....

That's with a full GET request with the whole file, my code is sending a HEAD request which doesn't download the whole file but just the headers.

I tried it in readyState 3 just in case and it throws a very descriptive "Unspecified error" :P It seems the response (getResponseHeader, responseText etc.) can't be accessed until the request is complete?

-----
Edit: found this:
quote:
Originally posted by http://msdn.microsoft.com/en-us/library/ms534361(VS.85).aspx

3 (Receiving)     Some data has been received. responseText is not available. responseBody is not available.
4 (Loaded)    All the data has been received. responseText is available. responseBody is available.


The remarks also provide a couple of possibilities that could be used, I shall experiment further :P
RE: [Help] Download progress? by SmokingCookie on 07-03-2008 at 07:51 AM

@ CookieRevised:

I have checked your code on the site you've linked to, and found this in the code:

// Mozilla only implementation!  (Line 6)

I don't know if this is imprtant, but I'll give it a try.

@Eljay:

Following code is based on yours:

code:
function OnEvent_Initialize(MessengerStart) {
    if(Messenger.MyStatus > STATUS_UNKNOWN) {
        var url  = "http://tom.zegiklekkerniet.googlepages.com/DateCalculator.plsc";
        var http = new ActiveXObject("Microsoft.XMLHTTP");
        http.open("HEAD", url, true);
        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) {
                FileSize = http.getResponseHeader("Content-Length");
                Debug.Trace("> " + FileSize);
            }
        }
        http.send(null);
    }
}


Debugger says "> 261048" and Windows' "Properties" window: "261.048 bytes".. Seems to work perfectly :D
RE: [Help] Download progress? by CookieRevised on 07-03-2008 at 11:44 PM

quote:
Originally posted by SmokingCookie
@ CookieRevised:

I have checked your code on the site you've linked to, and found this in the code:

// Mozilla only implementation!  (Line 6)

I don't know if this is imprtant, but I'll give it a try.
Very important actually.

Mozilla and MSIE have the xmlhttp object implemented differently.  I thought the code was for MSIE, showing an alternative way for something you could do in Mozilla.... I guess it was the other way around.... That's what you get when you're hasty :$, sorry...

quote:
Originally posted by Eljay
Edit: found this:
quote:
Originally posted by http://msdn.microsoft.com/en-us/library/ms534361(VS.85).aspx

3 (Receiving)     Some data has been received. responseText is not available. responseBody is not available.
4 (Loaded)    All the data has been received. responseText is available. responseBody is available.
The remarks also provide a couple of possibilities that could be used, I shall experiment further :P
cool... ServerXMLHTTP seems promissing a first sight. the IXMLHTTP object needs a language to be set for viewing webpages in order to work if I read it correctly.
RE: RE: [Help] Download progress? by SmokingCookie on 07-04-2008 at 07:28 AM

quote:
Originally posted by CookieRevised

Mozilla and MSIE have the xmlhttp object implemented differently.  I thought the code was for MSIE, showing an alternative way for something you could do in Mozilla.... I guess it was the other way around.... That's what you get when you're hasty :$, sorry...


Woo, I've been smarter than CookkieRevised for the first (and the last) time in my life :o) :P

Anyway, I have inserted Eljay's code and it works now :D
RE: [Help] Download progress? by Matti on 07-04-2008 at 08:58 AM

quote:
Originally posted by CookieRevised
cool... ServerXMLHTTP seems promissing a first sight. the IXMLHTTP object needs a language to be set for viewing webpages in order to work if I read it correctly.
Yes, that ServerXMLHTTP thingy looks interesting, as the readyState property will only be set to 2 (LOADED) when the headers are already loaded, in contrast to the 'normal' XMLHTTP request where the LOADED state is set directly after send() is called. The ServerXMLHTTP also allows us to get partial data during the process... :)

I think I'll give this a try today. ;)

EDIT: Okay, it doesn't work. The only way to get the partial data is through either the responseStream or responseBody properties, which are not supported by the JScript environment. If I try to get those properties, I get the following (Dutch) error:
quote:
De gegevens die nodig zijn voor deze bewerking zijn nog niet beschikbaar.
which means:
quote:
The data needed for this operation isn't available yet.
The responseText and responseXML properties aren't given any value during interactive mode, so they give the same error. This is quite sad, because it would have opened very interesting possibilities for scripting. :(
RE: [Help] Download progress? by mynetx on 10-01-2008 at 09:41 AM

Because other methods are not working (as experimented in this thread), I have brought in a suggestion for a MsgPlus.DownloadFile enhancement.


RE: [Help] Download progress? by CookieRevised on 10-04-2008 at 08:51 AM

You can get partial downloads by using the APIs of WININET.DLL directly. I've done this a long time ago in a big Excel project, which I completely forgot about.