Sections.nsh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. ; Sections.nsh
  2. ;
  3. ; Defines and macros for section control
  4. ;
  5. ; Include in your script using:
  6. ; !include "Sections.nsh"
  7. ;--------------------------------
  8. !ifndef SECTIONS_INCLUDED
  9. !define SECTIONS_INCLUDED
  10. ;--------------------------------
  11. ; Generic section defines
  12. # section or section group is selected
  13. !define SF_SELECTED 1
  14. # section group
  15. !define SF_SECGRP 2
  16. !define SF_SUBSEC 2 # deprecated
  17. # section group end marker
  18. !define SF_SECGRPEND 4
  19. !define SF_SUBSECEND 4 # deprecated
  20. # bold text (Section !blah)
  21. !define SF_BOLD 8
  22. # read only (SectionIn RO)
  23. !define SF_RO 16
  24. # expanded section group (SectionGroup /e blah)
  25. !define SF_EXPAND 32
  26. # section group is partially selected
  27. !define SF_PSELECTED 64 # internal
  28. # internal
  29. !define SF_TOGGLED 128 # internal
  30. !define SF_NAMECHG 256 # internal
  31. # mask to toggle off the selected flag
  32. !define SECTION_OFF 0xFFFFFFFE
  33. ;--------------------------------
  34. ; Select / unselect / reserve section
  35. !macro SelectSection SECTION
  36. Push $0
  37. Push $1
  38. StrCpy $1 "${SECTION}"
  39. SectionGetFlags $1 $0
  40. IntOp $0 $0 | ${SF_SELECTED}
  41. SectionSetFlags $1 $0
  42. Pop $1
  43. Pop $0
  44. !macroend
  45. !macro UnselectSection SECTION
  46. Push $0
  47. Push $1
  48. StrCpy $1 "${SECTION}"
  49. SectionGetFlags $1 $0
  50. IntOp $0 $0 & ${SECTION_OFF}
  51. SectionSetFlags $1 $0
  52. Pop $1
  53. Pop $0
  54. !macroend
  55. ; If section selected, will unselect, if unselected, will select
  56. !macro ReverseSection SECTION
  57. Push $0
  58. Push $1
  59. StrCpy $1 "${SECTION}"
  60. SectionGetFlags $1 $0
  61. IntOp $0 $0 ^ ${SF_SELECTED}
  62. SectionSetFlags $1 $0
  63. Pop $1
  64. Pop $0
  65. !macroend
  66. ;--------------------------------
  67. ; Macros for mutually exclusive section selection
  68. ; Written by Tim Gallagher
  69. ;
  70. ; See one-section.nsi for an example of usage
  71. ; Starts the Radio Button Block
  72. ; You should pass a variable that keeps the selected section
  73. ; as the first parameter for this macro. This variable should
  74. ; be initialized to the default section's index.
  75. ;
  76. ; As this macro uses $R0 and $R1 you can't use those two as the
  77. ; varible which will keep the selected section.
  78. !macro StartRadioButtons var
  79. !define StartRadioButtons_Var "${var}"
  80. Push $R0
  81. SectionGetFlags "${StartRadioButtons_Var}" $R0
  82. IntOp $R0 $R0 & ${SECTION_OFF}
  83. SectionSetFlags "${StartRadioButtons_Var}" $R0
  84. Push $R1
  85. StrCpy $R1 "${StartRadioButtons_Var}"
  86. !macroend
  87. ; A radio button
  88. !macro RadioButton SECTION_NAME
  89. SectionGetFlags ${SECTION_NAME} $R0
  90. IntOp $R0 $R0 & ${SF_SELECTED}
  91. IntCmp $R0 ${SF_SELECTED} 0 +2 +2
  92. StrCpy "${StartRadioButtons_Var}" ${SECTION_NAME}
  93. !macroend
  94. ; Ends the radio button block
  95. !macro EndRadioButtons
  96. StrCmp $R1 "${StartRadioButtons_Var}" 0 +4 ; selection hasn't changed
  97. SectionGetFlags "${StartRadioButtons_Var}" $R0
  98. IntOp $R0 $R0 | ${SF_SELECTED}
  99. SectionSetFlags "${StartRadioButtons_Var}" $R0
  100. Pop $R1
  101. Pop $R0
  102. !undef StartRadioButtons_Var
  103. !macroend
  104. ;--------------------------------
  105. ; These are two macros you can use to set a Section in an InstType
  106. ; or clear it from an InstType.
  107. ;
  108. ; Written by Robert Kehl
  109. ;
  110. ; For details, see http://nsis.sourceforge.net/wiki/SetSectionInInstType%2C_ClearSectionInInstType
  111. ;
  112. ; Use the defines below for the WANTED_INSTTYPE parameter.
  113. !define INSTTYPE_1 1
  114. !define INSTTYPE_2 2
  115. !define INSTTYPE_3 4
  116. !define INSTTYPE_4 8
  117. !define INSTTYPE_5 16
  118. !define INSTTYPE_6 32
  119. !define INSTTYPE_7 64
  120. !define INSTTYPE_8 128
  121. !define INSTTYPE_9 256
  122. !define INSTTYPE_10 512
  123. !define INSTTYPE_11 1024
  124. !define INSTTYPE_12 2048
  125. !define INSTTYPE_13 4096
  126. !define INSTTYPE_14 8192
  127. !define INSTTYPE_15 16384
  128. !define INSTTYPE_16 32768
  129. !define INSTTYPE_17 65536
  130. !define INSTTYPE_18 131072
  131. !define INSTTYPE_19 262144
  132. !define INSTTYPE_20 524288
  133. !define INSTTYPE_21 1048576
  134. !define INSTTYPE_22 2097152
  135. !define INSTTYPE_23 4194304
  136. !define INSTTYPE_24 8388608
  137. !define INSTTYPE_25 16777216
  138. !define INSTTYPE_26 33554432
  139. !define INSTTYPE_27 67108864
  140. !define INSTTYPE_28 134217728
  141. !define INSTTYPE_29 268435456
  142. !define INSTTYPE_30 536870912
  143. !define INSTTYPE_31 1073741824
  144. !define INSTTYPE_32 2147483648
  145. !macro SetSectionInInstType SECTION_NAME WANTED_INSTTYPE
  146. Push $0
  147. Push $1
  148. StrCpy $1 "${SECTION_NAME}"
  149. SectionGetInstTypes $1 $0
  150. IntOp $0 $0 | ${WANTED_INSTTYPE}
  151. SectionSetInstTypes $1 $0
  152. Pop $1
  153. Pop $0
  154. !macroend
  155. !macro ClearSectionInInstType SECTION_NAME WANTED_INSTTYPE
  156. Push $0
  157. Push $1
  158. Push $2
  159. StrCpy $2 "${SECTION_NAME}"
  160. SectionGetInstTypes $2 $0
  161. StrCpy $1 ${WANTED_INSTTYPE}
  162. IntOp $1 $1 ~
  163. IntOp $0 $0 & $1
  164. SectionSetInstTypes $2 $0
  165. Pop $2
  166. Pop $1
  167. Pop $0
  168. !macroend
  169. ;--------------------------------
  170. ; Set / clear / check bits in a section's flags
  171. ; Written by derekrprice
  172. ; Set one or more bits in a sections's flags
  173. !macro SetSectionFlag SECTION BITS
  174. Push $R0
  175. Push $R1
  176. StrCpy $R1 "${SECTION}"
  177. SectionGetFlags $R1 $R0
  178. IntOp $R0 $R0 | "${BITS}"
  179. SectionSetFlags $R1 $R0
  180. Pop $R1
  181. Pop $R0
  182. !macroend
  183. ; Clear one or more bits in section's flags
  184. !macro ClearSectionFlag SECTION BITS
  185. Push $R0
  186. Push $R1
  187. Push $R2
  188. StrCpy $R2 "${SECTION}"
  189. SectionGetFlags $R2 $R0
  190. IntOp $R1 "${BITS}" ~
  191. IntOp $R0 $R0 & $R1
  192. SectionSetFlags $R2 $R0
  193. Pop $R2
  194. Pop $R1
  195. Pop $R0
  196. !macroend
  197. ; Check if one or more bits in section's flags are set
  198. ; If they are, jump to JUMPIFSET
  199. ; If not, jump to JUMPIFNOTSET
  200. !macro SectionFlagIsSet SECTION BITS JUMPIFSET JUMPIFNOTSET
  201. Push $R0
  202. SectionGetFlags "${SECTION}" $R0
  203. IntOp $R0 $R0 & "${BITS}"
  204. IntCmp $R0 "${BITS}" +3
  205. Pop $R0
  206. StrCmp "" "${JUMPIFNOTSET}" +3 "${JUMPIFNOTSET}"
  207. Pop $R0
  208. Goto "${JUMPIFSET}"
  209. !macroend
  210. ;--------------------------------
  211. ; Removes a section by unselecting and hiding it
  212. !macro RemoveSection SECTION
  213. Push $R0
  214. Push $R1
  215. StrCpy $R1 `${SECTION}`
  216. SectionGetFlags $R1 $R0
  217. IntOp $R0 $R0 & ${SECTION_OFF}
  218. SectionSetFlags $R1 $R0
  219. SectionSetText $R1 ``
  220. Pop $R1
  221. Pop $R0
  222. !macroend
  223. ; Undoes the RemoveSection action
  224. !macro UnremoveSection SECTION SECTION_TEXT
  225. Push $R0
  226. Push $R1
  227. Push $R2
  228. StrCpy $R1 `${SECTION}`
  229. StrCpy $R2 `${SECTION_TEXT}`
  230. SectionGetFlags $R1 $R0
  231. IntOp $R0 $R0 | ${SF_SELECTED}
  232. SectionSetFlags $R1 $R0
  233. SectionSetText $R1 $R2
  234. Pop $R2
  235. Pop $R1
  236. Pop $R0
  237. !macroend
  238. ;--------------------------------
  239. !endif