Use one NSIS installer to install 32-bit binaries on 32-bit OS and 64-bit binaries on 64-bit OS possible?
Asked Answered
S

3

14

I currently have two WIX installers for a product that I maintain. One for 32-bit operating systems, and one for 64-bit operating systems. Instead of maintaining two separate installers, I want to combine them into one NSIS installer that can "determine" the "bitness" of the OS and then copy the appropriate binaries into the program directory. Has anyone had any experience with this and could provide a working sample script that NSIS can use to make the installer?

Stelmach answered 20/6, 2012 at 19:18 Comment(0)
E
11

x64.nsh has some helper macros and you can install into $programfiles32 or $programfiles64

Edit:

Function .onInit
StrCpy $instdir $programfiles32\MyApp
${If} ${RunningX64}
  StrCpy $instdir $programfiles64\MyApp
${EndIf}
FunctionEnd

...

Section
Setoutpath $instdir
${If} ${RunningX64}
  File /r build\64\*
${Else}
  File /r build\32\*
${EndIf}
SectionEnd
Elyssa answered 20/6, 2012 at 19:29 Comment(3)
I did look at this and it will allow me to determine the bitness of the operating system, but I still run into the problem where I need to tell the installer which files to install. I currently have one "section" that contains this: SetOutPath ${PROGRAMINSTALL} File /r build\\* So I'm not sure that x64 module would help in this situation...Stelmach
Also, I'm not installing 32-bit binaries on a 64-bit system... I'm installing 64-bit files on 64-bit operating systems and 32-bit files on 32-bit operating systems...Stelmach
@JulianEasterling this does tell the system which files to install. If you put 64-bit files in build\64 and 32-bit files in build\32. If you also need to change the installation directory depending on the architecture then you can put SetOutPath inside the If / ElseFingerling
S
4

I believe that I figured it out... I haven't tested this yet, but it should work...

The answer is to create two "sections" for each set of files. SEC0000 for 32-bit and SEC0001 for 64-bit files. Then,

!include x64.nsh

Function .onInit
  #Determine the bitness of the OS and enable the correct section
  ${if} ${RunningX64}
    SectionSetFlags ${SEC0001} 17
    SectionSetFlags ${SEC0000} 16
  ${else}
    SectionSetFlags ${SEC0001} 16
    SectionSetFlags ${SEC0000} 17
  ${endif}
FunctionEnd

I believe that the same logic will be needed in the un.onInit function too so the Uninstaller knows which files to remove...

Stelmach answered 20/6, 2012 at 20:19 Comment(0)
J
4

For a simple universal installer using 3.0a0, I found with a little experimentation that the following worked for me:

!include x64.nsh
Function .onInit
  #Determine the bitness of the OS and enable the correct section
  ${If} ${RunningX64}
    SectionSetFlags ${SEC0000}  ${SECTION_OFF}
    SectionSetFlags ${SEC0001}  ${SF_SELECTED}
  ${Else}
    SectionSetFlags ${SEC0001}  ${SECTION_OFF}
    SectionSetFlags ${SEC0000}  ${SF_SELECTED}
  ${EndIf}
FunctionEnd

I just had to remember to put the function after the referenced sections. Each of my sections simply referenced a same-named .exe in their respective 32-bit/ and 64-bit/ directories, so my uninstaller did not require any special treatment. I haven't tested it on a 32-bit system but it did work for a 64-bit system.

Example:

section "64-bit" SEC0001
  messageBox MB_OK "64-BIT!"
  File "C:\foo\64-bit\some-utility.exe"
sectionEND
Jeromejeromy answered 5/6, 2013 at 16:0 Comment(1)
for this you'll need !include "Sections.nsh" in your script as SF_SELECTED selected is part of Sections.nshFingerling

© 2022 - 2024 — McMap. All rights reserved.