Archive: how to backup files during installation ?


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


http://nsis.sourceforge.net/archive/...php?pageid=314


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

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

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