#include-once ;~ #include ; Create this script in C:\Luigi_auto_update with name AutoUpdate.au3 Func FileLoad($file, $mode = $FO_UTF8_NOBOM) ; @TODO ter certeza da codifição do arquivo Local $hFile = FileOpen($file, $mode) Local $read = FileRead($hFile) FileClose($hFile) Return $read EndFunc ;==>FileLoad Func __ScriptVersion() If @Compiled Then Return FileGetVersion(@ScriptFullPath, $FV_FILEVERSION) Else Local $script = FileLoad(@ScriptFullPath) $script = StringSplit($script, @LF, $STR_NOCOUNT) Local $regex = "(?s)\#AutoIt3Wrapper_Res_Fileversion\=([\d.]+)" Local $arr, $version = 0 For $ii = 0 To UBound($script, $UBOUND_ROWS) - 1 $arr = StringRegExp($script[$ii], $regex, $STR_REGEXPARRAYGLOBALMATCH) If IsArray($arr) Then $version = $arr[0] ExitLoop EndIf Next Return $version EndIf EndFunc ;==>__ScriptVersion Func FileVersionEx($arr1, $arr2) $arr1 = StringRegExp($arr1, "(\d+)+", $STR_REGEXPARRAYGLOBALMATCH) $arr2 = StringRegExp($arr2, "(\d+)+", $STR_REGEXPARRAYGLOBALMATCH) Local $iSize1 = UBound($arr1, $UBOUND_ROWS) - 1 Local $iSize2 = UBound($arr2, $UBOUND_ROWS) - 1 If $iSize1 > $iSize2 Then _ArrayAdd($arr2, 0) If $iSize1 < $iSize2 Then _ArrayAdd($arr1, 0) Local $igual = $iSize1 + 1 Local $num1 = $iSize1 Local $num2 = $iSize1 For $ii = 0 To $iSize1 $igual -= Number($arr1[$ii]) = Number($arr2[$ii]) ? 1 : 0 $num1 -= Number($arr1[$ii]) < Number($arr2[$ii]) ? 1 : 0 $num2 -= Number($arr1[$ii]) > Number($arr2[$ii]) ? 1 : 0 Next Return $igual ? $num1 < $num2 ? 1 : -1 : 0 EndFunc ;==>FileVersionEx Func AutoUpdate_Die($msg) Local $txt Switch $msg Case 1 $txt = "$REMOTE não existe" Case 2 $txt = "impossível criar diretório $DIR" Case 3 $txt = "impossível copiar $REMOTE para $LOCAL" Case 4 $txt = "impossível criar arquivo de $AUTO_UPDATE" Case 5 $txt = "impossível remover $LOCAL após atualização" Case 6 $txt = "impossível atualizar $UPDATE" Case 7 $txt = "impossível remover $UPDATE" EndSwitch MsgBox(0, "Erro", $txt) ConsoleWrite("[" & $msg & "]" & $txt & @LF) Exit EndFunc ;==>AutoUpdate_Die Func AutoUpdate($app, $name, $dir, $repo) Local $local, $local_version Local $remote, $remote_version Local $update, $update_version Local $version If @Compiled Then $local = $dir & "\" & $name & "\" & $app & ".exe" $local_version = FileGetVersion($local) If _Singleton("local_" & $app, 1) = 0 Then Exit $update = $dir & "\" & $name & "\" & $app & "_update.exe" If _Singleton("update_" & $app, 1) = 0 Then Exit $remote = $repo & "\" & $app & ".exe" $remote_version = FileGetVersion($remote) If _Singleton("repo_" & $app, 1) = 0 Then Exit $version = FileVersionEx($remote_version, $local_version) If Not FileExists($remote) Then AutoUpdate_Die(1) If Not FileExists($dir & "\" & $name) And Not DirCreate($dir & "\" & $name) Then AutoUpdate_Die(2) If Not FileExists($local) And Not FileCopy($remote, $local) Then AutoUpdate_Die(3) Switch @ScriptFullPath Case $local If $version = -1 Then If Not FileCopy($remote, $update) Then AutoUpdate_Die(4) ShellExecute($app & "_update.exe", $dir & "\" & $name) Exit EndIf Case $update If Not FileDelete($local) Then AutoUpdate_Die(5) If Not FileCopy($update, $local) Then AutoUpdate_Die(6) ShellExecute($app & ".exe", "", $dir & "\" & $name) Exit Case Else If $version = -1 Then If Not FileDelete($local) Then AutoUpdate_Die(5) If Not FileCopy($remote, $local) Then AutoUpdate_Die(6) EndIf ShellExecute($app & ".exe", "", $dir & "\" & $name) Exit EndSwitch If FileExists($update) And Not FileDelete($update) Then AutoUpdate_Die(7) EndIf EndFunc ;==>AutoUpdate