UDF de atualização automática

y programas personales para otros como tu, puede que te corrijan ;)
Splash
Mensajes: 18
Registrado: 10 Feb 2010, 21:32
Ubicación: Brasil, Porto Alegre
Contactar:

UDF de atualização automática

Mensaje por Splash »

Código: Seleccionar todo

#cs
    Author: Igor "Splash" Cemim
    Profile: http://www.autoitscript.com/forum/index.php?showuser=46021
    Email: igor dot cemim at yahoo dot com dot br

    Thanks to _SelfDelete author (???). :)
#ce

;$scriptVersion = Versão do seu script/programa.
;$iniUrl = URL de onde será baixado o arquivo de configuração.
;[Opcional]
;$fileName = Nome do arquivo atualizado após o download.
;$iniName = Nome do arquivo de configuração após o donwload.
Func CheckUpdate($scriptVersion, $iniUrl, $fileName = "update.exe", $iniName = "update.ini")
    InetGet($iniUrl, $iniName, 1)
    $lastestVersion = IniRead($iniName, "Update", "lastestVersion", 0)
    $updateUrl = IniRead($iniName, "Update", "updateUrl", 0)
    If ($lastestVersion > $scriptVersion) Then
        InetGet($updateUrl, $fileName, 1, 0)
        FileDelete(@ScriptDir & "\" & $iniName)
        _DoUpdate(@ScriptDir & "\" & $fileName)
    EndIf
EndFunc   ;==>CheckUpdate

;$newFile = Arquivo atualizado.
;$iDelay = Tempo de espera entre a execução dos comandos.
Func _DoUpdate($newFile, $iDelay = 4)
    Local $sCmdFile
    FileDelete(@TempDir & "\doIt.bat")
    $sCmdFile = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & 'rename "' & $newFile & '" "' & @ScriptName & '" > nul' & @CRLF _
             & 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _
             & '"' & @ScriptFullPath & '" > nul ' & @CRLF _
             & 'del "' & @TempDir & '\doIt.bat" > nul'
    FileWrite(@TempDir & "\doIt.bat", $sCmdFile)
    Run(@TempDir & "\doIt.bat", @TempDir, @SW_HIDE)
    Exit
EndFunc   ;==>_DoUpdate
Exemplo de arquivo de configuração:

Código: Seleccionar todo

[Update]
lastestVersion=2
UpdateUrl=http://www.mysite.com/update/newfile.exe
Se tiverem alguma dúvida perguntem.

Idade/Age: 16
Web: http://meadiciona.com/cemim/
Responder