Sign in to follow this  
Followers 0
gcue

updater script

3 posts in this topic

#1 ·  Posted (edited)

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

 

#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
Edited by gcue

Share this post


Link to post
Share on other sites



Looking at it quickly, and without being able to test it in your environment, I'd ask a couple of questions:

1. Have you added ConsoleWrite to any of your functions to determine where in your script the operation is failing?

2. Is it possible that your SFX solution is the issue? Could it possibly be that the files are not extracted?

    - For this case I would check to see if the files exist in your Copy_Files function first (possibly checking if the dir is not empty)

Assuming that the SFX extraction is the issue, I would recommend that you use the _Zip.au3 by wraithdu and use normal zip files. These zip functions are very stable and consistent.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi 0xdefea7 =)

1. ConsoleWrite - I have used it but don't see where it can be failing. What makes it difficult is that the issue is not consistent.

2. I suppose that can be a possibility - files aren't extracting. When it happens though, it's usually just 1 or 2 people that mention the issue and 30 or so successfully update from the same file.

Before I try using the zip udf - I wanted to make sure it wasn't my logic first.

Edited by gcue

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0