surfdabbler
16th May 2006 14:19 UTC
Passing data through to !included files
I have a set of similar installations based on one common NSIS script. Mostly the same fileset, but a different main exe, different product name, different Start Menu name, etc. (i.e. different versions for different customers).
I use an external script to swap in the appropriate exe to a standard name before running the script.
I have tried using 2 nsi files, as follows...
product1.nsi
!define APP_NAME "Product1"
!include "common.nsi"
And common.nsi then uses APP_NAME for the Name, install dir, StartMenu naming, etc. But, APP_NAME doesn't seem to carry through to the second file. It only works if I define it in common.nsi. Any hints on how to make this work, or different ways of doing this?
I've tried using a Var, but it doesn't seem to work either. I can define "Name" in product1.nsi, and it carries through to common.nsi, but that doesn't do everything I need it to do.
Red Wine
16th May 2006 18:08 UTC
compile common.nsi and use a header with all needed info.
i.e. !include header.nsh where header.nsh could be like this:
!define APP_NAME 'my app'
!define VERSION '1.5.0.0'
!define MAIN_EXE 'c:\temp\myapp.exe'
etc
surfdabbler
17th May 2006 00:45 UTC
Thanks for the reply.
I don't understand how using a header file allows me to select at compile time which values to use. I would have to somehow selectively include one of several different .nsh files, or write several common.nsi files to include the different headers, which defeats the whole purpose of common.nsi.
My external shell script knows about the different versions, but how can this information be handled in the NSI scripting?
The shell script can copy the appropriate product1.nsh or product2.nsh to a standard name, product.nsh, and common.nsi can include product.nsh, but surely there's a nicer way...?
Comperio
17th May 2006 01:41 UTC
One thing that I do is create a separate EXE using an NSIS script that generates an custom page that asks the user options he/she wants to use. This EXE would then create a header file on the fly.
Then, in your main script, add the following lines of code:
!system "SelectBuild.exe" ### this is the name of your EXE
!include "ProductVersion.nsh" ### this is the header that is created
; the rest of your code goes here...
The attached sample script helps illustrate the header creation file.
Anther option:
Pass a define using the '/d' command on MakeNSIS.exe and then use !ifdef blocks for each of your products.
For more ideas, have a look at the NSIS help manual, compile-time commands (chapter 5)
Red Wine
17th May 2006 05:53 UTC
I don't understand how using a header file allows me to select at compile time which values to use. I would have to somehow selectively include one of several different .nsh files, or write several common.nsi files to include the different headers, which defeats the whole purpose of common.nsi.
use !ifdef on header.nsh
!ifdef PROG_1
<include this and that>
!endif
!ifdef PROG_2
..............
!endif
and in nsi file:
!define PROG_1
surfdabbler
17th May 2006 06:15 UTC
This goes back to my original solution of having multiple main files, that include common.nsi. And after trying this for several hours yesterday, I tried it again today, and it actually works now. I don't know what's different, but it is all good. Thanks for your help!