- NSIS Discussion
- Need some help...
Archive: Need some help...
Beaver
13th November 2002 18:05 UTC
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
13th November 2002 18:11 UTC
CreateDirectory $INSTDIR\backup
CopyFiles /SILENT $INSTDIR\*.* $INSTDIR\backup
That should do the trick.
Beaver
13th November 2002 18:20 UTC
Thanks...
  I will try that. Is there any way to just backup the files that it is going to replace?
Beaver
kichik
13th November 2002 18:29 UTC
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 $INSTDIRbackup
>!insertmacro BackupAndExtract "C:\\dev\\whateverfile.something" "outputname.st"
># NSIS will only delete this dir if it's empty
>RMDir $INSTDIRbackup 
>
    
    
      Beaver
      13th November 2002 18:46 UTC
      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
      13th November 2002 19:02 UTC
      You have read the old post :(
      
      I have edited it since you have read it... Please read it again.
     
    
    
      Beaver
      13th November 2002 19:23 UTC
      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
      13th November 2002 19:30 UTC
      You need to replcae outputname.st with the output name of your file. For example:
      
      !insertmacro BackupAndExtract "C:\dev\Core.dll" "Core.dll"
     
    
    
      Beaver
      13th November 2002 19:57 UTC
      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
      13th November 2002 19:58 UTC
      Attach the script please.
     
    
    
      kichik
      13th November 2002 20:25 UTC
      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
      13th November 2002 22:18 UTC
      That Worked! Thanks you VERY much for your help today. With out it I do not think we could have met our deadline...