Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
Global $Url,$MainButton,$temp,$ButtonQuit,$progressbar1,$ButtonStop,$percentage
[b]Global $GUI = GUICreate("Firefox Download Automatization", 300, 200, -1, -1,$WS_OVERLAPPEDWINDOW,$WS_EX_LAYERED)[/b]
GUICtrlSetColor (- 1 , 32250) ;thème Windows
WinSetTrans("Firefox Download Automatization","",210); Défini la transparence de la fenêtre
Init()
GUISetState(@SW_SHOW)
GUICtrlSetState($MainButton, $GUI_FOCUS)
GUICtrlSetState($ButtonQuit, $GUI_HIDE)
GUICtrlSetState($ButtonStop, $GUI_HIDE)
$percentage = 0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $MainButton
If ($temp <> "Install") Then
Download_Firefox()
Else
Install_Firefox()
EndIf
Case $GUI_EVENT_RESIZED
$InfoBox = WinGetPos($GUI)
$Width = $InfoBox[2]
$Height = $InfoBox[3]
Case $GUI_EVENT_CLOSE
ExitLoop
Case $ButtonQuit
ExitLoop
EndSwitch
WEnd
Func Init()
Global $Url = "http://download.mozilla.org/?product=firefox-3.0rc2&os=win&lang=fr"
$InfoBox = WinGetPos($GUI)
$Width = $InfoBox[2]
$Height = $InfoBox[3]
$picb = GUICtrlCreatePic("C:\firefox.jpg",0,0,300,200,BitOR($WS_GROUP,$WS_CLIPSIBLINGS))
$txt1 = GUICtrlCreateLabel("This Program will help you to download automatically the", 10, 30)
$txt2 = GUICtrlCreateLabel("last version of Firefox!",95 , 50)
GUICtrlSetBkColor ( $txt1 , $GUI_BKCOLOR_TRANSPARENT )
GUICtrlSetBkColor ( $txt2 , $GUI_BKCOLOR_TRANSPARENT )
Global $MainButton = GUICtrlCreateButton("Download" , 160, 125, 80 , 35) ; bouton
Global $ButtonStop = GUICtrlCreateButton("Stop", 250, 125, 30, 35)
Global $ButtonQuit = GUICtrlCreateButton("Quit", 250, 125, 30, 35)
Global $grouppercent = GUICtrlCreateGroup("", 10,120, 60,40)
Global $grouppercent = GUICtrlCreateGroup("", 99, 99, 1 ,1)
Global $progressbar1 = GUICtrlCreateProgress (10 , 170 , 280 , 20) ; processbar
If (FileExists(@DesktopDir&"/Install-FireFox.exe") = 1) Then
; $FileSizeIn = FileGetSize (@DesktopDir&"/Install-FireFox.exe")
EndIf
;If ($FileSize = $FileSizeIn) Then
; GUICtrlSetData($MainButton , "Install")
;EndIf
$temp = GUICtrlRead($MainButton)
EndFunc
Func Download_Firefox()
GUICtrlSetData ( $progressbar1 , 0 )
GUICtrlSetState($ButtonQuit, $GUI_HIDE)
GUICtrlSetState($MainButton, $GUI_DISABLE)
GUICtrlSetState($ButtonStop, $GUI_SHOW)
GUICtrlSetState($ButtonStop, $GUI_FOCUS)
$FileSize = InetGetSize ( $Url ) ; ceci calcul la taille de ton fichier qui se trouve sur internet
InetGet( $Url , @DesktopDir&"/Install-FireFox.exe", 1, 1);il sera dl sur le bureau
$txt3 = GUICtrlCreateLabel($percentage & "%", 15, 135)
GUICtrlSetBkColor ( $txt3 , $GUI_BKCOLOR_TRANSPARENT )
While @InetGetActive
;$i = TrayTip("Download...", Int ( ( @InetGetBytesRead * 100 ) / $FileSize )&" %", 10, 16)
GUICtrlSetData ( $progressbar1 , Int ( ( @InetGetBytesRead * 100 ) / $FileSize ) )
;$percentage= (Int(( @InetGetBytesRead * 100 )*100 / $FileSize)/10)
;GUICtrlCreateLabel(Int(( @InetGetBytesRead * 100 )*10 / $FileSize)/10, 60, 90)
If ($percentage <> (Int(( @InetGetBytesRead * 100 ) / $FileSize))) Then
$percentage= (Int(( @InetGetBytesRead * 100 ) / $FileSize))
GUICtrlDelete($txt3)
$txt3 = GUICtrlCreateLabel($percentage & "%", 15, 135)
GUICtrlSetBkColor ( $txt3 , $GUI_BKCOLOR_TRANSPARENT )
EndIf
Sleep(50)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $ButtonStop
FileDelete("Install-Firefox.exe")
ExitLoop
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
Wend
If (Int ((@InetGetBytesRead * 100 ) / $FileSize) = 100) Then
$percentage= (Int(( @InetGetBytesRead * 100 ) / $FileSize))
$txt3 = GUICtrlCreateLabel($percentage & "%", 15, 135)
GUICtrlSetBkColor ( $txt3 , $GUI_BKCOLOR_TRANSPARENT )
$i = TrayTip("Download Done!", "Firefox Download is complete!", 10 , 1)
GUICtrlSetData($MainButton , "Install")
WinSetTitle("Firefox Download Automatization","","Install Firefox");Changement du titre de la barre
Else
$i = TrayTip("Download Aborted!", "Firefox Install has been removed!", 10)
EndIf
$temp = GUICtrlRead($MainButton)
GUICtrlSetState($ButtonQuit, $GUI_SHOW)
GUICtrlSetState($MainButton, $GUI_ENABLE)
GUICtrlSetState($ButtonStop, $GUI_HIDE)
GUICtrlDelete($txt3)
Sleep(1000)
EndFunc
Func Install_Firefox()
GUICtrlSetState($ButtonQuit, $GUI_SHOW)
Run(@DesktopDir&"/Install-FireFox.exe")
WinWaitActive("Installation de Mozilla Firefox")
Sleep(300)
send("{ENTER}")
WinWaitActive("Installation de Mozilla Firefox","Accord de licence")
Sleep(300)
send("{TAB}")
send("{SPACE}")
send("{ENTER}")
WinWaitActive("Installation de Mozilla Firefox","Type d'installation")
Sleep(300)
send("{ENTER}")
WinWaitActive("Installation de Mozilla Firefox","Résumé")
Sleep(300)
send("{ENTER}")
WinWaitActive("Installation de Mozilla Firefox","Fin de l'assistant d'installation de Mozilla Firefox")
Sleep(300)
send("{ENTER}")
Sleep(300)
EndFunc