Skip to content
⌘ NSIS Forum Archive

Two installations in one installer: Main app and host environment

4 posts

Motti#

Two installations in one installer: Main app and host environment

On the NSIS Sourceforge site, there is this sample script for installing two software packages in one installer. I am trying to adapt it for my purpose, which is to install additional, ancillary software in a separate folder from the main install if the target machine is a Windows 32 system.

I am a newbie on NSIS and I'm having trouble understanding how that script works. Could someone publish a simpler, cut-down version of it, that -

- uses the older, simpler, non-MUI installer,
and is without -
- language selection
- the pages for the user to select components of the package to install
- the section below the comment "Please don't modify below here unless ..."

I am hoping that such a cut-down, simpler version will make it easier to understand and adapt it.
Motti#
Yes, I do, because I am installing a 16-bit program that I wrote decades ago. In 32-bit Windows (nowadays a rarity), it runs seamlessly as a console app, so only my app needs to be installed, but if the target system is 64-bit Windows, the installation needs to include DosBox and some additions to its config file, hence the (conditional) need for two installations.
Anders#
The example you linked to uses two InstFiles pages which is extra complicated and not really needed in your scenario.

The basics are really simple, just unselect the function in .onInit if you are on a x86 system. A bit more tweaking is required to get the directory pages to display the correct sizes.

InstallDir "$ProgramFiles\MyApp"
!include LogicLib.nsh
!include x64.nsh
!include Sections.nsh
!include WinMessages.nsh
Var DosboxDir
Page Components
Page Directory MainDirPagePreCallback
PageEx Directory
    PageCallbacks DosBoxDirPagePreCallback
    DirVar $DosboxDir
    Caption ": DOSBox directory"
PageExEnd
Page InstFiles
Function .onInit
StrCpy $DosboxDir "$ProgramFiles\DOSBox" ; Default DOSBox directory
Call ConfigureSectionsForPlatform
FunctionEnd
Section -Pre
Call ConfigureSectionsForPlatform ; Restore sections because we changed them for the directory pages
SectionEnd
Section "Main Application" SID_MAIN
SectionIn RO
SetOutPath $InstDir
File $%windir%\Explorer.exe ; Dummy file
SectionEnd
Section "DOSBox" SID_DOSBOX
SectionIn RO
SetOutPath $DosboxDir
File $%windir%\system32\regedit.exe ; Dummy file
SectionEnd
Function ConfigureSectionsForPlatform
!insertmacro SelectSection ${SID_MAIN}
${If} ${IsNativeIA32}
    !insertmacro UnselectSection ${SID_DOSBOX}
${Else}
    !insertmacro SelectSection ${SID_DOSBOX}
${EndIf}
FunctionEnd
Function MainDirPagePreCallback
Call ConfigureSectionsForPlatform
!insertmacro UnselectSection ${SID_DOSBOX}
${If} ${IsNativeIA32}
    GetDlgItem $0 $hWndParent 1
    SendMessage $0 ${WM_SETTEXT} "" "STR:$(^InstallBtn)" ; Change the button text if there is no other pages before the InstFiles page
${EndIf}
FunctionEnd
Function DosBoxDirPagePreCallback
${If} ${IsNativeIA32}
    Abort ; Skip the page
${EndIf}
Call ConfigureSectionsForPlatform
!insertmacro UnselectSection ${SID_MAIN}
FunctionEnd