Skip to content
⌘ NSIS Forum Archive

Select aditional components

4 posts

Coby#

Select aditional components

This post shows you how to select multiple files on the component page

!define APP "My Setup"
!define INIT
!define MULTILANG
!define LANGDIR "Language"
!define COMPONENTS
# DETAILS #
Name "${APP}"
OutFile "${APP}.exe"
InstallDir "$TEMP\${APP}"
Caption "${APP}"
# COMPRESS #
SetCompressor /SOLID /FINAL lzma
# EXEC LEVEL #
RequestExecutionLevel 'User'
# RUNTIME SWITCHES #
ShowInstDetails hide
ShowInstDetails nevershow
ShowUnInstDetails nevershow
AutoCloseWindow true 
# INCLUDE #
!include "MUI.nsh"
!include "WinCore.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!insertmacro GetOptions
# STYLE #
BrandingText /TRIMRIGHT " "
# PAGE #
!define MUI_CUSTOMFUNCTION_GUIINIT "onGuiInit"
!insertmacro MUI_PAGE_WELCOME
!ifdef OPTIONS | COMPONENTS | MULTILANG
  !define MUI_COMPONENTSPAGE_NODESC
  !define MUI_COMPONENTSPAGE_INTERFACE
  !define MUI_COMPONENTSPAGE_SMALLDESC
  !insertmacro MUI_PAGE_COMPONENTS
!endif
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
# LANGUAGE #
!insertmacro MUI_LANGUAGE "English"
# INIT #
Function ".onInit"
  # INIT
 
  !ifdef INIT
    Call Init
  !endif
  # INIT
 
  !ifdef MULTILANG
    Call MultiLang
  !endif
FunctionEnd
Function "onGuiInit"
FunctionEnd
var /GLOBAL ERROR
Section "-${APP}" Main
  SetDetailsPrint textonly
  DetailPrint `Installing ... Please wait ...`
  SetDetailsPrint listonly
  SetDetailsView hide
  SectionIn RO
  CreateDirectory $INSTDIR
    SetOutPath "$INSTDIR"
     File "Installer.nsi"
  Goto +2
   StrCpy $ERROR "true"
  SetAutoClose true
SectionEnd
!ifdef COMPONENTS
    SectionGroup "${APP} Select"
      Section /o "${APP} Free" Free
      SectionEnd
      Section /o "${APP} Professional" Professional
        IfFileExists "$INSTDIR\${APP}.exe" "" +4
            SetOutPath "$INSTDIR"
                ;File "Professional\Register.dll"
      SectionEnd
    SectionGroupEnd
