What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] Download progress?

Pages: (2): « First « 1 [ 2 ] Last »
[Help] Download progress?
Author: Message:
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: [Help] Download progress?
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 |-)
07-02-2008 07:46 PM
Profile PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [Help] Download progress?
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...

This post was edited on 07-02-2008 at 07:54 PM by Eljay.
07-02-2008 07:53 PM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Help] Download progress?
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        },

This post was edited on 07-02-2008 at 08:32 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
07-02-2008 08:11 PM
Profile PM Find Quote Report
Eljay
Elite Member
*****

Avatar
:O

Posts: 2949
Reputation: 77
– / Male / –
Joined: May 2004
RE: [Help] Download progress?
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

This post was edited on 07-02-2008 at 08:27 PM by Eljay.
07-02-2008 08:16 PM
Profile PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: [Help] Download progress?
@ 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

This post was edited on 07-03-2008 at 07:59 AM by SmokingCookie.
07-03-2008 07:51 AM
Profile PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Help] Download progress?
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.

This post was edited on 07-03-2008 at 11:58 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
07-03-2008 11:44 PM
Profile PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: RE: [Help] Download progress?
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
07-04-2008 07:28 AM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [Help] Download progress?
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. :(

This post was edited on 07-04-2008 at 01:48 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
07-04-2008 08:58 AM
Profile E-Mail PM Web Find Quote Report
mynetx
Skinning Contest Winner
*****

Avatar
Microsoft insider

Posts: 1175
Reputation: 33
36 / Male / Flag
Joined: Jul 2007
RE: [Help] Download progress?
Because other methods are not working (as experimented in this thread), I have brought in a suggestion for a MsgPlus.DownloadFile enhancement.
mynetx - Microsoft, enhanced.

You have a problem or issue with Windows, Internet
Explorer or Office?
Send a tweet!
10-01-2008 09:41 AM
Profile E-Mail PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Help] Download progress?
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.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-04-2008 08:51 AM
Profile PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On