how I can do a section in other section? - nsis

I want to make a section in other section, how I can do this thing ?
Section /o "Control System Toolbox"
Section "Communications Toolbox"
SectionIn RO
FileWrite $9 "product=Control System Toolbox$\r$\n"
AddSize 0
SectionEnd
FileWrite $9 "product=Control System Toolbox$\r$\n"
AddSize 0
SectionEnd

You can organize sections in section groups. The groups cannot execute code but you can put hidden sections in them:
Page Components
Page InstFiles
SectionGroup /e "Main Component"
Section "" SID_MAIN
DetailPrint "Installing Main Component..."
SectionEnd
Section /o "Bonus feature" SID_BONUS
DetailPrint "Installing bonus Component..."
SectionEnd
SectionGroupEnd
!include Sections.nsh
!include LogicLib.nsh
Function .OnSelChange
${If} ${SectionIsSelected} ${SID_BONUS}
!insertmacro SelectSection ${SID_MAIN} ; The main component is required when installing the bonus component
${EndIf}
FunctionEnd

Related

How to make NSIS section mandatory depending on condition

I have a section in my installer I am attempting to make mandatory depending on some condition (the presence of a registry value) but I am not getting the behaviour I am expecting.
I am attempting to use the following command to make the section ticked and locked:
SectionIn RO
I also have a registry value that definitely exists but both of the following code chunks cause the section to be locked and ticked...
ClearErrors
ReadRegStr $0 HKCU "Software\Test" "TestValue"
${If} ${Errors}
SectionIn RO ; registry key not found
${Else}
; do nothing
${EndIf}
ClearErrors
ReadRegStr $0 HKCU "Software\Test" "TestValue"
${If} ${Errors}
; do nothing
${Else}
SectionIn RO ; registry key was found
${EndIf}
So it seems like either both control paths are being executed or the SectionIn command is trancending the if logic.
I can't seem to find much documentation on this particular command but I am a bit stumped. Any ideas?
SectionIn is an attribute and cannot be changed at run-time.
You should use the section helper macros in .onInit:
Section "blah" S_1
SectionEnd
!include LogicLib.nsh
!include Sections.nsh
Function .onInit
...
${If} ${Errors}
!insertmacro SetSectionFlag ${S_1} ${SF_RO}
${EndIf}
FunctionEnd

How to load the files based on the locale and generate the installer using NSIS?

