简体   繁体   English

使用一个NSIS安装程序可以在32位操作系统上安装32位二进制文​​件,在64位操作系统上安装64位二进制文​​件吗?

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

I currently have two WIX installers for a product that I maintain. 我目前有两个WIX安装程序用于我维护的产品。 One for 32-bit operating systems, and one for 64-bit operating systems. 一个用于32位操作系统,一个用于64位操作系统。 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. 我想将它们组合成一个NSIS安装程序,而不是维护两个单独的安装程序,它可以“确定”操作系统的“位数”,然后将相应的二进制文件复制到程序目录中。 Has anyone had any experience with this and could provide a working sample script that NSIS can use to make the installer? 有没有人有这方面的经验,并可以提供NSIS可用于制作安装程序的工作示例脚本?

x64.nsh has some helper macros and you can install into $programfiles32 or $programfiles64 x64.nsh有一些辅助宏,你可以安装到$programfiles32$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

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. SEC0000用于32位, SEC0001用于64位文件。 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... 我相信在un.onInit函数中也需要相同的逻辑,因此卸载程序知道要删除哪些文件...

For a simple universal installer using 3.0a0, I found with a little experimentation that the following worked for me: 对于使用3.0a0的简单通用安装程序,我通过一些实验发现以下内容对我有用:

!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. 我的每个部分都简单地在它们各自的32位/ 64位/目录中引用了同名的.exe,因此我的卸载程序不需要任何特殊处理。 I haven't tested it on a 32-bit system but it did work for a 64-bit system. 我没有在32位系统上测试它,但它确实适用于64位系统。

Example: 例:

section "64-bit" SEC0001
  messageBox MB_OK "64-BIT!"
  File "C:\foo\64-bit\some-utility.exe"
sectionEND

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM