Jump to content

Call a function with switch/case


 Share

Recommended Posts

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 !!

#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

 

Link to comment
Share on other sites

Use a Adlib registered func for check donwload:

#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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...