Jump to content

AutoUpdate Gets Stuck


Recommended Posts

This seems to work quite well for me, however; my test users get stuck in an infinite loop when I update the remote file. I've made sure that the users have access to the remote location.

I can't see the bug and am wondering if anyone else can?

Thanks in advance.

; <header>
; <variable Declarations>

If @Compiled Then _AutoUpdate($CmdLine, "F:\CRUAssist\CRUAssist.exe", "G:\COMMON\PUBLIC FOLDER\Drache\CRUAssist\CRUAssist.exe")

; <Gui>


Func _AutoUpdate($sz_CommandParam, $sz_fileSelf, $sz_fileRemote)
    Local $sz_dateSelf = "", $sz_dateRemote = ""
    Local $funcTemp = "", $t = "", $sz_WinTitleOld = AutoItWinGetTitle()
    AutoItWinSetTitle("AutoUpdate")
    If Not FileExists($sz_fileRemote) Then
        MsgBox(0, "AutoUpdate", "Error#:187" & @LF & "Update file not found.  Program will continue normally")
        SetError(0)
        SetExtended(1)
        AutoItWinSetTitle($sz_WinTitleOld)
        Return 0
    EndIf
    ; check here for command line parameters
    If $sz_CommandParam[0] > 0 Then ; commandline passed!
        If $sz_CommandParam[1] = "-update" Then
            ; 5a) If -update has been called, this is the temp file running.
            ;    Copy the remote to the user's normal local folder, run the updated local, self-delete and exit.
            FileCopy($sz_fileRemote, $sz_fileSelf, 1)
            Run($sz_fileSelf)
            _SelfDelete()
            Exit
        Else
            ; 5b) If any other command line parameter has been called.   Die.  Horribly.
            MsgBox(0, "AutoUpdate", "Bad Command Line Parameter(s)" & @LF & "I only accept -update at this time.")
            Exit
        EndIf
    Else ; no command line passed
        ; 1) Get file date on self.
        $t = FileGetTime($sz_fileSelf, 1)
        If Not @error Then
            $sz_dateSelf = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(1)
            Return -1
        EndIf
        ; 2) Get file date on file in remote location
        $t = FileGetTime($sz_fileRemote, 1)
        If Not @error Then
            $sz_dateRemote = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
        Else
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(2)
            Return -1
        EndIf
        ; 3) Determine if remote is newer
        $t = _DateDiff('s', $sz_dateSelf, $sz_dateRemote)
        If @error Then
            AutoItWinSetTitle($sz_WinTitleOld)
            SetError(3)
            Return -1
        EndIf
        Switch $t
            Case - 3600 To 3600
                ; 4a) If the remote is an hour or less different, don't bother.
                AutoItWinSetTitle($sz_WinTitleOld)
                Return $t
            Case Else
                ; 4b) Otherwise, copy remote into temp folder with random name.
                ;     Execute the temp with command line parameter and terminate.
                $funcTemp = Random(1001, 9999, 1)
                FileCopy($sz_fileRemote, @TempDir & "\AUD-" & $funcTemp & ".exe")
                Run(@ComSpec & " /c " & @TempDir & '"\AUD-' & $funcTemp & '.exe" -update', "", @SW_HIDE)
                Exit
        EndSwitch
    EndIf
EndFunc   ;==>_AutoUpdate
#endregion
#region Function: _SelfDelete
Func _SelfDelete($iDelay = 0)
    ; This is from the help file.
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
             & ':loop' & @CRLF _
             & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
             & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
             & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc   ;==>_SelfDelete
#endregion

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

There is only one loop that I see and that is running the bat file. If that is the problem then you could remove the @SW_HIDE parameter to see if the command prompt is continually looping through the commands. You could also try using the delay parameter so the bat file will execute later after process closure of the exe file which may help.

:)

Link to comment
Share on other sites

Oh, it doesn't get stuck in an internal loop.... The file keeps executing the update routine over and over and over. The program runs, sees it needs to update, goes through the update process flawlessly, and then runs the new updated file as planned, but ... doesn't continue like it should. It gets shunted back into the update loop for some reason, even though the difference between file times are effectively zero.

Might it be the Case -3600 To 3600 that's causing the hiccup, because the negative is a space away? (Blame Tidy on that one)

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Not possible. That section runs the newly updated program before the one in the temp folder deletes itself. Oh snap...that's what's happening. I think I need a hard wait when the program enters the update routine, to check for existence of the update window and then, if it exists, wait for it to close.

If this doesn't work, I'll just put in a msgbox notifying the user that the program's been updated and to restart the darn thing manually.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...