PASSO A — Includes no início do fonte principal: #include #include PASSO B — Constantes junto às constantes globais: Global Const $APP_VERSION = "2.1.0" Global Const $UPDATE_BASE_URL = "https://monitor.rinfo.com.br/download/" Global Const $UPDATE_MANIFEST_URL = $UPDATE_BASE_URL & "version.json" Global Const $APP_DIR = @LocalAppDataDir & "\RInfoMonitor" Global Const $APP_EXE = $APP_DIR & "\RInfoMonitor.exe" Global Const $UPDATER_EXE = $APP_DIR & "\RInfoUpdater.exe" PASSO C — Chamada no início do programa: Coloque depois das constantes e ANTES de _InicializarBiblioteca() / _Conectar(): If _VerificarAtualizacao() Then Exit PASSO D — Acrescente as funções abaixo ao final do fonte: Func _VerificarAtualizacao() DirCreate($APP_DIR) Local $sManifestTmp = $APP_DIR & "\version.tmp" If Not _BaixarUpdate($UPDATE_MANIFEST_URL, $sManifestTmp) Then Return False Local $sJson = FileRead($sManifestTmp) Local $sVersao = _JsonValorUpdate($sJson, "version") Local $sUrl = _JsonValorUpdate($sJson, "download") Local $sHash = _JsonValorUpdate($sJson, "sha256") If $sVersao = "" Or $sUrl = "" Or StringLen($sHash) <> 64 Then Return False If _CompararVersoes($sVersao, $APP_VERSION) <= 0 Then Return False Local $sNovo = $APP_DIR & "\RInfoMonitor.new.exe" If Not _BaixarUpdate($sUrl, $sNovo) Then Return False If Not _ValidarHashUpdate($sNovo, $sHash) Then FileDelete($sNovo) Return False EndIf If Not FileExists($UPDATER_EXE) Then FileDelete($sNovo) Return False EndIf ; Updater aguarda o PID atual terminar, faz backup, troca o EXE e reinicia. ShellExecute($UPDATER_EXE, @AutoItPID & ' "' & $sNovo & '" "' & $APP_EXE & '"') If @error Then FileDelete($sNovo) Return False EndIf Return True EndFunc Func _BaixarUpdate($sUrl, $sDestino) FileDelete($sDestino) Local $iBytes = InetGet($sUrl, $sDestino, 1, 0) If @error Or $iBytes <= 0 Or Not FileExists($sDestino) Then Return False Return True EndFunc Func _JsonValorUpdate($sJson, $sChave) Local $a = StringRegExp($sJson, '"' & $sChave & '"\s*:\s*"([^"]*)"', 1) If @error Or Not IsArray($a) Then Return "" Return $a[0] EndFunc Func _ValidarHashUpdate($sArquivo, $sHashEsperado) If Not _Crypt_Startup() Then Return False Local $bHash = _Crypt_HashFile($sArquivo, $CALG_SHA_256) Local $iErro = @error _Crypt_Shutdown() If $iErro Then Return False Return StringLower(Hex($bHash)) = StringLower($sHashEsperado) EndFunc Func _CompararVersoes($sRemota, $sLocal) Local $a = StringSplit($sRemota, ".", 2) Local $b = StringSplit($sLocal, ".", 2) For $i = 0 To 2 Local $nA = 0, $nB = 0 If $i < UBound($a) Then $nA = Number($a[$i]) If $i < UBound($b) Then $nB = Number($b[$i]) If $nA > $nB Then Return 1 If $nA < $nB Then Return -1 Next Return 0 EndFunc