My requirement is, I have specific files (Dlls, chms, etc) for each Locale (Language). I need to load those files based on the locale and generate the installer.
And while uninstalling i should uninstall those files as well from the traget directory.
Here what i am doing is in .onInit function, using GetUserDefaultUILanguage() i am getting the locale and checking this locale and loading the files under this locale.
is it the correct way? Please provide any suggestions for this code.
And also do we need to use ;Pages section before the ;Languages section?
Because i am getting a warning to use ;Pages section before the ;Languages section when i am compiling.
Below is the code snippet i have written:
; LocaleDlls.nsi
;
;
; It will install LocaleDlls.nsi into a directory that the user selects.
;--------------------------------
!include LogicLib.nsh
!include "MUI2.nsh"
; The name of the installer in the path C:\Program Files\LocaleDlls
Name "LocaleDlls"
; The file to write in the path E:\Source\NULLSOFT\src
OutFile "LocaleDlls.exe"
; The default installation directory in the path C:\Program Files\LocaleDlls
InstallDir $PROGRAMFILES\LocaleDlls
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically) It shows the path the path C:\Program Files\LocaleDlls
InstallDirRegKey HKLM "Software\NSIS_LocaleDlls" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
;Pages
; Do we need to use PAGE macros before giving LANGUAGE as when compiling we are getting an error.
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "PortugueseBR"
;--------------------------------
;Installer Functions
Function .onInit
System::Call 'kernel32::GetUserDefaultUILanguage() i.r10'
MessageBox MB_OK "Return value = $R0"
StrCpy $Language ${LANG_PORTUGUESEBR}
MessageBox MB_OK "Return value = $Language"
${If} $Language P= 1046
MessageBox MB_OK "Current Locale is Portuguese... Loading Portuguese Files"
${EndIf}
File E:\Source\NULLSOFT\src\EngPortuguese\Portuguese\AllowStandby.reg
File E:\Source\NULLSOFT\src\EngPortuguese\Portuguese\Test.chm
File E:\Source\NULLSOFT\src\EngPortuguese\Portuguese\Testdlg.dll
File E:\Source\NULLSOFT\src\EngPortuguese\Portuguese\resource.dll
FunctionEnd
;--------------------------------
; The stuff to install
Section "LocaleDlls (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\LocaleDlls
SetOutPath $INSTDIR
; Give the File path
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")' ; Tell Windows we trust all .DLLs in this directory
System::Call 'KERNEL32::LoadLibrary(t "$INSTDIR\testdlg.dll.dll")p.r8 ?e'
Pop $7 ; Get ?e result
${IfThen} $8 P= 0 ${|} MessageBox MB_ICONSTOP "Failed to load pchuteres.dll, error $7" ${|}
${If} $8 P<> 0
MessageBox MB_OK 'Successfully loaded "$INSTDIR\testdlg.dll.dll" # $8'
${EndIf}
; Do the install
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_DllTesting "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "DisplayName" "NSIS LocaleDlls"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\LocaleDlls"
CreateShortcut "$SMPROGRAMS\LocaleDlls\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortcut "$SMPROGRAMS\LocaleDlls\LocaleDlls (MakeNSISW).lnk" "$INSTDIR\LocaleDlls.nsi" "" "$INSTDIR\LocaleDlls.nsi" 0
SectionEnd
;--------------------------------
; Uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls"
DeleteRegKey HKLM SOFTWARE\NSIS_LocaleDlls
; Remove files and uninstaller
Delete $INSTDIR\LocaleDlls.nsi
Delete $INSTDIR\uninstall.exe
; Remove shortcuts, if any
Delete "$SMPROGRAMS\LocaleDlls\*.*"
; Remove directories used
RMDir "$SMPROGRAMS\LocaleDlls"
RMDir "$INSTDIR"
SectionEnd
;--------------------------------
;Uninstaller Functions
Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
FunctionEnd
You don't need to call GetUserDefaultUILanguage, NSIS calls GetUserDefaultUILanguage to try to set the default $language. If it cannot find a matching language, the first language specified in the .NSI is used. All of this happens before .onInit is called and you don't have to do anything. You can however change $language in .onInit if you are not happy with the language NSIS has chosen. You can also use !insertmacro MUI_LANGDLL_DISPLAY to display a language selection dialog.
Pages need to be inserted before the language when using MUI because the language macro needs to know which strings are required by the pages. It is important that you use the MUI page macros MUI_PAGE_* and not the native page:
!insertmacro MUI_PAGE_WELCOME
Page Custom MyPage ; There is no MUI_PAGE_* macro for this
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English" ; Must come after all MUI_PAGE_* macros.

NSIS do things if section is not checked

I have created an NSIS Installer which works fine. Now I want to add another section called "install as update" which only will do things when it is NOT checked.
Why:
When the full version is installed, it will overwrite certain files which contain the activation codes of the software.
I can do it otherwise, and make a section called "install full version", but that makes less sense.
Section /o "Install as update" SecUpdate
*if(checked == false){
SetOutPath "$INSTDIR\data"
File "data\ConfigFile.xml"
File "..."
File "..."
File "..."
File "..."
File "..."
File "..."
File "..."
*}
SectionEnd
*these two lines represent what I would like to do.
If a section is unchecked then the code in it will not execute no matter what you do so you have to put the code somewhere else. A hidden section is a good solution:
!include LogicLib.nsh
!include Sections.nsh
Page Components
Page InstFiles
Section "Program files"
SectionIn RO
;SetOutPath ...
;File ...
SectionEnd
Section /o "Install as update" SID_UPDATE
SectionEnd
Section -OverwriteActivation SID_OWACTIVATION
SetOutPath "$INSTDIR\data"
File "whatever.xml"
SectionEnd
Function .onSelChange
${If} ${SectionIsSelected} ${SID_UPDATE}
!insertmacro UnselectSection ${SID_OWACTIVATION}
${Else}
!insertmacro SelectSection ${SID_OWACTIVATION}
${EndIf}
FunctionEnd

Changing the selection in the components page of NSIS based on the OS on which we are installing

