Set section names according ini file

From NSIS Wiki
Jump to navigationJump to search
Author: bholliger (talk, contrib)


Description

This example shows how to set section titles according to an ini file.

The section title at compile time must be included in the ini-file. This section text will be replaced at run-time with the corresponding entry given in the ini-file. Remember to adjust the maximal number of sections ("SECTIONCOUNT").

Example

;--------------------------------
;Include Modern UI
 
  !include "MUI.nsh"
  !include "logiclib.nsh"
;--------------------------------
;General
 
  Outfile settextfromini.exe
 
;--------------------------------
;Pages
 
  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_INSTFILES
 
Function .onInit
  InitPluginsDir
  File /oname=$PLUGINSDIR\secs.ini secs.ini
 
  Call ComponentShow
 
FunctionEnd
 
!define SECTIONCOUNT 2 ; max sections - 1
 
;--------------------------------
;Sections
 
Section 'sec0'
  ; ...
SectionEnd
 
Section 'sec1'
  ; ...
SectionEnd
 
Section 'sec2'
  ; ...
SectionEnd
 
; Set component's texts
Function ComponentShow
  ${For} $R1 0 ${SECTIONCOUNT}
    SectionGetText $R1 $R2
    ReadINIStr $R0 "$PLUGINSDIR\secs.ini" "setup" "$R2"
    SectionSetText $R1 $R0
  ${Next}
FunctionEnd
 
;--------------------------------
;Languages
 
  !insertmacro MUI_LANGUAGE "English"

Structure of secs.ini:

 ; section titles
 [setup]
 sec0=my first section
 sec1=my second section
 sec2=my third section