Jump to content

How to determine when Dircopy has completed?


hogfan
 Share

Recommended Posts

I have an autoupdater for my app that copies the new version from a UNC path after it closes the running application. Sometimes the app keeps finding a new version when it supposedly already updated. I am thinking that I need to "wait" until my dircopy action has completed copying down the new .exe before launching my appication again (which first action it takes is to check for a new version. What is the best way to pause my script on the Dircopy until it has completely finished copying all the new files down? Thanks for any assistance.

-hogfan

Link to comment
Share on other sites

$result = DirCopy($sourcefile, $targetfile, 1) ;assuming you want to overwrite existing files

Here is how I handle auto-updates for my scripts. You can modify it to handle directories instead of an individual EXE.

include update.au3, and call _CheckForAppUpdate() near the beginning of your script.

update.au3

#include-once
#Include <Misc.au3>
Func _CheckForAppUpdate()
Local $updatepath="\\Your\UNC\goes\here\"
Local $parm=""
Local $yn, $curver, $newver, $i
If StringRight($updatepath,1)<>"\" Then $updatepath &= "\"
$curver=FileGetVersion(@ScriptFullPath)
If @error Then Return
$newver=FileGetVersion($updatepath & @ScriptName)
If @error Then Return
If _VersionCompare($newver,$curver)=1 Then
  ;Update found
  $yn=MsgBox(4,@ScriptName & " Update","A newer vesion of this program is available." & @CRLF & "Upgrade now?")
  If $yn=6 Then
   If $CmdLine[0]>0 Then
    For $i=1 to $CmdLine[0]
     $parm &= " " & StringLower($CmdLine[$i])
    Next
   EndIf
   _StatusUpdate2("Downloading updated applicatoin file")
   ;copy it down, appending an _ to the name (can't overwrite it while running it)
   FileCopy($updatepath & @ScriptName,@ScriptFullPath & "_",9)
   ;drop stub and let it do the work
   FileInstall("stub.exe",@ScriptDir & "\stub.exe",1)
   Run(@ScriptDir & "\stub.exe" & $parm,@ScriptDir)
   ;stub will wait for this script to end, so be sure to exit right away.
   Exit
  EndIf
EndIf
EndFunc

stub.au3

;;;;; Be sure to compile me to an EXE before you compile your main prog, since the update process will drop me using FileInstall().
Const $MainEXE = "myprog.exe"
Dim $parm, $i
ProcessWaitClose($MainEXE)
If FileExists(@ScriptDir & "\" & $MainEXE & "_") Then
;swap files before deleting old one, just be be safe.
FileMove(@ScriptDir & "\" & $MainEXE, @ScriptDir & "\_" & $MainEXE,1)
FileMove(@ScriptDir & "\" & $MainEXE & "_", @ScriptDir & "\" & $MainEXE,1)
FileDelete(@ScriptDir & "\_" & )
EndIf
;Add /stub to the command line parameters, so that the update checking does not have to be re-run
$parm = " /stub"
If $CmdLine[0]>0 Then
For $i=1 to $CmdLine[0]
  $parm &= " " & StringLower($CmdLine[$i])
Next
EndIf
Run(@ScriptDir & "\" & $MainEXE & $parm)
_selfdelete()
Exit
Func _selfdelete
ShellExecute(@ComSpec, "/c ping 0.0.0.1 -n 1 -w 1000 & del " & @ScriptName, @ScriptDir, "open", @SW_HIDE)
EndFunc
Link to comment
Share on other sites

Right, I am doing something similar. However, my app launches and external script to check for updates and each launch. If there is an update, it kills the running process and overwrites all files in my app directory with the ones from the share. So basically all I'm really needing to do at this point is check the status of the DirCopy process to know when it has completed. Thanks for posting the script though. It is very similar to what I am doing.

Link to comment
Share on other sites

So basically all I'm really needing to do at this point is check the status of the DirCopy process to know when it has completed.

Just call it as I showed in the first code block. It will return a 1 if it copied correctly. Code flow will not continue until it is done.

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...