User Tools

Site Tools


nsis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
nsis [2014/12/09 12:49] – [Sections] skipidarnsis [2020/12/27 20:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 +===== NSIS Installer =====
 +http://nsis.sourceforge.net/Main_Page
  
 +An old installer.
 +Use Inno Setup if possible:
 +
 +http://jrsoftware.org/isinfo.php \\
 +http://sourceforge.net/projects/istool/ 
 +
 +
 +=== Command Line parameters  ===
 +
 +Read command line parameters
 +<code>
 +${GetOptions} "[Parameters]" "[Option]" $var
 +</code>
 +
 +<code>
 +"[Parameters]"     ; command line parameters
 +                   ;
 +"[Option]"         ; option name
 +                   ;
 +$var               ; Result: option string
 +</code>
 +
 +
 +**Example**
 +<code>
 +Section
 + ${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR="  $R0
 + ;$R0=C:\Program Files\Common Files
 +SectionEnd
 +</code>
 +
 +
 +=== Multiple Files via include ===
 +merge multiple files via **include**
 +
 +This command will include 'file' as if it was part of the original script. Note that if a file is included in another directory, the current directory is still where the script was compiled from (not where the included file resides). If the compiler can't find the file it will look for it in every include directory. See !addincludedir for more information. If the /nonfatal switch is used and no files are found, a warning will be issued instead of an error.
 +
 +
 +
 +<code>
 +!include WinMessages.nsh
 +!include Library.nsh
 +!include C:\MyConfig.nsi
 +!include ..\MyConfig.nsh
 +!include /NONFATAL file_that_may_exist_or_not.nsh
 +</code>
 +
 +
 +Use **!addincludedir** to point to a folder where some NSIS Scripts may be found for inclusion. 
 +
 +
 +=== Variables ===
 +
 +The **$** is prepended to the variables: **$varName** \\
 +Variables are defined once. \\
 +Then they are overridden via **StrCopy** \\
 +
 +
 +**Example**
 +<code>
 +Var example
 +
 +Function testVar
 +  Var /GLOBAL example2
 +
 +  StrCpy $example "example value"
 +  StrCpy $example2 "another example value"
 +FunctionEnd
 +
 +</code>
 +
 +
 +
 +==== Sections ====
 +
 +The script is devided in sections. 
 +Each section matches a logical unit - a logical unit. E.g. a decision, a set of commands etc.
 +
 +<code>
 +# Installer sections
 +Section /o Sales SEC0000
 +    SetOutPath $INSTDIR
 +    SetOverwrite on
 +    File "componentDummyFiles\sales.txt"
 +SectionEnd
 +
 +Section Tariff SEC0001
 +    SetOutPath $INSTDIR
 +    SetOverwrite on
 +    File "componentDummyFiles\tariff.txt"
 +SectionEnd
 +
 +Section  /o Customer SEC0002
 +    SetOutPath $INSTDIR
 +    SetOverwrite on
 +    File "componentDummyFiles\customer.txt"
 +SectionEnd
 +
 +Function .onSelChange
 +  MessageBox MB_OK "onSelChange"
 +FunctionEnd
 +</code>
 +
 +Rendered as checkboxes:
 +
 +{{http://i520.photobucket.com/albums/w327/schajtan/2014-12-09_13-46-46_zpsd25039ed.png}}
 +
 +you may implement callbacks which are triggered when the seleciton is changed.
 +
 +<code>
 +Function .onSelChange
 +  MessageBox MB_OK "onSelChange"
 +FunctionEnd
 +
 +</code>
 +
 +you may change the state of checkboxes programmatically:
 +<code>
 +; executed on initialization of wizard
 +Function .onInit
 +  
 +  IfSilent 0 silentCodeEnd ; executed in silent mode only 
 +    !insertmacro SetSectionFlag ${SEC0000} ${SF_SELECTED}
 +    !insertmacro SetSectionFlag ${SEC0001} ${SF_SELECTED}
 +    !insertmacro SetSectionFlag ${SEC0002} ${SF_SELECTED}
 +  silentCodeEnd: ; silent block ENDS here
 +  
 +FunctionEnd
 +</code>