I am finding it difficult to change the selection in the components page of nsis.
The requirement is during installation i get a license agreement page ,if the user agrees then he/she will click on I AGREE ,after the user clicks on I AGREE ,i want to know on which OS the
setup is being installed that is it can be either on a Windows Embedded OS or WinXp/Win7.
So if it is Windows Embedded OS i want to change the installation package and if it is not Windows Embedded OS then the installation package will be different.
I am using MUI ver1 not MUI2 in my project.
Please let me know how this can be achieved.
To test for the OS where the setup is running, you can use macros defined Winver.nsh with those provided with LogicLib.nsh to make elegant tests like this
;Dont't forget to include
!include "LogicLib.nsh" # use of various logic statements
!include "WinVer.nsh" # LogicLib extension for OS tests
A platform test example:
${if} ${AtLeastWin95}
${AndIf} ${AtMostWinME}
;here we are on a pre-win2k
;do something
${elseIf} ${isWin2008}
${orIf} ${AtLeastWin2008R2}
;this is post-win7
;do other thing
${endif}
To change at runtime the components to install, you can use the macros from Sections.nsh:
;if you have
Section "Sample Database" SecApplicationDB
;...
SectionEnd
;you can select or un select by code:
!insertmacro SelectSection ${SecApplicationDB}
;or
!insertmacro UnselectSection ${SecApplicationDB}
WinVer.nsh does not support checking for Embedded NT but you can perform the check yourself:
!include Sections.nsh
!include MUI.nsh
!ifndef VER_SUITE_EMBEDDEDNT
!define VER_SUITE_EMBEDDEDNT 0x00000040
!endif
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Section "Embedded" SID_EMBED
SectionIn RO
SectionEnd
Section "Normal" SID_NORMAL
SectionIn RO
SectionEnd
Function .onInit
System::Call '*(i156,&i152)i.r1'
System::Call 'KERNEL32::GetVersionExA(ir1)'
System::Call '*$1(&i152,&i2.r2)'
System::Free $1
IntOp $2 $2 & ${VER_SUITE_EMBEDDEDNT}
${If} $2 <> 0
!insertmacro SelectSection ${SID_EMBED}
!insertmacro UnselectSection ${SID_NORMAL}
${Else}
!insertmacro UnselectSection ${SID_EMBED}
!insertmacro SelectSection ${SID_NORMAL}
${EndIf}
FunctionEnd

Empty box showing up in my installer? How do I remove it?

I'm using a pretty simple install script for my application and its showing an empty box on the section selection screen. I would like to remove it, or at least know what its for and fill it up.
here is a screenshot
and my install script
; example2.nsi
;
; This script is based on example1.nsi, but it remember the directory,
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install ICV-MRI into a directory that the user selects,
;--------------------------------
!include "MUI.nsh"
; The name of the installer
Name "ICV-MRI"
; The file to write
OutFile "ICV-MRI_Setup.exe"
; The default installation directory
InstallDir $PROGRAMFILES\ICV-MRI
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\ICV-MRI" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
Function LaunchLink
ExecShell "" "$INSTDIR\mri.exe"
FunctionEnd
;--------------------------------
; Pages
Page components
Page directory
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles
; !insertmacro MUI_PAGE_WELCOME
; !insertmacro MUI_PAGE_DIRECTORY
; !insertmacro MUI_PAGE_INSTFILES
# These indented statements modify settings for MUI_PAGE_FINISH
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Run MRI when the installer closes"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
; The stuff to install
Section "ICV-MRI (required)"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File "dist\bz2.pyd"
File "dist\library.zip"
File "dist\mri.exe"
File "dist\PyQt4.QtCore.pyd"
File "dist\PyQt4.QtGui.pyd"
File "dist\python26.dll"
File "dist\QtCore4.dll"
File "dist\QtGui4.dll"
File "dist\select.pyd"
File "dist\sip.pyd"
File "dist\unicodedata.pyd"
File "dist\w9xpopen.exe"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\ICV-MRI "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ICV-MRI" "DisplayName" "ICV-MRI"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ICV-MRI" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ICV-MRI" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ICV-MRI" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\ICV-MRI"
CreateShortCut "$SMPROGRAMS\ICV-MRI\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\ICV-MRI\ICV-MRI.lnk" "$INSTDIR\mri.exe" "" "$INSTDIR\mri.exe" 0
SectionEnd
Section "Desktop Shortcuts"
CreateShortCut "$DESKTOP\ICV-MRI.lnk" "$INSTDIR\mri.exe" "" "$INSTDIR\mri.exe" 0
SectionEnd
;--------------------------------
If you want to remove it, !define MUI_COMPONENTSPAGE_NODESC at the top of your script
That box is for the section description.
Take a look at the Modern UI Basic.nsi file:
;--------------------------------
;Installer Sections
Section "Dummy Section" SecDummy
SetOutPath "$INSTDIR"
;ADD YOUR OWN FILES HERE...
;Store installation folder
WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
;--------------------------------
;Descriptions
;Language strings
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Read more Modern UI Readme, section on Components page descriptions.
The Modern UI components page has a text box in which a description can be shown when the user hovers the mouse over a component. If you don't want to use these descriptions, insert the MUI_COMPONENTSPAGE_NODESC interface setting.
To set a description for a section, an additional parameter needs to be added to Section commmand with a unique identifier for the section. This name can later be used to set the description for this section.

Resources