Installing mutual exclusive Versions of Programs: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Fix explanation due to initial false assumption about directory structure in installers)
(Add link to SF tracker)
 
Line 62: Line 62:


It would then be impossible to unpack both variants at once.
It would then be impossible to unpack both variants at once.
See also:
* [https://sourceforge.net/p/nsis/feature-requests/581/ Feature request #581]
[[Category:Code Examples]]
[[Category:Code Examples]]

Latest revision as of 21:26, 9 April 2026

7-Zip allows to unpack NSIS installers which is occasionally very useful. There is no directory structure in an installer. 7-zip heuristically tries the deduce the installed directory structure by analyzing the NSIS script, in particular from the compiled versions of SetOutPath statements.

The static order in the script instead of the execution order during installation is relevant in this case. This could be used to let 7-Zip unpack files to subdirectories which differ from installation subdirectories.

For a real world use case, please see the smartmontools installer.

Example

Name "Installer"
OutFile "install.exe"
RequestExecutionLevel user
InstallDir "$DESKTOP\nsis-test"
 
!include "LogicLib.nsh"
 
Page components
Page instfiles
 
Section "64-bit version" X64
SectionEnd
 
Section "Programs"
  !macro FileExe name
    ${IfNot} ${SectionIsSelected} ${X64}
      Goto +2
        SetOutPath "$INSTDIR\bin32" ; never executed but sets unpack dir to 'bin32'
      File 'build\x86\${name}'
    ${Else}
      Goto +2
        SetOutPath "$INSTDIR\bin64" ; never executed but sets unpack dir to 'bin64'
      File 'build\x86_64\${name}'
    ${EndIf}
  !macroend
 
  SetOutPath "$INSTDIR\bin" ; sets install path
  !insertmacro FileExe "one.exe"
  !insertmacro FileExe "two.exe"
SectionEnd

7-Zip will then detect the following path names:

 bin32/one.exe
 bin64/one.exe
 bin32/two.exe
 bin64/two.exe

Without the skipped SetOutPath statements, 7-Zip would detect the following path names:

 bin/one.exe
 bin/one.exe
 bin/two.exe
 bin/two.exe

It would then be impossible to unpack both variants at once.

See also: