Archiving $INSTDIR using rename
4.9.1.6 Rename
[/REBOOTOK] source_file dest_file
Rename source_file to dest_file. You can use it to move a file from anywhere on the system to anywhere else and you can move a directory to somewhere else on the same drive. The destination file must not exist or the move will fail (unless you are using /REBOOTOK). If /REBOOTOK is specified, and the file cannot be moved (if, for example, the destination exists), then the file is moved when the system reboots. If the file will be moved on a reboot, the reboot flag will be set. The error flag is set if the file cannot be renamed (and /REBOOTOK is not used) or if the source file does not exist.
Ok, I am trying to understand what this means. Firstly, do I need /REBOOTOK or not? I understand the purpose of the flag, but the name of the flag, and the text in the help is a bit confusing to me.
I have seen several other posts in regard to renaming a directory, but I can't for the life of me figure out why I am having trouble renaming files or directories. I just want to move the whole directory prior to putting files there.
So, I have logging as well, so I turn logging on in my $INSTDIR, then when I get to the archive part, I turn logging off, attempt to move the log into $TEMP, then move the entire $INSTDIR to an archive directory. It took me a while to figure out what the "error flag" is, BTW. It is all over the documentation, and usually it isn't shown in the examples. It would be nice to add a link to the IfErrors section (I know, a ton of busy work), for those of us who don't have time to read the entire manual cover to cover.
When you rename a directory, should the destination be there, or not? I am guessing not, but no matter what I try to do, it fails.
I am guessing I am being screwed by the logger, as it fails to rename the install.log file to the $TEMP directory successfully.
Any help would be welcome.
Thanks,
-Kevin
SetOutPath "$INSTDIR\.."
IfFileExists "$INSTDIR\${mcexec}" "" skipArchive
DetailPrint "Archiving old files"
;GetRoot "$INSTDIR" $R0
StrCpy $ArchivePath "$ArchiveRoot\${packagename}_Archive_$2$1$0_$4$5"
MessageBox MB_OK "Archive path is $ArchivePath"
;CreateDirectory "c:\$archive_$2$1$0_$4$5"
;Note that when using rename, the new path must not exist...
;but we need to create the root if it is missing...
CreateDirectory "$ArchiveRoot"
;CreateDirectory "$ArchivePath"
DetailPrint "About to move $INSTDIR to $ArchivePath"
DetailPrint "About to move $INSTDIR\install.log to $TEMP\install.log"
;turn logger off and move the log file to the side...
!insertmacro Logger off
ClearErrors
LogSet off
IfErrors 0 +2
MessageBox MB_OK "Turning the log off failed";
MessageBox MB_OK "Just turned off the logger";
ClearErrors
Rename "$INSTDIR\install.log" "$TEMP\install.log"
IfErrors 0 +2
MessageBox MB_OK "Rename $INSTDIR\install.log to $TEMP\install.log failed";
;CopyFiles "$INSTDIR\*.*" "$ArchivePath"
ClearErrors
Rename "$INSTDIR" "$ArchivePath"
IfErrors 0 +2
MessageBox MB_OK "Rename $INSTDIR to $ArchivePath failed";
;put logfile back and turn logger back on
MessageBox MB_OK "Rename complete ($0), about to copy the log back";
ClearErrors
Rename "$TEMP\install.log" "$INSTDIR\install.log"
IfErrors 0 +2
MessageBox MB_OK "Rename $TEMP\install.log to $INSTDIR\install.log failed";
!insertmacro Logger on
MessageBox MB_OK "Just turned on the logger (the log rename returned $0)";
DetailPrint "Archive complete"
skipArchive: