JaffaDog
3rd September 2003 22:51 UTC
Rename /REBOOTOK Questions
Hello All,
1. How does this achieve it's "rebootok" magic? I've checked the runonce keys and it does not appear to be loading anything there. Where is it scheduling anything to happen on reboot?
2. When I use Rename /rebootok and the target file exists, it will always choose to schedule this for reboot. Even if the target file is not locked. I can precede the rename with a delete, but this seems unnecessary.
TIA,
Jeremy
RDaneel
4th September 2003 03:37 UTC
Check out the SDK docs on MoveFile and MoveFileEx.
Basically, NSIS will try a MoveFile, which *always* fails if the dst exists. Then it trys a MoveFileEx, which *can* work if the dst is present, but only asks for the rename to be scheduled at reboot time... if MoveFileEx isn't present (it showed up in NT4), then an entry is made in "wininit.ini" to handle things.
I have tried (in vain) to get KiCHiK to adjust this logic so that MoveFileEx is the preferred API, only falling back to the older stuff in case of failure, but it hasn't worked. :(
I even tried to imply that I would make the changes myself (well, I *would*) and hand them over. :)
I think he prefers the model of use the oldest APIs if possible, rather than to model things after the newer APIs and fall back to old stuff as required... and since he "owns" this area of the code, that's the way it is (for now).
OTOH, his judgement is usually good, and he does work cheap... :D
kichik
4th September 2003 12:42 UTC
So I'm a sweatshop worker now? :)
JaffaDog
4th September 2003 19:34 UTC
Thanks. The Win SDK spells this out nicely (http://msdn.microsoft.com/library/de...movefileex.asp). I'm using NSIS to put together a patcher, replacing files which may be in use (some are locked by the explorer.exe shell). I'll share the macro I've put together (so far):
!macro UpdateFile FILENAME DESTPATH
DetailPrint ""
; Add this file to the install package
File "files\${FILENAME}"
; Check if this file is present on the target PC
IfFileExists "${DESTPATH}\${FILENAME}" "check_${DESTPATH}\${FILENAME}"
DetailPrint "File does not exist ${DESTPATH}\${FILENAME}"
Goto "update_${DESTPATH}\${FILENAME}"
"check_${DESTPATH}\${FILENAME}:"
; If the file is found on the target PC, check its date to determine if it is the same as the file in the install package
DetailPrint "Checking version of ${DESTPATH}\${FILENAME}"
; Get date of update file from install package (SetOutPath $TEMP)
GetFileTime "$TEMP\${FILENAME}" $R0 $R1
StrCpy $0 "$R0.$R1"
; Get date of existing file on target PC
GetFileTime "${DESTPATH}\${FILENAME}" $R0 $R1
StrCpy $1 "$R0.$R1"
DetailPrint "Comparing dates <$0> <$1>"
StrCmp $0 $1 0 "update_${DESTPATH}\${FILENAME}"
DetailPrint "This file is up to date - No update needed"
goto "done_${DESTPATH}\${FILENAME}"
"update_${DESTPATH}\${FILENAME}:"
; Update the file; delete the old version and replace it with the new version
DetailPrint "Updating this file"
Delete "${DESTPATH}\${FILENAME}"
Rename /REBOOTOK "$TEMP\${FILENAME}" "${DESTPATH}\${FILENAME}"
"done_${DESTPATH}\${FILENAME}:"
!macroend