Skip to content
⌘ NSIS Forum Archive

Need some help...

12 posts

Beaver#

Need some help...

I have read through the messages on the boards and tried to re-use some of the posted code but to no avail...

Here is the nature of the problem:

I have created a simple installer that copy's 25 files in to the $INSTDIR. However this is an upgrade... I need a way to move files to $INSTDIR\backup directory *before* they get overwritten by the installer... Can anyone help? (BTW... I am Sooooo Not a programer...)


Beaver
kichik#
CreateDirectory $INSTDIR\backup
CopyFiles /SILENT $INSTDIR\*.* $INSTDIR\backup

That should do the trick.
Beaver#
Thanks...

I will try that. Is there any way to just backup the files that it is going to replace?

Beaver
kichik#
Well, you can if you want check for the existance of every every file and move it. You can make a simple macro out it:

!macro BackupAndExtract FILE ONAME
  IfFileExists "$INSTDIR\${ONAME}" 0 +2
    Rename "$INSTDIR\\${ONAME}" "$INSTDIR\\backup\\${ONAME}"
  File "/oname=${ONAME}" "${FILE}"
!macroend 
To use it:

CreateDirectory $INSTDIR\\backup
!insertmacro BackupAndExtract "C:\\dev\\whateverfile.something" "outputname.st"
# NSIS will only delete this dir if it's empty
RMDir $INSTDIR\\backup 
Beaver#
Boy this humbling....

OK So I am obviously doing something very wrong....


Can you look at the attached and tell me where I am missing the point....

*Waits to be hit by the ClueX4*

Beaver
kichik#
You have read the old post 🙁

I have edited it since you have read it... Please read it again.
Beaver#
Ok saw the new post. Made some changes. But getting a compilation error:

File: "Core.dll"->"outputname.st" 2338816 bytes
File: "Customize.dll"->"outputname.st" 786432 bytes
File: "Editor.dll"->"outputname.st" 2637824 bytes
File: "file.dll"->"outputname.st" 241664 bytes
File: "file.exe"->"outputname.st" 204800 bytes
File: "Generator.dll"->"outputname.st" 327680 bytes
Usage: File ([/a] [/r] filespec [...]|/oname=outfile one_file_only)
Error in macro BackupAndExtract on macroline 3
Error in script "C:\Documents and Settings\mbeaver\My Documents\Development\NSIS\betapatch.nsi" on line 27 -- aborting creation process


Any thoughts? We are getting closer BTW... thanks!

Beaver
kichik#
You need to replcae outputname.st with the output name of your file. For example:

!insertmacro BackupAndExtract "C:\dev\Core.dll" "Core.dll"
Beaver#
OK this works:
!insertmacro BackupAndExtract "C:\dev\Core.dll" "Core.dll"


But if I have a file:
!insertmacro BackupAndExtract "C:\dev\XML\stuff.xsl" "stuff.xsl"

It does not get backed up...


Any thoughts?

Beaver
kichik#
Here is the new version that works with sub folders too:
!macro BackupAndExtract DIR FILE
  SetOutPath "$INSTDIR\\${DIR}"
  IfFileExists "$OUTDIR\\${FILE}" 0 +3
    CreateDirectory "$INSTDIR\\backup\\${DIR}"
    Rename "$OUTDIR\\${FILE}" "$INSTDIR\\backup\\${DIR}\\${FILE}"
  File "<insert app dir here>\\${DIR}\\${FILE}"
!macroend
!insertmacro BackupAndExtract "" "Core.dll"
!insertmacro BackupAndExtract "subfolder" "AnotherDLL.dll" 
Beaver#
That Worked! Thanks you VERY much for your help today. With out it I do not think we could have met our deadline...