- NSIS Discussion
- How to get what files to install on compile time?
Archive: How to get what files to install on compile time?
Chilli24
11th April 2006 10:11 UTC
How to get what files to install on compile time?
Hi...I stopped using NSIS about an year ago. I know that then it was not possible to define in an .ini file which files the NSIS executable should contain.
So, my question is this: Is it possible to tell the NSIS compiler to get the files from an .ini file.
I want to have a generic setup script to install some patches for my application. And because different patches may contain different files, I do not want to be forced to reedit the script when those files change. I want just to edit an .ini file and the NSIS compiler should look at that file and get from there the files.
Thank you.
Afrow UK
11th April 2006 10:33 UTC
http://nsis.sourceforge.net/Invoking...n_compile-time
Create another NSIS installer which is executed at compile time to use ReadINIStr and write a list of NSIS File instructions in a seperate .nsi file which is later !include-d by the main .nsi script.
-Stu
Chilli24
11th April 2006 10:43 UTC
Thank you. I will try that.
Red Wine
11th April 2006 11:51 UTC
If you're going to use Afrow's RecFind you'll make your life easy. :-)
1. Create the header
!define PatchDir 'D:\Patch1'
!define Header 'Patch1_Files.nsh'
OutFile 'CreateHeader.exe'
!include RecFind.nsh
Section
SetOutPath '$EXEDIR'
FileOpen $R2 ${Header} w
${RecFindOpen} "${PatchDir}" $R0 $R1
${RecFindFirst}
FileWrite $R2 'File "${PatchDir}$R0\$R1"$\r$\n'
${RecFindNext}
${RecFindClose}
FileClose $R2
SectionEnd
2. Create your Installation
!define Header 'Patch1_Files.nsh'
!system CreateHeader.exe
!include ${Header}
This way you only need to edit the two defines each time you want to add a new patch. :-)
Afrow UK
11th April 2006 12:20 UTC
Nice script Red Wine!
Just one thing though,
!include ${Header}
-Stu
Chilli24
11th April 2006 12:49 UTC
Thank you. I am glad that there is a solution for my problem. I will try to do this a.s.a.p
Red Wine
11th April 2006 12:59 UTC
@ Stu
hmm a typo! that's me! :-)
@ Chilli24
to include subdirs as well place the line bellow under ${RecFindOpen} "${PatchDir}" $R0 $R1:
FileWrite $R2 'SetOutPath "$$INSTDIR$R0"$\r$\n'
Section
SetOutPath '$EXEDIR'
FileOpen $R2 ${Header} w
${RecFindOpen} "${PatchDir}" $R0 $R1
FileWrite $R2 'SetOutPath "$$INSTDIR$R0"$\r$\n'
${RecFindFirst}
FileWrite $R2 'File "${PatchDir}$R0\$R1"$\r$\n'
${RecFindNext}
${RecFindClose}
FileClose $R2
SectionEnd
Red Wine
11th April 2006 14:51 UTC
Just posted an article at wiki
JasonFriday13
12th April 2006 00:55 UTC
It is also possible to compile and run a premade script from your installer at compile time:
!define PatchType 'Patch1_Files'
!define PatchPath 'C:\${PatchType}'
!system '"${NSISDIR}\makensis.exe" /D PatchDir "${PatchPath}" /D Header "${PatchType}" "CreateHeader.nsi"'
!system 'CreateHeader.exe'
Section
!include '${PatchType}.nsh'
SectionEnd
CreateHeader.nsi contains the code above by Red Wine, and remove the top two lines of the script as they are defined on the command line :). Now all you have to change is the patch type at the top of my script :).
[edit]Typo: 'bellow' is spelled 'below' :) [/edit]
JasonFriday13
12th April 2006 04:04 UTC
Sorry, just found an error: forgot the extenstion on the command line.
!define PatchType 'Patch1_Files'
!define PatchPath 'C:\${PatchType}'
!system '"${NSISDIR}\makensis.exe" /D PatchDir "${PatchPath}" /D Header "${PatchType}.nsh" "CreateHeader.nsi"'
!system 'CreateHeader.exe'
Section
!include '${PatchType}.nsh'
SectionEnd
Just ran out of time to edit my post, so I replied again.
Red Wine
12th April 2006 14:18 UTC
@ Jason
I really appreciate your notice for my spelling, though, don't expect I will not do it again.:-)
If you don't mind, please contribute your extension on the above mentioned article
regards
JasonFriday13
12th April 2006 23:22 UTC
Will do. [edit] Done. [/edit]