jerder
15th June 2005 18:47 UTC
how to backup files during installation ?
Hi everybody,
I am writing an installer with NSIS the first time, and am encountering the problem of backing up files during install before they are replaced with new files by the installer.
The installer uses the file command to install complete
directory trees similiar to :
File /r "C:\Installer\dir1"
But I found no possibility to specify any kind of backup of files.
Any help welcome !
-jerder
jerder
16th June 2005 17:53 UTC
Originally posted by Mæster
http://nsis.sourceforge.net/archive/...php?pageid=314
this will work. But does it mean I can't
use the /r switch of the File command then ?
-jerder
Mæster
16th June 2005 22:45 UTC
But does it mean I can't
use the /r switch of the File command then ?
Yes, I think you could not use the /r switch. If you would like to backup all files of a specific folder you have to make your own macro/function to do that. Maybe something like the following (untested!) ...
!macro BackupDir SOURCE_DIR BACKUP_TO
; SOURCE_DIR = Source Directory
; BACKUP_TO = Backup Directory
; INSTDIR = Destination Directory
; $R0 = handle from the search function
; $R1 = current file
FindFirst $R0 $R1 "${SOURCE_DIR}\*.*"
strcmp $R1 "" EndBackup ;Source Dir does not exist
loop:
Strcmp $R1 "" EndBackup
StrCmp $R1 "." next
StrCmp $R1 ".." next
IfFileExists "${SOURCE_DIR}\$R1\*.*" next
; Backup File
!insertmacro BackupFile $INSTDIR $R1 ${BACKUP_TO}
; install new version
File "${SOURCE_DIR}\$R1"
next:
FindNext $R0 $R1
Goto loop
EndBackup:
FindClose $R0
!macroend
Example:
Section "Install Files"
!insertmacro BackupDir "C:\MyProject\Install Source" "$INSTDIR\backup"
SectionEnd
Afrow UK
17th June 2005 17:43 UTC
Mæster you're confusing run-time with compile-time.
The loop will be executed on run-time but you need to compress the files on compile-time.
This page shows how you can invoke NSIS run-time commands at compile-time by creating a seperate installer to execute.
You can use this to recursively loop through a folder:
http://nsis.sourceforge.net/archive/...ances=0,11,211
-Stu
Mæster
17th June 2005 21:45 UTC
Mæster you're confusing run-time with compile-time.
Argh - you are right, what a stupid mistake.
Another attemt to include many files/directories whithout naming each file in the scrip is to include them as an already compiled archive (zip) and to put that archive at runtime to a temp folder. You could use the zip-plugin to extract them in the temp folder. Now you have a source and a destination folder and you could use the loop (the code above has to be fixed a bit to do that) to "backup-install" them.