!endif
!ifdef MULTILANG
    SectionGroup "Language"
        Section /o "Albanian" albanian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Albanian.lng"
        SectionEnd
        Section /o "Arabic" arabic
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Arabic.lng"
        SectionEnd
        Section /o "Belarusian" belarusian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Belarusian.lng"
        SectionEnd
        Section /o "Bulgarian" bulgarian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Bulgarian.lng"
        SectionEnd
        Section /o "SimpChinese" simpChinese
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\ChineseSimp.lng"
        SectionEnd
        Section /o "TradChinese" tradChinese
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\ChineseTrad.lng"
        SectionEnd
        Section /o "Croatian" croatian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Croatian.lng"
        SectionEnd
        Section /o "Czech" czech
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Czech.lng"
        SectionEnd
        Section /o "Danish" danish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Danish.lng"
        SectionEnd
        Section /o "Dutch" dutch
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Dutch.lng"
        SectionEnd
        Section "English" english
            SectionIn RO
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\English.lng"
        SectionEnd
        Section /o "Finnish" finnish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Finnish.lng"
        SectionEnd
        Section /o "French" french
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\French.lng"
        SectionEnd
        Section /o "German" german
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\German.lng"
        SectionEnd
        Section /o "Greek" greek
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Greek.lng"
        SectionEnd
        Section /o "Hebrew" hebrew
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Hebrew.lng"
        SectionEnd
        Section /o "Hungarian" hungarian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Hungarian.lng"
        SectionEnd
        Section /o "Italian" italian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Italian.lng"
        SectionEnd
        Section /o "Japanese" japanese
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Japanese.lng"
        SectionEnd
        Section /o "Korean" korean
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Korean.lng"
        SectionEnd
        Section /o "Mongolian" mongolian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Mongolian.lng"
        SectionEnd
        Section /o "Nepali" nepali
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Nepali.lng"
        SectionEnd
        Section /o "Polish" polish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Polish.lng"
        SectionEnd
        Section /o "Portuguese" Portuguese
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Portuguese (PT-PT).lng"
        SectionEnd
        Section /o "PortugueseBR" portugueseBr
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Portuguese (PT-BR).lng"
        SectionEnd
        Section /o "Romanian" romanian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Romanian.lng"
        SectionEnd
        Section /o "Russian" russian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Russian.lng"
        SectionEnd
        Section /o "Serbian" serbian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Serbian (Cyrillic).lng"
        SectionEnd
        Section /o "SerbianLatin" serbianLatin
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Serbian (Latin).lng"
        SectionEnd
        Section /o "Slovenian" slovenian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Slovenian.lng"
        SectionEnd
        Section /o "Spanish" spanish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Spanish.lng"
        SectionEnd
        Section /o "Swedish" swedish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Swedish.lng"
        SectionEnd
        Section /o "Thai" thai
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Thai.lng"
        SectionEnd
        Section /o "Turkish" turkish
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Turkish.lng"
        SectionEnd
        Section /o "Ukrainian" ukrainian
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Ukrainian.lng"
        SectionEnd
        Section /o "Vietnamese" vietnamese
            SetOutPath "$INSTDIR\${LANGDIR}"
                ;File "${LANGDIR}\Vietnamese.lng"
        SectionEnd
    SectionGroupEnd
    Function MultiLang
        ; === Automatically select language with the same language of Windows language ===
        System::Call `kernel32::GetUserDefaultLangID() i .r0`
        StrCmp $0 "1025" "" +2
            SectionSetFlags ${arabic} 1
        StrCmp $0 "1026" "" +2
            SectionSetFlags ${bulgarian} 1
        StrCmp $0 "1028" "" +2
            SectionSetFlags ${tradChinese} 1
        StrCmp $0 "1029" "" +2
            SectionSetFlags ${czech} 1
        StrCmp $0 "1030" "" +2
            SectionSetFlags ${danish} 1
        StrCmp $0 "1031" "" +2
            SectionSetFlags ${german} 1
        StrCmp $0 "1032" "" +2
            SectionSetFlags ${greek} 1
        StrCmp $0 "1033" "" "" ; English
            SectionSetFlags ${English} 1
        StrCmp $0 "1034" "" +2
            SectionSetFlags ${spanish} 1
        StrCmp $0 "1035" "" +2
            SectionSetFlags ${finnish} 1
        StrCmp $0 "1036" "" +2
            SectionSetFlags ${french} 1
        StrCmp $0 "1037" "" +2
            SectionSetFlags ${hebrew} 1
        StrCmp $0 "1038" "" +2
            SectionSetFlags ${hungarian} 1
        StrCmp $0 "1040" "" +2
            SectionSetFlags ${italian} 1
        StrCmp $0 "1041" "" +2
            SectionSetFlags ${japanese} 1
        StrCmp $0 "1042" "" +2
            SectionSetFlags ${korean} 1
        StrCmp $0 "1043" "" +2
            SectionSetFlags ${dutch} 1
        StrCmp $0 "1045" "" +2
            SectionSetFlags ${polish} 1
        StrCmp $0 "1046" "" +2
            SectionSetFlags ${portugueseBr} 1
        StrCmp $0 "1048" "" +2
            SectionSetFlags ${romanian} 1
        StrCmp $0 "1049" "" +2
            SectionSetFlags ${russian} 1
        StrCmp $0 "1050" "" +2
            SectionSetFlags ${croatian} 1
        StrCmp $0 "1052" "" +2
            SectionSetFlags ${albanian} 1
        StrCmp $0 "1053" "" +2
            SectionSetFlags ${swedish} 1
        StrCmp $0 "1054" "" +2
            SectionSetFlags ${thai} 1
        StrCmp $0 "1055" "" +2
            SectionSetFlags ${turkish} 1
        StrCmp $0 "1058" "" +2
            SectionSetFlags ${ukrainian} 1
        StrCmp $0 "1059" "" +2
            SectionSetFlags ${belarusian} 1
        StrCmp $0 "1060" "" +2
            SectionSetFlags ${slovenian} 1
        StrCmp $0 "1066" "" +2
            SectionSetFlags ${Vietnamese} 1
        StrCmp $0 "1104" "" +2
            SectionSetFlags ${mongolian} 1
        StrCmp $0 "1121" "" +2
            SectionSetFlags ${nepali} 1
        StrCmp $0 "2052" "" +2
            SectionSetFlags ${simpChinese} 1
        StrCmp $0 "2070" "" +2
            SectionSetFlags ${portuguese} 1
        StrCmp $0 "2074" "" +2
            SectionSetFlags ${serbianLatin} 1
        StrCmp $0 "3098" "" +2
            SectionSetFlags ${serbian} 1
    FunctionEnd
