ATR Posted June 16, 2016 Posted June 16, 2016 Hello, I have a problem with my script. I have a GUI and condition with switch / case / endswitch I call a function if we clicked the "download" button, andwe click an other button, we must wait until the first case statement is not finished !! expandcollapse popup#include <GUIConstantsEx.au3> #include <Inet.au3> Global $Gui = GUICreate("", 250, 100) $Specs = GUICtrlCreateButton("Download", 20, 70, 100, 26) $Open_Folder = GUICtrlCreateButton("Open folder", 140, 70, 100, 26) Global $Download_Folder = @DesktopDir & "\" GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Specs Call(Test_1()) ContinueLoop Case $Open_Folder ShellExecute(@DesktopDir & "\") EndSwitch WEnd GUIDelete($Gui) Func Test_1() Local $File_Size = InetGetSize("http://updates3.safer-networking.org/spybot1/spybotsd162.exe", $INET_FORCERELOAD) ConsoleWrite($File_Size & @LF) $Download = InetGet("http://updates3.safer-networking.org/spybot1/spybotsd162.exe", $Download_Folder & "Spybot162.exe", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) $Info = InetGetInfo($Download) If @error Then Return 0 Else While Not InetGetInfo($Download, $INET_DOWNLOADCOMPLETE) Sleep(100) WEnd InetClose($Download) ConsoleWrite("END" & @LF) EndIf EndFunc
AutoBert Posted June 16, 2016 Posted June 16, 2016 Use a Adlib registered func for check donwload: expandcollapse popup#include <GUIConstantsEx.au3> #include <Inet.au3> Global $Gui = GUICreate("", 250, 100) $Specs = GUICtrlCreateButton("Download", 20, 70, 100, 26) $Open_Folder = GUICtrlCreateButton("Open folder", 140, 70, 100, 26) Global $Download, $Download_Folder = @DesktopDir & "\" GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Specs Call(Test_1()) ContinueLoop Case $Open_Folder ShellExecute(@DesktopDir & "\") EndSwitch WEnd GUIDelete($Gui) Func Test_1() Local $File_Size = InetGetSize("http://updates3.safer-networking.org/spybot1/spybotsd162.exe", $INET_FORCERELOAD) ConsoleWrite($File_Size & @LF) $Download = InetGet("http://updates3.safer-networking.org/spybot1/spybotsd162.exe", $Download_Folder & "Spybot162.exe", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) $Info = InetGetInfo($Download) If @error Then Return 0 Else AdlibRegister('_Downloaded', 100) EndIf EndFunc ;==>Test_1 Func _Downloaded() If not InetGetInfo($Download, $INET_DOWNLOADCOMPLETE) Then Return InetClose($Download) ConsoleWrite("END" & @LF) AdlibUnRegister('_Downloaded') EndFunc ;==>_Downloaded
ATR Posted June 20, 2016 Author Posted June 20, 2016 My new problem is I have multiple func like Test_1() (with download) and if I put AdlibRegister in each function, it doesn't work properly
AutoBert Posted June 21, 2016 Posted June 21, 2016 There is only one func needed watching if there is at least one handle from a backload download open. Use a Arrays for your downloadlinks and the opened/running Downloads.
ATR Posted June 21, 2016 Author Posted June 21, 2016 with this method I can't download multiple at once
AutoBert Posted June 22, 2016 Posted June 22, 2016 (edited) 17 hours ago, ATR said: with this method I can't download multiple at once with this method it's possible,it's only a problem of your logic. Edited June 22, 2016 by AutoBert
ATR Posted June 22, 2016 Author Posted June 22, 2016 Thank you for your help AutoBert ! I make several tests ! But I can't use links in my array, because all my downloads are not direct links ! For each program I want download I use a function An example of download : Func Malwarebytes_Anti_Malware() $http = ObjCreate("WinHttp.WinHttpRequest.5.1") $http.Open("GET", "http://data-cdn.mbamupdates.com/v0/program/mbam.check.program") $http.Send() $http.WaitForResponse() $source = $http.ResponseText $statut = $http.Status If $statut == 200 Then Local $File_Size = InetGetSize("http://data-cdn.mbamupdates.com/v0/program/data/mbam-setup-" & $source & ".exe", $INET_FORCERELOAD) $Telechargement = InetGet("http://data-cdn.mbamupdates.com/v0/program/data/mbam-setup-" & $source & ".exe", $Dossier_Telechargement & "Malwarebytes.exe", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) $Info = InetGetInfo($Telechargement) If Not @error Then While Not InetGetInfo($Telechargement, $INET_DOWNLOADCOMPLETE) $Avancement = InetGetInfo($Telechargement, $INET_DOWNLOADREAD) $Pourcentage = $Avancement * 100 / $File_Size GUICtrlSetData($ID_Label, Round($Pourcentage) & " %") Sleep(100) WEnd GUICtrlSetData($ID_Label, "100 %") InetClose($Telechargement) EndIf EndIf $http = 0 EndFunc
ATR Posted June 22, 2016 Author Posted June 22, 2016 (edited) I have multiple functions like this, and I want download in my loop Edited June 25, 2016 by ATR
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