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

╄→гoц情女王★ 提交于 2020-01-11 08:05:55

问题


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?


回答1:


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



回答2:


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...




回答3:


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


来源:https://stackoverflow.com/questions/11126629/use-one-nsis-installer-to-install-32-bit-binaries-on-32-bit-os-and-64-bit-binari

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!