Code : Tout sélectionner
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Images\ours.ico
#AutoIt3Wrapper_Outfile=script_reception_sources_web2_ftp_test.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=Téléchargement CD-WEB2
#AutoIt3Wrapper_Res_Description=Téléchargement CD-WEB2
#AutoIt3Wrapper_Res_Fileversion=0.0.1.1
#AutoIt3Wrapper_Res_LegalCopyright=***
#AutoIt3Wrapper_Res_Language=1036
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Res_Compatibility=Vista,Windows7
#AutoIt3Wrapper_Res_File_Add=Images\logo.jpg, rt_rcdata, logo
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <resources.au3>
;mode événement activé
Opt("GUIOnEventMode", 1)
;variable permettant d'interrompre une fonction
Global $stop = 0
Global $chemin_complet = "" ; ne pas déclarer une variable en Global dans une fonction
; nom du dossier compressé CD-WEB2
Global $cdweb2 = "CD-WEB2" ; cette variable ne sert à rien
;variable permettant de connaître la taille du dossier compressé
Global $SizeFile = InetGetSize("ftp://nomutilisateur:Nanook@ftp.***-********.fr/CD-WEB2.zip")
;Fonction qui permet de fermer la fenêtre quand on clique sur "Quitter"
Func quitter()
Exit
EndFunc
;Test du contrôle graphique
Func _Ischecked($control)
Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc
;Fonction pour faire fonctionner la barre de progression par rapport au dossier compressé récupéré sur le FTP
Func _SetProgress($ctrlId,$SizeFile,$SizeDownload)
GUICtrlSetData($ctrlId,Int(($sizeDownload/$SizeFile)*100))
EndFunc
;interface graphique de la fenêtre Windows
Global $Gestion = GUICreate("Téléchargement du CD-WEB2", 350, 410, 500, 300)
GUISetBkColor(0x94CEDD)
Global $Group1 = GUICtrlCreateGroup("Cochez la case puis cliquez sur Télécharger", 24, 152, 129, 135)
Global $fichier1 = GUICtrlCreateCheckbox("CD-WEB2.zip", 25, 226, 100, 17)
GUICtrlSetOnEvent( -1,"checkbox")
Global $telecharger_1 = GUICtrlCreateButton("Télécharger", 160, 194, 75, 25)
GuiCtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetOnEvent( -1,"telechargeProgress")
Global $quitter= GUICtrlCreateButton("Quitter", 160, 232, 75, 25)
GUICtrlSetOnEvent( -1,"quitter")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $progressbar = GUICtrlCreateProgress(18, 306, 220, 20)
GUISetState(@SW_SHOW)
;Fonction qui intercepte les messagesWindows
Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $lParam
Local $test = BitAND($wParam, 0xFFF0)
If $test = 0xF060 Then ; <== $SC_CLOSE = 0xF060 (clic sur la croix)
$stop = 1
Exit
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc
;Fonction qui intercepte les messagesWindows
Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $lParam
Switch BitAND($wParam, 0x0000FFFF)
Case $telecharger_1 ;<== clic sur le bouton "Annuler"
If GuiCtrlRead($progressbar)<>0 Then $stop = 1
EndSwitch
Return 'GUI_RUNDEFMSG'
EndFunc
;Variables Windows qui enregistrent une fonction définie par l'utilisateur pour un message Windows connue
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")
; Icône AFI
GUISetIcon(@ScriptDir & "\Images\ours.ico", -1)
; Couleur arrière plan de la fenêtre Windows
GUISetBkColor(0x94CEDD)
; zones d'info/texte + image concernant ***
$Pic1 = GUICtrlCreatePic("", 24, 16, 217, 100)
_ResourceSetImageToCtrl($Pic1, "logo")
$Label2 = GUICtrlCreateLabel("*****", 24, 350, 160, 17)
$Label3 = GUICtrlCreateLabel("Téléphone : ** ** ** ** **", 200, 350, 136, 17)
$Label4 = GUICtrlCreateLabel("Mail : ******@***-**.fr", 24, 370, 108, 17)
$Label5 = GUICtrlCreateLabel("Non administrateur", 200, 370, 150, 20)
If IsAdmin() == 1 Then
GUICtrlSetData($Label5, "Administrateur du poste")
EndIf
;boucle qui permet au programme de rester affiché
While 1
sleep(10)
WEnd
; Menu dropdown & sous menus
;$MenuItem2 = GUICtrlCreateMenu("?")
;$MenuItem3 = GUICtrlCreateMenuItem("&Aide" & @TAB & "F1", $MenuItem2)
;$MenuItem4 = GUICtrlCreateMenuItem("À &propos", $MenuItem2)
;Système permettant de prévenir l'utilisateur si il a assez d'espace disque disponible ou pas sur son lecteur
;de disque par défaut pour télécharger le dossier compressé sur le FTP
Func checkbox()
$chemin_complet = FileSaveDialog("Choisir un emplacement :", @HomeDrive, "Fichiers d'archivage (*.zip)", 16, "CD-WEB2.zip")
If @error Then Exit ;<<<<<<<<<<
FileChangeDir(@ScriptDir)
If _Ischecked(@GUI_CtrlId) then
$drive = StringLeft($chemin_complet, 3) ;<= retourne le lecteur, ex. D:\
If not _IsSpaceOK($SizeFile, $drive) Then
GuiCtrlSetState($telecharger_1, $GUI_DISABLE)
MsgBox (1024, "", "L'espace disque est insuffisant !")
Else
GuiCtrlSetState($telecharger_1, $GUI_ENABLE)
MsgBox (1024, "", "Vous assez d'espace disque disponible !")
$stop = 0
EndIf
EndIf
EndFunc
Func _IsSpaceOK($Size, $disk)
Local $iFreeSpace = Round(DriveSpaceFree($disk)*1024*1024)
If $iFreeSpace < $Size Then
Return 0
Else
Return 1
EndIf
EndFunc
;Fonction de téléchargement du dossier compressé sur le site ftp "ftp.***-********.fr" + fenêtres d'affichage
;indiquant si le téléchargement est terminé ou interrompu selon le choix de l'utilisateur
Func telechargeProgress()
If _Ischecked($fichier1) and $stop = 0 Then
If StringRight($chemin_complet, 4) <> ".zip" Then $chemin_complet &= ".zip"
Local $hDownload = InetGet("ftp://nomutilisateur:motdepasse@ftp.***-********.fr/CD-WEB2.zip", $chemin_complet, 1, 1)
GuiCtrlSetData($telecharger_1, "Annuler")
GuiCtrlSetState($quitter, $GUI_DISABLE)
Do
If $stop = 1 Then
InetClose($hDownload)
Exitloop
EndIf
$info = InetGetInfo($hDownload)
_SetProgress($progressbar, $info[1], $info[0])
Sleep(100)
Until $info[2]
If $stop = 1 Then
MsgBox(64, "CD-WEB2", "Téléchargement interrompu")
GuiCtrlSetData($telecharger_1, "Télécharger")
GuiCtrlSetData($progressbar, 0)
Exit
Else
MsgBox(64, "CD-WEB2", "Téléchargement terminé")
EndIf
EndIf
GuiCtrlSetState($quitter, $GUI_ENABLE)
;codes pour décompresser le dossier
global $path7z = @ScriptDir & "\7-Zip\" & @OSArch & "\7z.exe"
if FileExists ($path7z) Then
;commande complète pour l'extraction du dossier compressé
global $command = $path7z & " x -o" & '"' & $chemin_complet & '"' ;<<<<<<<<<<<<<
;lancement de l'extraction du CD-AFI-WEB2
runwait($command)
Else
Exit
EndIf
;Lancement de "Install.exe" du contenu du dossier "CD-WEB2"
$dossier = StringRegExpReplace($chemin_complet, '(.+)\\[^\\]+', "$1") ; dossier où est le zip
msgbox(0,"", $dossier & "\CD-WEB2\Install.exe")
ShellExecute ($dossier & "\CD-WEB2\Install.exe") ; à vérifier le chemin \CD-WEB2\
EndFunc
#cs
;Gestion des boucles
While 1
$nMsg = GUIGetMsg() ; <== sans objet en mode onevent
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
#ce
;Fin du script