Hi elitepvpers, ich release hier meine Update Funktion bzw. Update Programm für (AutoIt) Programme.
Code:
#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer%
#AutoIt3Wrapper_Res_Field=Compile Date|%date% %time%
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs 0 /cn 0 /cf 0 /cv 0 /sf 1 /sv 1
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Crypt.au3>
; #FUNCTION# ====================================================================================================================
; Name ..........: _EXE_Update
; Description ...: Checks the MD5 of an EXE File/AutoIT Script and updates the EXE.
; Syntax ........: _EXE_Update($sEXEFullPath, $sNewEXEMD5, $sNewEXEUrl)
; Parameters ....: $sEXEFullPath - A string value.
; $sNewEXEMD5 - A string value.
; $sNewEXEUrl - A string value.
; Return values .: None
; AutoIt Version.: 3.3.8.1+
; Author ........: Achat (www.elitepvpers.com)
; Modified ......:
; Remarks .......: Just compile that script and run it from your main script (FileInstall & Run/ShellExecute).
; Related .......: Requires #include <Crypt.au3> [Updater Script]
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
#cs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Example -- Main Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FileInstall('C:\FileInstall\_EXE_Update.exe', @ScriptDir & '\_EXE_Update.exe',1)
ShellExecute(@ScriptDir & '\_EXE_Update.exe', @ScriptFullPath &'|'&'1e996be9f8d39c37c1ba2bb54c30976f'&'|'&'http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe')
Exit
[IMG]http://i.epvpimg.com/SfN8g.png[/IMG]
#ce ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Example -- Main Script~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#region Updater
Local $a1DsParameters = StringSplit($CmdLineRaw, '|', 2)
If UBound($a1DsParameters, 1) <> 3 Then Exit
If FileExists($a1DsParameters[0]) = 0 Then Exit
_EXE_Update($a1DsParameters[0], $a1DsParameters[1], $a1DsParameters[2])
Func _EXE_Update($sEXEFullPath, $sNewEXEMD5, $sNewEXEUrl)
$sNewEXEMD5 = StringUpper($sNewEXEMD5)
ToolTip('#Update---> Update in progress... please wait.' & @CRLF & _
'#Update---> Path to local EXE: ' & $sEXEFullPath & @CRLF & _
'#Update---> ' & StringTrimLeft(_Crypt_HashData($sEXEFullPath, $CALG_MD5), 2) & ' <--- MD5 Hash of the local EXE' & @CRLF & _
'#Update---> ' & $sNewEXEMD5 & ' <--- MD5 Hash of the remote EXE ' & @CRLF & _
'#Update---> Url to remote EXE: ' & $sNewEXEUrl, 0, 0, '#--->Update<---#')
If StringTrimLeft(_Crypt_HashFile($sEXEFullPath, $CALG_MD5), 2) <> $sNewEXEMD5 Then
InetGet($sNewEXEUrl, @TempDir & '\update.tmp', 1)
Else
Exit
EndIf
If StringTrimLeft(_Crypt_HashFile(@TempDir & '\update.tmp', $CALG_MD5), 2) = $sNewEXEMD5 Then
$iReturn = FileMove(@TempDir & '\update.tmp', $sEXEFullPath, 1)
If $iReturn <> 1 Then
Exit
EndIf
FileDelete(@TempDir & '\update.tmp')
ToolTip('#Update---> Update successful', 0, 0)
ShellExecute($sEXEFullPath)
Else
FileDelete(@TempDir & '\update.tmp')
ToolTip('#Update---> Update failed. MD5 hash mismatch.', 0, 0)
EndIf
Sleep(5000)
ToolTip('')
EndFunc ;==>_EXE_Update
#endregion Updater
Verwendung:
Ihr müsst das Script einfach kompilieren. Dann erhaltet ihr eine Updater.exe. Diese installiert ihr dann z.B. mit FileInstall in euer Hauptprogramm (es muss nicht mit AutoIt geschrieben sein).
Dann braucht ihr noch eine Datei im Internet, in der die aktuelle Version eures Programms steht, sowie MD5 einer neuen Version und die URL zur neuen Version. So prüft ihr dann in eurem Hauptprogramm, ob die aktuelle Version der Version in der Datei entspricht. Wenn das nicht der Fall ist, führt ihr einfach die Updater.exe mit Parametern aus:
Code:
@ScriptFullPath&'|'&'MD5Hash der neuen Version'&'|'&'Link zur neuen Programmversion'
Und schließt danach euer Hauptprogramm.
Wenn das Update abgeschlossen ist, wird euer Programm wieder gestartet.
Im Script oben findet ihr auch ein Beispiel.
Feedback ist erwünscht :)
english:
Function / program to update programs.
Read comments in .au3 file...
If you have any questions, feel free to ask me.
Feedback is appreciated!