 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 1338
|
Posted: Thu May 24, 2007 8:57 am Post subject: UrlDownloadToFile Progress |
|
|
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 |
|
 |
BoBoĻ Guest
|
Posted: Thu May 24, 2007 9:13 am Post subject: |
|
|
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.
Have fun  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Thu May 24, 2007 9:32 am Post subject: |
|
|
Dear Sean,
I expected this, but not so fast..
I am overwhelmed!.. Thank you
This looks like a dream. I will reply as soon as I wake-up.
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1338
|
Posted: Thu May 24, 2007 9:47 am Post subject: |
|
|
Thanks, BoBo and Skan.
I simplified the script a little. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu May 24, 2007 10:29 am Post subject: |
|
|
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 |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Thu May 24, 2007 10:40 am Post subject: |
|
|
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 |
|
 |
new_noobie Guest
|
Posted: Thu May 24, 2007 11:17 am Post subject: |
|
|
@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
This forum would be alot less useful without your presence.
(and some other gurus also ) |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Thu May 24, 2007 1:21 pm Post subject: |
|
|
Dear Sean,
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.
 |
|
| Back to top |
|
 |
JGR
Joined: 15 Jun 2006 Posts: 52 Location: Unavailable until ~30th August
|
Posted: Thu May 24, 2007 1:33 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5887
|
Posted: Thu May 24, 2007 1:40 pm Post subject: |
|
|
| 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
 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1338
|
Posted: Fri May 25, 2007 12:14 am Post subject: |
|
|
| toralf wrote: | | And this a another simplified mod of a part of PhiLhos script. |
I like it. I updated the script. |
|
| Back to top |
|
 |
AbsolutePressure
Joined: 28 May 2006 Posts: 30
|
Posted: Wed May 30, 2007 1:55 pm Post subject: |
|
|
I get an error on line10
| Quote: | | This line does not contain a recognized action. |
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1338
|
Posted: Wed May 30, 2007 2:20 pm Post subject: |
|
|
| AbsolutePressure wrote: | I get an error on line10  |
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 |
|
 |
Helpy Guest
|
Posted: Wed May 30, 2007 2:21 pm Post subject: |
|
|
| 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
|
Posted: Wed May 30, 2007 10:41 pm Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|