!endif
Function .onSelChange
    !insertmacro StartRadioButtons $1
    !insertmacro RadioButton "${Free}"
    !insertmacro RadioButton "${Professional}"
    !insertmacro EndRadioButtons
FunctionEnd
!ifdef INIT
    Function Init
           var /GLOBAL REQUIREDSIZE
        ; === Destroy size lol ===
        StrCpy $0 0
        ${If} ${SectionIsSelected} $0
                SectionGetSize $${Main} $1
                SectionGetSize $${arabic} $1
                SectionGetSize $${bulgarian} $1
                SectionGetSize $${tradChinese} $1
                SectionGetSize $${czech} $1
                SectionGetSize $${danish} $1
                SectionGetSize $${german} $1
                SectionGetSize $${greek} $1
                SectionGetSize $${English} $1
                SectionGetSize $${spanish} $1
                SectionGetSize $${finnish} $1
                SectionGetSize $${french} $1
                SectionGetSize $${hebrew} $1
                SectionGetSize $${hungarian} $1
                SectionGetSize $${italian} $1
                SectionGetSize $${japanese} $1
                SectionGetSize $${korean} $1
                SectionGetSize $${dutch} $1
                SectionGetSize $${polish} $1
                SectionGetSize $${portugueseBr} $1
                SectionGetSize $${romanian} $1
                SectionGetSize $${russian} $1
                SectionGetSize $${croatian} $1
                SectionGetSize $${albanian} $1
                SectionGetSize $${swedish} $1
                SectionGetSize $${thai} $1
                SectionGetSize $${turkish} $1
                SectionGetSize $${ukrainian} $1
                SectionGetSize $${belarusian} $1
                SectionGetSize $${slovenian} $1
                SectionGetSize $${Vietnamese} $1
                SectionGetSize $${mongolian} $1
                SectionGetSize $${nepali} $1
                SectionGetSize $${simpChinese} $1
                SectionGetSize $${portuguese} $1
                SectionGetSize $${serbianLatin} $1
                SectionGetSize $${serbian} $1
                SectionGetSize $${Free} $1
                SectionGetSize $${Professional} $1
            IntOp $0 $0 + $1
        ${EndIf}    
        InTop $0 $0 * 1024 ; KBytes -> Bytes
        IntOp $1 $0 / 1000000
        IntOp $2 $0 % 1000000
        StrCpy $2 $2 2 0
        IntOp $3 $0 / 1048576
        IntOp $4 $0 % 1048576
        StrCpy $4 $4 2 0
        SectionSetSize $${Main} "0" ;use ($1,$2 MB) ;or ($3,$4 MB)
        Strcpy $REQUIREDSIZE '$3,$4 MB'
        SectionSetSize $${arabic} 0
        SectionSetSize $${bulgarian} 0
        SectionSetSize $${tradChinese} 0
        SectionSetSize $${czech} 0
        SectionSetSize $${danish} 0
        SectionSetSize $${german} 0
        SectionSetSize $${greek} 0
        SectionSetSize $${English} 0
        SectionSetSize $${spanish} 0
        SectionSetSize $${finnish} 0
        SectionSetSize $${french} 0
        SectionSetSize $${hebrew} 0
        SectionSetSize $${hungarian} 0
        SectionSetSize $${italian} 0
        SectionSetSize $${japanese} 0
        SectionSetSize $${korean} 0
        SectionSetSize $${dutch} 0
        SectionSetSize $${polish} 0
        SectionSetSize $${portugueseBr} 0
        SectionSetSize $${romanian} 0
        SectionSetSize $${russian} 0
        SectionSetSize $${croatian} 0
        SectionSetSize $${albanian} 0
        SectionSetSize $${swedish} 0
        SectionSetSize $${thai} 0
        SectionSetSize $${turkish} 0
        SectionSetSize $${ukrainian} 0
        SectionSetSize $${belarusian} 0
        SectionSetSize $${slovenian} 0
        SectionSetSize $${Vietnamese} 0
        SectionSetSize $${mongolian} 0
        SectionSetSize $${nepali} 0
        SectionSetSize $${simpChinese} 0
        SectionSetSize $${portuguese} 0
        SectionSetSize $${serbianLatin} 0
        SectionSetSize $${serbian} 0
        SectionSetSize $${Free} "0"
        SectionSetSize $${Professional} "0"
        ; === Other actions ===
        StrCpy $1 ${Free}
    FunctionEnd
