AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

UrlDownloadToFile Progress
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1338

PostPosted: Thu May 24, 2007 8:57 am    Post subject: UrlDownloadToFile Progress Reply with quote

This is a preliminary/oversimplified version which will show a progress percentage of downloading of a web file.
It's written on request of our dear friend Skan.

It was become possible due to the ingenious work by JGR, callback.dll , which is absolutely needed in the script.
Many thanks to him.

PS. I used DebugView here to display the percentage.
And, please keep in mind that this is only a test version, so there may be problems. Then, please inform me.

RegisterCallback version:
Code:
sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
sFile := A_Temp . "\AutoHotkeyInstall.exe"

Progress, % "M W" . A_ScreenWidth//2, 0, 0 of 0
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
   NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)

DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
   If A_EventInfo = 6
   Progress, % p := 100 * nProgress//nProgressMax, %p%, % nProgress . " of " . nProgressMax
   Return 0
}

callback.dll version:
Code:
sUrl  := "http://download.sysinternals.com/Files/DebugView.zip"
sFile := "C:\DebugView.zip"

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)

OnMessage(WM_AHK_Callback := DllCall("RegisterWindowMessage", "str", "WM_AHK_Callback"), "WM_AHK_Callback")

VarSetCapacity(vt, 4*11), hModule := DllCall("LoadLibrary", "str", "callback"), nParams = 31132253353
Loop, Parse, nParams
   EncodeInteger(&vt + 4*(A_Index-1), hCallback%A_Index% := DllCall("callback\callbackit", "Uint", A_LoopField, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", A_Index-1))

MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel . "|" . A_LastError

Loop, 11
   DllCall("GlobalFree", "Uint", hCallback%A_Index%)
DllCall("FreeLibrary", "Uint", hModule)
ExitApp


WM_AHK_Callback(wParam, lParam)
{
   OutputDebug, % wParam <> 6 ? wParam : DecodeInteger(lParam+4)/DecodeInteger(lParam+8) * 100
   Return 0
}

DecodeInteger(ref, nSize = 4)
{
   DllCall("RtlMoveMemory", "int64P", val, "Uint", ref, "Uint", nSize)
   Return val
}

EncodeInteger(ref, val = 0, nSize = 4)
{
   DllCall("RtlMoveMemory", "Uint", ref, "int64P", val, "Uint", nSize)
}


Last edited by Sean on Wed Jun 13, 2007 2:12 am; edited 5 times in total
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Thu May 24, 2007 9:13 am    Post subject: Reply with quote

I really like to see to be surrounded by proffessionals .
Thx Sean & to all of you out there. Keep up your good work.
Much appreciated.

Very Happy Have fun Very Happy
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Thu May 24, 2007 9:32 am    Post subject: Reply with quote

Dear Sean,

I expected this, but not so fast.. Surprised
I am overwhelmed!.. Thank you

This looks like a dream. I will reply as soon as I wake-up.

Smile
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1338

PostPosted: Thu May 24, 2007 9:47 am    Post subject: Reply with quote

Thanks, BoBo and Skan. Very Happy
I simplified the script a little.
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu May 24, 2007 10:29 am    Post subject: Reply with quote

Aah, the power of copy/paste...
I prefer this form:
Code:
sUrl  = http://www.autohotkey.com/download/AutoHotkeyInstall.exe
sFile = C:\AutoHotkeyInstall.exe

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)
Progress M W400 R1-100, -, Downloading, %A_ScriptName%

WM_AHK_Callback := DllCall("RegisterWindowMessage", "str", "WM_AHK_Callback")
OnMessage(WM_AHK_Callback, "WM_AHK_Callback")

hModule    := DllCall("LoadLibrary", "str", "callback")
vals = 31132253353
Loop 11
{
   i := A_Index - 1
   v := SubStr(vals, A_Index, 1)
   hCallback%i% := DllCall("callback\callbackit", "Uint", v, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", i)
}

VarSetCapacity(vt, 4 *11)
Loop 11
{
   i := A_Index - 1
   EncodeInteger(&vt+ 4 * i, hCallback%i%)
}

MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel "|" A_LastError

Loop 11
{
   i := A_Index - 1
   DllCall("GlobalFree", "Uint", hCallback%i%)
}
DllCall("FreeLibrary","Uint", hModule)
ExitApp


WM_AHK_Callback(wParam, lParam)
{
   p := wParam <> 6 ? wParam : DecodeInteger(lParam+4)/DecodeInteger(lParam+8) * 100
   Progress %p%, % Floor(p)
   Return 0
}
I added a progress bar, I first thought it didn't worked, as I expected to see the IE download progress bar...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Thu May 24, 2007 10:40 am    Post subject: Reply with quote

And this a another simplified mod of a part of PhiLhos script. *Not tested* Since I do not have callback.dll installed yet
Code:
vals = 31132253353
Loop, Parse, vals
   hCallback%A_Index% := DllCall("callback\callbackit", "Uint", A_LoopField, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", A_Index - 1)
VarSetCapacity(vt, 4 *11)
Loop 11
   EncodeInteger(&vt+ 4 * (A_Index - 1), hCallback%A_Index%)
MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel "|" A_LastError
Loop 11
   DllCall("GlobalFree", "Uint", hCallback%A_Index%)

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
new_noobie
Guest





PostPosted: Thu May 24, 2007 11:17 am    Post subject: Reply with quote

@PhiLho
Thanks for the working example. I have been following the "callback"
discussions here, and have not been able to get any of the examples
to work on Win98.

Your posted code (after I added XXXInteger subroutines) worked
very well Very Happy

This forum would be alot less useful without your presence.
(and some other gurus also Smile )
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Thu May 24, 2007 1:21 pm    Post subject: Reply with quote

Dear Sean, Smile

I tested your code and it does not work for me in Win 2k SP4 / Win XP SP2
I get the MsgBox with ErrorLevel:0xc0000005 and LastError:126

    ---------------------------
    URL.ahk
    ---------------------------
    |0xc0000005|126
    ---------------------------
    OK
    ---------------------------


Ditto with PhiLho's code.

Rolling Eyes
Back to top
View user's profile Send private message
JGR



Joined: 15 Jun 2006
Posts: 52
Location: Unavailable until ~30th August

PostPosted: Thu May 24, 2007 1:33 pm    Post subject: Reply with quote

Put a pause command just before the DllCall, and post the contents of your variables.
Also check that you actually have the callback.dll and urlmon.dll

JGR
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5887

PostPosted: Thu May 24, 2007 1:40 pm    Post subject: Reply with quote

JGR wrote:
Check that you actually have the callback.dll


That was it! Long awaited, and glad to have this facility.
Thanks to you and Sean

Very Happy
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1338

PostPosted: Fri May 25, 2007 12:14 am    Post subject: Reply with quote

toralf wrote:
And this a another simplified mod of a part of PhiLhos script.

I like it. I updated the script.
Back to top
View user's profile Send private message
AbsolutePressure



Joined: 28 May 2006
Posts: 30

PostPosted: Wed May 30, 2007 1:55 pm    Post subject: Reply with quote

I get an error on line10 Question

Quote:
This line does not contain a recognized action.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1338

PostPosted: Wed May 30, 2007 2:20 pm    Post subject: Reply with quote

AbsolutePressure wrote:
I get an error on line10 Question

What build of AHK are you using currently?
I just noticed Chris updated AHK to 1.0.46.16 today, it can be a good time to update if you're using some older build.
And, don't forget to download callback.dll too, which is linked at the top post.
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Wed May 30, 2007 2:21 pm    Post subject: Reply with quote

This usually means your version of AutoHotkey is too old. Sean uses some new facilities, like assignment as expression and multiple expression on one line.
Back to top
AbsolutePressure



Joined: 28 May 2006
Posts: 30

PostPosted: Wed May 30, 2007 10:41 pm    Post subject: Reply with quote

Yes, I looked and I am using an old version. Sorry. I have 1.0.46.10, but I will update today. I am certainly not blaming anyone but myself for the mistake, but I would like to make a forum suggestion. The suggestion would be in having the scripts labeled in the version they were created. This might help ignorant post such as mine from having the wrong version.

Sorry Sean for posting the error off my own mistake, and thanks for sharing this script.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group