hogfan Posted September 13, 2011 Share Posted September 13, 2011 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 More sharing options...
willichan Posted September 13, 2011 Share Posted September 13, 2011 $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 My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
hogfan Posted September 13, 2011 Author Share Posted September 13, 2011 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 More sharing options...
KaFu Posted September 13, 2011 Share Posted September 13, 2011 Write progress & status to an ini-file. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
willichan Posted September 13, 2011 Share Posted September 13, 2011 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. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Yashied Posted September 13, 2011 Share Posted September 13, 2011 You can use My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
hogfan Posted September 15, 2011 Author Share Posted September 15, 2011 Thanks. That helps a lot. -hogfan Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now