Vadersapien Posted January 30, 2010 Posted January 30, 2010 Hi, I know this is probably quite simple, but I'd like to know how to download a file(in the background) and put the amount downloaded in the progress bar. I'd like to be able execute a function when the download finishes, as well as allowing the script to continue while downloading the files. It is a folder of files that will change quite contantly, so a file list can't be hardcoded. Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
martin Posted January 30, 2010 Posted January 30, 2010 Hi,I know this is probably quite simple, but I'd like to know how to download a file(in the background) and put the amount downloaded in the progress bar. I'd like to be able execute a function when the download finishes, as well as allowing the script to continue while downloading the files.It is a folder of files that will change quite contantly, so a file list can't be hardcoded.I assume that you have read the help for InetGet and still can't see how to do it. Is that correct? If the answer is "No" then I would be wasting my time with an answer. If the answer is "Yes" then I will add some ideas if no-one else does by the time I look at this thread again. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Vadersapien Posted January 31, 2010 Author Posted January 31, 2010 I had read the help for InetGet prior to posting this thread. Tried to implement it in my code, but it didn't work. Tried again from a fresh script. It worked. Here's how far I got: #include <GUIConstants.au3> Local $hGUI = GUICreate('Download File', 800, 70) Local $Progress = GUICtrlCreateProgress(10, 10, 780, 20) DirCreate(@TempDir & '\RS Media Manager\') GUISetState() _RSMWare_GetData('http://10.0.0.5/rsmware/rsmware.ini', @TempDir & '\RS Media Manager\rsmware.ini') GUICtrlCreateButton('Button', 10, 40, 780, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() DirRemove(@TempDir & '\RS Media Manager', 1) Exit EndSwitch WEnd Func _RSMWare_GetData($url, $target) $hDownload = InetGet($url, $target, 1, 1) Do GUICtrlSetData($Progress, Ceiling((InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100)) Until InetGetInfo($hDownload, 2) InetClose($hDownload) MsgBox(Default, '', IniRead(@TempDir & '\RS Media Manager\rsmware.ini', 'Alarm Clock', 'Author', 'Unknown')) EndFunc Because of the Do...Until loop in the function it "removes" the entire "background downloading" feature...is there a way to fix this? Also I haven't been able to figure out a way to download multiple files at once...could anyone help with this Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
martin Posted January 31, 2010 Posted January 31, 2010 (edited) I had read the help for InetGet prior to posting this thread. Tried to implement it in my code, but it didn't work. Tried again from a fresh script. It worked. Here's how far I got: #include <GUIConstants.au3> Local $hGUI = GUICreate('Download File', 800, 70) Local $Progress = GUICtrlCreateProgress(10, 10, 780, 20) DirCreate(@TempDir & '\RS Media Manager\') GUISetState() _RSMWare_GetData('http://10.0.0.5/rsmware/rsmware.ini', @TempDir & '\RS Media Manager\rsmware.ini') GUICtrlCreateButton('Button', 10, 40, 780, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() DirRemove(@TempDir & '\RS Media Manager', 1) Exit EndSwitch WEnd Func _RSMWare_GetData($url, $target) $hDownload = InetGet($url, $target, 1, 1) Do GUICtrlSetData($Progress, Ceiling((InetGetInfo($hDownload, 0)/InetGetInfo($hDownload, 1))*100)) Until InetGetInfo($hDownload, 2) InetClose($hDownload) MsgBox(Default, '', IniRead(@TempDir & '\RS Media Manager\rsmware.ini', 'Alarm Clock', 'Author', 'Unknown')) EndFunc Because of the Do...Until loop in the function it "removes" the entire "background downloading" feature...is there a way to fix this? Also I haven't been able to figure out a way to download multiple files at once...could anyone help with this Here is a quick example of downloading more than one file at a time. (Actually the same file multiple times) expandcollapse popup#include <GUIConstants.au3> Local $hGUI = GUICreate('Download File', 800, 370) ;Local $Progress = GUICtrlCreateProgress(10, 10, 780, 20) DirCreate(@TempDir & '\RS Media Manager\') GUISetState() Dim $hDownloadNo[10];say we want up to 10 downloads. We can increase with ReDim if needed $iIndex = 0 Dim $Progress[10];could be progress bars but for this example just make them edits Dim $Target[10] $inmax = 5;set the number of consecutive downloads. $inmax -= 1 if $inmax < 0 then $inmax = 0 if $inmax > 9 then $inmax = 9 For $n = 0 To $inmax $Progress[$n] = GUICtrlCreateProgress(10 + (Mod($n, 5)) * 150, Int($n / 5) * 40 + 20, 130, 15) $Target[$n] = @TempDir & "\pic" & $n & ".bmp" $hDownloadNo[$n] = _RSMWare_GetData('http://www.mosaiccgl.co.uk/inetgetimage/line1.bmp', $Target[$n]);5Mb file ; $hDownloadNo[$n] = _RSMWare_GetData('http://www.mosaiccgl.co.uk/inetgetimage/open3.bmp', $Target[$n]);4Kb file Next AdlibRegister("SetProgress", 500) GUICtrlCreateButton('Button', 10, 340, 780, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE AdlibUnRegister("SetProgress") GUIDelete() ;DirRemove(@TempDir & '\RS Media Manager', 1) For $n = 0 To $inmax If $hDownloadNo[$n] <> 0 Then InetClose($hDownloadNo[$n]) Next Exit EndSwitch WEnd Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) ConsoleWrite("handle = " & $hDownload & @CRLF) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state For $n = 0 To $inmax If $hDownloadNo[$n] <> 0 Then ConsoleWrite("Get data for handle " & $n & @CRLF) $state = InetGetInfo($hDownloadNo[$n]);, -1) If @error = 0 Then ConsoleWrite("bytes for " & $n & "= " & $state[0] & @CRLF) GUICtrlSetData($Progress[$n], Ceiling(($state[0] / $state[1]) * 100)) If $state[2] Then $hDownloadNo[$n] = 0 InetClose($hDownloadNo[$n]) EndIf EndIf EndIf Next EndFunc ;==>SetProgress It needs some work for a real script but I hope it gives the idea. I tried this a few times and if I set the maximum number of downloads to more than 6 I only ever had 6 successful downloads if I set the large file in my svcript. I would be interested if you find the same. Fo rthe small file 10 was ok. Also, on my PC with XP I only ever get 2 downloads at a time; when one has completed another starts so that there are at most 2 in progress. I guess this is a limitation of IE. Edited January 31, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
FaT3oYCG Posted January 31, 2010 Posted January 31, 2010 If you wanted to get really smart you could use http requests to download a file and the headder gives the total which would allow you to tell the user the percentage of the download (progress bar) but that may be a little advanced . Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.
ProgAndy Posted January 31, 2010 Posted January 31, 2010 (edited) If you wanted to get really smart you could use http requests to download a file and the headder gives the total which would allow you to tell the user the percentage of the download (progress bar) but that may be a little advanced .When using InetGet in asynchronous mode , you can fetch the sizes with InetGetInfo. You can get e.g. total size and already downloaded size.As far as I can see, this is already included in the code Edited January 31, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
FaT3oYCG Posted January 31, 2010 Posted January 31, 2010 I wasn't saying that it didn't do that I added that response as I don't see there being a limit on sending and receiving http requests, hence unlimited number of downloads (within reason) as you stated IE only seems to allow 2 at a time . Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.
modoran Posted January 31, 2010 Posted January 31, 2010 The 2 limit paralel downloads could be increased from registry, some pirated copy of windows has already increased this limit in install kit
martin Posted January 31, 2010 Posted January 31, 2010 The 2 limit paralel downloads could be increased from registry, some pirated copy of windows has already increased this limit in install kitAs explained here but not tested my me. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
ProgAndy Posted January 31, 2010 Posted January 31, 2010 (edited) As explained here but not tested my me.I think InetGet is not limited by this since it doesn't use IE, just the underlying unlimited Internet-API. Edited January 31, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Vadersapien Posted February 1, 2010 Author Posted February 1, 2010 Here is a quick example of downloading more than one file at a time. (Actually the same file multiple times) expandcollapse popup#include <GUIConstants.au3> Local $hGUI = GUICreate('Download File', 800, 370) ;Local $Progress = GUICtrlCreateProgress(10, 10, 780, 20) DirCreate(@TempDir & '\RS Media Manager\') GUISetState() Dim $hDownloadNo[10];say we want up to 10 downloads. We can increase with ReDim if needed $iIndex = 0 Dim $Progress[10];could be progress bars but for this example just make them edits Dim $Target[10] $inmax = 5;set the number of consecutive downloads. $inmax -= 1 if $inmax < 0 then $inmax = 0 if $inmax > 9 then $inmax = 9 For $n = 0 To $inmax $Progress[$n] = GUICtrlCreateProgress(10 + (Mod($n, 5)) * 150, Int($n / 5) * 40 + 20, 130, 15) $Target[$n] = @TempDir & "\pic" & $n & ".bmp" $hDownloadNo[$n] = _RSMWare_GetData('http://www.mosaiccgl.co.uk/inetgetimage/line1.bmp', $Target[$n]);5Mb file ; $hDownloadNo[$n] = _RSMWare_GetData('http://www.mosaiccgl.co.uk/inetgetimage/open3.bmp', $Target[$n]);4Kb file Next AdlibRegister("SetProgress", 500) GUICtrlCreateButton('Button', 10, 340, 780, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE AdlibUnRegister("SetProgress") GUIDelete() ;DirRemove(@TempDir & '\RS Media Manager', 1) For $n = 0 To $inmax If $hDownloadNo[$n] <> 0 Then InetClose($hDownloadNo[$n]) Next Exit EndSwitch WEnd Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) ConsoleWrite("handle = " & $hDownload & @CRLF) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state For $n = 0 To $inmax If $hDownloadNo[$n] <> 0 Then ConsoleWrite("Get data for handle " & $n & @CRLF) $state = InetGetInfo($hDownloadNo[$n]);, -1) If @error = 0 Then ConsoleWrite("bytes for " & $n & "= " & $state[0] & @CRLF) GUICtrlSetData($Progress[$n], Ceiling(($state[0] / $state[1]) * 100)) If $state[2] Then $hDownloadNo[$n] = 0 InetClose($hDownloadNo[$n]) EndIf EndIf EndIf Next EndFunc ;==>SetProgress It needs some work for a real script but I hope it gives the idea. I tried this a few times and if I set the maximum number of downloads to more than 6 I only ever had 6 successful downloads if I set the large file in my svcript. I would be interested if you find the same. Fo rthe small file 10 was ok. Also, on my PC with XP I only ever get 2 downloads at a time; when one has completed another starts so that there are at most 2 in progress. I guess this is a limitation of IE. Tested it on 7 and and only the 2nd and 4th progress bars work. The others don't budge. According to the console they aren't being downloaded either... The small ones seem to work fine though. Maybe a queue would be more suitable(the general idea would be to push the files into an array and read off that, wouldn't it?). Another thing I'd like to do is fire off a function to manipulate those files once downloaded(in this case extracting, I should be able to do that with the ZLib UDF) Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now