Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

updater script

$
0
0
Hello World.

I have a script that people throughout the company use called Freeze. Whenever I put out a new version, I put it along with other files into a self-extracting executable (winzip file). Upon startup, Freeze looks at a network share to see if there's an update available, if there is it sends the following command to another script (updater.exe) which is included in the same script directory. The problem I'm coming across is that users are saying that sometimes the Freeze.exe file is missing after an update. I've included some comments that hopefully explain the process more.

Any help is appreciated!

$update_file (includes full path to the new version of the script)
RunWait(@ScriptDir & '\updater.exe -auto_update ' & '"' & $update_file & '"')
Here's updater.exe
 
AutoIt         
#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=images\db.ico #AutoIt3Wrapper_Outfile=updater.exe #AutoIt3Wrapper_Run_Tidy=y #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Misc.au3> Global $msg_normal = 262144, $msg_error = 262160 Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 1) $exititem = TrayCreateItem("Exit") TrayItemSetOnEvent($exititem, "_Exit") TraySetState(1) ;Here's where it processes the command line or also supports self updating. If $CmdLine[0] > 0 Then For $i = 1 To $CmdLine[0] Select Case $CmdLine[$i] = "-auto_update" $remote_file = $CmdLine[$i + 1] UpdateScript($remote_file) EndSelect Next Else $remote_file = Find_RemoteFile() UpdateScript($remote_file) EndIf Func UpdateScript($remote_file) If Not FileExists($remote_file) Then MsgBox($msg_error, "Freeze", "Unable to access Freeze install file: " & $remote_file & ".") Exit EndIf ;These are running processes of Freeze - I terminate them before updating. Local $processes[2] $processes[0] = "Freeze.exe" $processes[1] = "Connect.exe" $exit = True For $x = 0 To UBound($processes) - 1 $close = Kill_Process($processes[$x]) If $close <> 1 Then $exit = False Next ;Extracting across the network was timing out so I copy the self-extractable update locally then extract to @tempdir then copy the files to the pre-existing script directory for Freeze If $exit = True Then $copy = FileCopy($remote_file, @TempDir & "\Freeze.exe", 1) If $copy = 0 Then $copy = FileCopy($remote_file, @TempDir & "\Freeze.exe", 1) If $copy = 0 Then MsgBox($msg_error, "Freeze", "Update failed to download." & @CRLF & _ @CRLF & _ $remote_file) _Exit() EndIf EndIf RunWait(@TempDir & "\Freeze.exe /auto " & @TempDir) Copy_Files() If @error Then MsgBox($msg_error, "Freeze", "Update failed to extract files.") _Exit() EndIf ;Delete the self-extracting executable and extracted directory FileDelete(@TempDir & "\Freeze.exe") DirRemove(@TempDir & "\Freeze", 1) Else MsgBox($msg_error, "Freeze", "Unable to exit Freeze." & @CRLF & _ "" & @CRLF & _ "Update canceled.") EndIf EndFunc ;==>UpdateScript Func Copy_Files() $search = FileFindFirstFile(@TempDir & "\Freeze\*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $copy = FileCopy(@TempDir & "\Freeze\" & $file, @ScriptDir, 1) If $copy = 0 Then Kill_Process($file) $copy = FileCopy(@TempDir & "\Freeze\" & $file, @ScriptDir, 1) If $copy = 0 Then MsgBox($msg_error, "Freeze", "Unable to replace file: " & $file & @CRLF & _ @CRLF & _ "Update canceled.") _Exit() EndIf EndIf WEnd Else SetError(1) EndIf EndFunc ;==>Copy_Files Func Find_RemoteFile() $update_initiated = False $mirror_dir = RegRead("HKLM\Software\Freeze", "MirrorDir") If @error Then $mirror_dir = "\\server101\apps\mapp\Freeze\zdo" EndIf If Not FileExists($mirror_dir) Then MsgBox($msg_error, "Freeze", $mirror_dir & " is not accessible.") Exit EndIf $remote_prod_search = FileFindFirstFile($mirror_dir & "\Freeze*.exe") If $remote_prod_search = -1 Then MsgBox($msg_error, "Freeze", "Freeze install file cannot be found in " & $mirror_dir & ".") Exit EndIf While 1 $file = FileFindNextFile($remote_prod_search) If @error Then ExitLoop $recent_prod_file = StringTrimRight($file, 4) WEnd $remote_prod_version = StringReplace($recent_prod_file, "Freeze v", "") $local_prod_version = FileGetVersion(@ScriptDir & "\Freeze.exe") $compare_prod_versions = _VersionCompare($local_prod_version, $remote_prod_version) If @error Or $compare_prod_versions = -1 Then $update_initiated = True $update_file = $mirror_dir & "\" & $recent_prod_file & ".exe" Return $update_file EndIf $local_test_version = FileGetVersion(@ScriptDir & "\Freeze.exe", "FileDescription") If $local_test_version <> "" Then $local_test_version = StringReplace(StringRight($local_test_version, 4), ")", "") $remote_test_search = FileFindFirstFile($mirror_dir & "\-=test=-\Freeze*.exe") If $remote_test_search = -1 Then MsgBox($msg_error, "Freeze", "Test version of Freeze cannot be found in " & $mirror_dir & ".") Exit EndIf While 1 $file = FileFindNextFile($remote_test_search) If @error Then ExitLoop $remote_test_file = StringTrimRight($file, 4) WEnd $remote_test_version = StringReplace(StringRight($remote_test_file, 4), ")", "") $compare_test_versions = _VersionCompare($local_test_version, $remote_test_version) If @error Or $compare_test_versions = -1 Then $update_initiated = True $update_file = $mirror_dir & "\-=test=-\" & $remote_test_file & ".exe" Return $update_file EndIf EndIf If $update_initiated = False Then MsgBox($msg_normal, "Freeze", "You have the newest version.") Exit EndIf EndFunc ;==>Find_RemoteFile Func Kill_Process($process_name) For $x = 1 To 10 If ProcessExists($process_name) Then ProcessClose($process_name) Else ExitLoop EndIf Next $close = 1 If ProcessExists($process_name) Then $close = ProcessWaitClose($process_name, 3) EndIf Return $close EndFunc ;==>Kill_Process Func _Exit() Exit EndFunc ;==>_Exit

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>