!endif
# MOUSE
Function '.onMouseOverSection'
        FindWindow $R0 "#32770" "" $HWNDPARENT
        GetDlgItem $R0 $R0 1043 ; description item
        ${If} $0 == -1
              CreateFont $1 "Arial" 9 500 ; create the font for the default description
              SetCtlColors $R0 0x5f5f61 0xF0F0F0
              SendMessage $R0 ${WM_SETFONT} $1 0
              EnableWindow $R0 0
                  SendMessage $R0 ${WM_SETTEXT} 0 "STR:Position your mouse over a component to see its description."
        ${Else}
            CreateFont $1 "Arial" 9 400 ; create the font for mouse over descriptions
        SetCtlColors $R0 0x5f5f61 0xF0F0F0
            SendMessage $R0 ${WM_SETFONT} $1 0
            EnableWindow $R0 1
        ${If} $0 == 0
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Select components for this program"
        ${ElseIf} $0 == 1
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Select components for this program"
        ${ElseIf} $0 == 2
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install ${APP} Free Version"
        ${ElseIf} $0 == 3
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install ${APP} Pro Version"
        ${ElseIf} $0 == 4
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install aditional language for ${APP}"
        ${ElseIf} $0 == 5
              SendMessage $R0 ${WM_SETTEXT} 0 "STR:Install aditional language for ${APP}"
        ${ElseIf} $0 == 6
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Albanian"'
        ${ElseIf} $0 == 7
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Arabic"'
        ${ElseIf} $0 == 8
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Belarusian"'
        ${ElseIf} $0 == 9
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Bulgarian"'
        ${ElseIf} $0 == 10
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Chinese Simplified"'
        ${ElseIf} $0 == 11
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Chinese Traditional"'
        ${ElseIf} $0 == 12
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Croatian"'
        ${ElseIf} $0 == 13
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Czech"'
        ${ElseIf} $0 == 14
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Danish"'
        ${ElseIf} $0 == 15
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Dutch"'
        ${ElseIf} $0 == 16
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "English"'
        ${ElseIf} $0 == 17
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Finnish"'
        ${ElseIf} $0 == 18
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "French"'
        ${ElseIf} $0 == 19
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "German"'
        ${ElseIf} $0 == 20
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Greek"'
        ${ElseIf} $0 == 21
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Hebrew"'
        ${ElseIf} $0 == 22
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Italian"'
        ${ElseIf} $0 == 23
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Japanese"'
        ${ElseIf} $0 == 24
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Korean"'
        ${ElseIf} $0 == 25
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Mongolian"'
        ${ElseIf} $0 == 26
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Nepali"'
        ${ElseIf} $0 == 27
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Polish"'
        ${ElseIf} $0 == 28
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Portuguese"'
        ${ElseIf} $0 == 29
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Portuguese Brasilian"'
        ${ElseIf} $0 == 30
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Romanian"'
        ${ElseIf} $0 == 31
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Russian"'
        ${ElseIf} $0 == 32
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Serbian"'
        ${ElseIf} $0 == 33
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Serbian Latin"'
        ${ElseIf} $0 == 34
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Slovenian"'
        ${ElseIf} $0 == 35
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Spanish"'
        ${ElseIf} $0 == 36
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Swedish"'
        ${ElseIf} $0 == 37
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Thai"'
        ${ElseIf} $0 == 38
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Turkish"'
        ${ElseIf} $0 == 39
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Ukrainian"'
        ${ElseIf} $0 == 40
              SendMessage $R0 ${WM_SETTEXT} 0 'STR:Install Language: "Vietnamese"'
        ${EndIf}
        ${EndIf}
FunctionEnd 
JasonFriday13#
That's a cool example, but why go to all the trouble of selecting language files? Just install all the language files and detect the default language that the program will use.
Coby#
I apologize for this error.
Below is fixed

!ifdef MULTILANG
    Function MultiLang
        System::Call `kernel32::GetUserDefaultLangID() i .r0`
        StrCmp $0 "1033" "" "" ; English default laguage
                    # SectionSetFlags ${English} 1 # Do not use
    FunctionEnd
!endif 
Anders#
NSIS does a much better job than you to detect the language, just use $language if your installer is also multi-language.