#include #include #include #include #include #include #include ;~ Check the CPU architeture Enum $systemInfo = _WinAPI_GetSystemInfo() If $systemInfo[0] == 9 Then Local $arch = "x64" Else Local $arch = "x86" EndIf ;~ Start everything main() ;~ Main Function Func main() Opt("GUIOnEventMode", 1) Global $mainWindow = GUICreate("Setup Vetor Soluções (" & $arch & ")", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 145, -1, -1) ;~ Special Events GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") Local $labelCNPJ = GUICtrlCreateLabel("Insira o CNPJ da loja", 10, 5, 300, 25) Local $colorCNPJ = GUICtrlSetColor($labelCNPJ, 0xFF0000) Local $setFont = GUICtrlSetFont($labelCNPJ, 13, -1, -1, "sans-serif", 2) Global $inputCNPJ = GUICtrlCreateInput("", 10, 30, 300, 25) Local $limitCNPJ = GUICtrlSetLimit($inputCNPJ, 14, 14) Local $setFont = GUICtrlSetFont($inputCNPJ, 13, -1, -1, "sans-serif", 2) Global $btnInstall = GUICtrlCreateButton("Instalar", 10, 65, 100, 25) Local $setFont = GUICtrlSetFont($btnInstall, 13, -1, -1, "sans-serif", 2) GUICtrlSetOnEvent($btnInstall, "Install") Global $btnCancel = GUICtrlCreateButton("Cancelar", 10, 65, 100, 25) Local $setFont = GUICtrlSetFont($btnCancel, 13, -1, -1, "sans-serif", 2) Local $updateBtnCancel = GUICtrlSetState($btnCancel, $GUI_HIDE) GUICtrlSetOnEvent($btnCancel, "Cancel") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd EndFunc ;~ Install function Func Install() Local $cnpj = GUICtrlRead($inputCNPJ) If $cnpj == "" Then MsgBox($MB_OK, "Informação", "Insira um CNPJ válido", $mainWindow) Else Local $choice = MsgBox($MB_YESNOCANCEL, "Confirmação de CNPJ", $cnpj, $mainWindow) If $choice == 6 Then Local $disableInputCNPJ = GUICtrlSetState($inputCNPJ, $GUI_DISABLE) Local $updateBtnInstall = GUICtrlSetState($btnInstall, $GUI_HIDE) Local $updateBtnCancel = GUICtrlSetState($btnCancel, $GUI_SHOW) Local $dirPath = "Vetor\" ; Instalação Java Local $fileURL = "http://conectacessoria.com.br/vetor/java" & $arch & ".exe" Local $fileName = "java" & $arch & ".exe" Local $fileDesc = "Java JDK 8u73 Windows " & $arch Local $installCmd = ' /s' Local $installFile = webDownloader($mainWindow, $btnInstall, $dirPath, $fileName, $fileDesc, $fileURL) Local $execInstall = installFile($fileURL, $fileName, $fileDesc, $installFile, $installCmd) ; Instalação Postgres $fileURL = "http://conectacessoria.com.br/vetor/postgresql" & $arch & ".exe" $fileName = "postgresql" & $arch & ".exe" $fileDesc = "PostgreSQL 9.5.1-1 Windows " & $arch $installCmd = ' /s' $installFile = webDownloader($mainWindow, $btnInstall, $dirPath, $fileName, $fileDesc, $fileURL) $execInstall = installFile($fileURL, $fileName, $fileDesc, $installFile, $installCmd) Exit Elseif $choice == 2 Then Exit EndIf EndIf ;~ CNPJ Check EndIf EndFunc ;~ Cancel function Func Cancel() If $handleDownload Then InetClose($handleDownload) Exit EndIf EndFunc ;~ Function for the special events (Close, Minimise and Maximize) Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Exit Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE Exit EndSelect EndFunc ;~ Install file function Func installFile($fileURL, $fileName, $fileDesc, $installFile, $installCmd) ;~ ProgressSet(100, "Instalando atualmente: " & @CRLF & $name) $exitCode = RunWait($installFile & $installCmd) ;~ If $exitCode = 0 Then ProgressSet(100, "Instalação completa") ;~ If $exitCode <> 0 Then ProgressSet(0, "A instalação falhou. #" & $exitCode) Sleep(1500) FileDelete($installFile) EndFunc ;~ webDownloader function Func webDownloader($mainWindow, $btnCancel, $dirPath, $fileName, $fileDesc, $fileURL) If Not FileExists($dirPath) Then DirCreate($dirPath) Local $progressBar = GUICtrlCreateProgress(10, 95, 300, 18, $PBS_SMOOTHREVERSE, $WS_EX_WINDOWEDGE) Local $targetPath = $dirPath & "\" & $fileName Local $fileSize = InetGetSize($fileURL) Global $handleDownload = InetGet($fileURL, $targetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND) Local $downloadTotalBytes = Round($fileSize / 1048576, 2) Local $labelDownload = GUICtrlCreateLabel("Baixando: " & $fileDesc, 120, 65, 180, 10) Local $labelProgress = GUICtrlCreateLabel("0 Mb de " & $downloadTotalBytes & " Mb", 120, 75, 180, 10) Local $setFontDownload = GUICtrlSetFont($labelDownload, 7, -1, -1, "sans-serif", 2) Local $colorDownload = GUICtrlSetColor($labelDownload, 0x0000FF) Local $setFontDownload = GUICtrlSetFont($labelProgress, 7, -1, -1, "sans-serif", 2) Local $colorDownload = GUICtrlSetColor($labelProgress, 0xFF0000) While InetGetInfo($handleDownload, $INET_DOWNLOADCOMPLETE) == False Local $downloadPercent = Round(InetGetInfo($handleDownload, $INET_DOWNLOADREAD) * 100 / $fileSize, 0) Local $downloadBytes = Round(InetGetInfo($handleDownload, $INET_DOWNLOADREAD) / 1048576, 2) If IsNumber($downloadBytes) And $downloadBytes >= 0 Then $updateProgress = GUICtrlSetData($progressBar, $downloadPercent) $updateLabelProgress = GUICtrlSetData($labelProgress, $downloadBytes & " Mb de " & $downloadTotalBytes & " Mb") EndIf If InetGetInfo($handleDownload, $INET_DOWNLOADERROR) Then ExitLoop EndIf Sleep(500) WEnd If InetGetInfo($handleDownload, $INET_DOWNLOADSUCCESS) Then $updateProgress = GUICtrlSetData($progressBar, 100) $updateLabelProgress = GUICtrlSetData($labelProgress, "Download completo") EndIf EndFunc