Skip to content
⌘ NSIS Forum Archive

File with variable

12 posts

mojmir#

File with variable

Hello,

this is my first install program so i am a bit clumsy with this.

I have at least 4 packages (xp, vista)x(32, 64). i somehow glued the detection from available sources and now i need to do the Section part.
What do I do:
1) create c:\_builds
2) build everything into it, so that it has folders like
blackbox.nsi
vs_vista_32
vs_vista_64
vs_xp_32
3) inside blackbox.nsi i assemble the build name, cca like this
  StrCpy $1 $usr_win
StrCpy $2 $usr_bits

StrCpy $builddir "vs_$1_$2"
4) now for the problematic Section, i'd like to do something like this:

Section "BlackBox"
SetOutPath $INSTDIR
File $builddir\"bbnote.exe"
...
SectionEnd
But this gives me error for nonexistent file (bbnote.exe).
So how to achieve it? Or do i have to take an another approach?

Best regards and many thanks for this great installer,
Mojmir
mojmir#
could you give me a hint how to do that, please?

i tried naive approach, but failed

!define platform_build_dir ${build_dir}

Section "BlackBox"
SetOutPath $INSTDIR
File "${platform_build_dir}\bbnote.exe"
JasonFriday13#
Originally Posted by mojmir View Post
inside blackbox.nsi i assemble the build name, cca like this
  StrCpy $1 $usr_win
StrCpy $2 $usr_bits

StrCpy $builddir "vs_$1_$2"
You're getting confused with compile-time and run-time commands. So based on what your build directories are, you'll want something like this:

; your platform define goes here, or you can specify it on the command line with /D.
;!define XP32

!ifdef XP32
!define platform_build_dir "vs_xp_32"
!endif

!ifdef VISTA32
!define platform_build_dir "vs_vista_32"
!endif

!ifdef VISTA64
!define platform_build_dir "vs_vista_64"
!endif

!ifndef platform_build_dir
!error "No platform specified for this installer."
!endif

; you can change the OutFile name based on this define, too.
;OutFile "BlackBox-Setup-${platform_build_dir}.exe"

Section "BlackBox"

SetOutPath $INSTDIR
File "${platform_build_dir}\bbnote.exe"

SectionEnd
mojmir#
ugh... *scratch my head*.. but is that what i want?

right now i do not want one installer per one build. i want 1 installer to contain N builds, and then, when the installer is executed, autodetect which one of the build will be used, and only that one is installed on target machine.

// although on the other hand the idea of creating N installers for N builds (for users that do know what they want) will be handy too, so thanks for that reponse anyway 🙂
JasonFriday13#
Originally Posted by mojmir View Post
ugh... *scratch my head*.. but is that what i want?

right now i do not want one installer per one build. i want 1 installer to contain N builds, and then, when the installer is executed, autodetect which one of the build will be used, and only that one is installed on target machine.
Oh, right. I didn't get that from your posts. If you don't have a components page in your installer, then it's relatively easy. Create a section for each build (use the '/o' option to deselect them), and include 'Sections.nsh' (for it's defines) to select a section based on what OS it's running on.
!include "Sections.nsh"

Section /o "XP32" SecXP32
; XP 32 bit files and stuff here
SectionEnd

Section /o "VISTA32" SecVISTA32
; Vista 32 bit files and stuff here
SectionEnd

Section /o "VISTA64" SecVISTA64
; Vista 64 bit files and stuff here
SectionEnd

Function .onInit
; Windows detection code goes here
; The result will run one of these commands below,
; though if detection fails it's good to set a
; default anyway.

;SectionSetFlags ${SecXP32} ${SF_SELECTED}
;SectionSetFlags ${SecVISTA32} ${SF_SELECTED}
;SectionSetFlags ${SecVISTA64} ${SF_SELECTED}
FunctionEnd
If you do have a components page, then it gets very tricky and will require a lot more work. It would be easier to separate the builds out to their own installers.
mojmir#
okay, i will try that later afternoon. many thanks!

i would like to have components, as the software has some styles and plugins that are optional. do you have a link to some example or similar installer perhaps?
JasonFriday13#
I whipped up an example, which wasn't as hard as I thought it might be. You can change the platform by uncommenting a line at the bottom of the script.
mojmir#
yes, this is pure gold, thank you Jason!

i do not think i would figure this out by myself in reasonable time
mojmir#
coming by to thank you once more.

i expanded the example into full blown installer over the weekend and it works great.