home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Include / Sections.nsh < prev    next >
Encoding:
Text File  |  2007-12-01  |  5.8 KB  |  273 lines

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