Util.nsh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. ; ---------------------
  2. ; Util.nsh
  3. ; ---------------------
  4. ;
  5. ; Voodoo macros to make end-user usage easier. This may be documented someday.
  6. !verbose push 3
  7. !ifndef ___UTIL__NSH___
  8. !define ___UTIL__NSH___
  9. # CallArtificialFunction, see WinVer.nsh and *Func.nsh for usage examples
  10. !macro CallArtificialFunctionHelper TYPE NAME
  11. !verbose pop
  12. Call :.${NAME}${TYPE}
  13. !ifndef ${NAME}${TYPE}_DEFINED
  14. !verbose push 2
  15. Goto ${NAME}${TYPE}_DONE
  16. !define ${NAME}${TYPE}_DEFINED
  17. !verbose pop
  18. .${NAME}${TYPE}:
  19. !insertmacro ${NAME}
  20. Return
  21. ${NAME}${TYPE}_DONE:
  22. !endif
  23. !verbose push 2
  24. !macroend
  25. !macro CallArtificialFunction NAME
  26. !verbose push 2
  27. !ifdef __UNINSTALL__
  28. !insertmacro CallArtificialFunctionHelper uninst ${NAME}
  29. !else
  30. !insertmacro CallArtificialFunctionHelper inst ${NAME}
  31. !endif
  32. !verbose pop
  33. !macroend
  34. !define CallArtificialFunction `!insertmacro CallArtificialFunction`
  35. !macro CallArtificialFunction2 NAME ; Retained for v2.4x..v3.0b0 compatibility
  36. ${CallArtificialFunction} ${NAME}
  37. !macroend
  38. !define CallArtificialFunction2 `!insertmacro CallArtificialFunction`
  39. !define Int32Op '!insertmacro Int32Op '
  40. !define Int64Op '!insertmacro Int64Op '
  41. !define IntPtrOp '!insertmacro IntPtrOp '
  42. !macro Int32Op r a o b
  43. IntOp `${r}` `${a}` `${o}` ${b}
  44. !macroend
  45. !macro Int64Op r a o b
  46. !echo "Int64Op ${r}=${a}${o}${b}"
  47. !verbose push 2
  48. System::Int64Op `${a}` `${o}` ${b}
  49. Pop ${r}
  50. !verbose pop
  51. !macroend
  52. !macro IntPtrOp r a o b
  53. IntPtrOp `${r}` `${a}` `${o}` `${b}`
  54. !macroend
  55. !define Int32Cmp '!insertmacro Int32Cmp '
  56. !define Int64Cmp '!insertmacro Int64Cmp '
  57. !define IntPtrCmp '!insertmacro IntPtrCmp '
  58. !macro Int32Cmp a b jeek jles jgtr
  59. IntCmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  60. !macroend
  61. !macro Int64Cmp a b jeek jles jgtr
  62. !if ${NSIS_PTR_SIZE} <= 4
  63. !ifmacrondef _LOGICLIB_TEMP
  64. !include LogicLib.nsh
  65. !endif
  66. !echo "Int64Cmp ${a}:${b} =${jeek}, <${jles}, >${jgtr}"
  67. !verbose push 2
  68. ${IfThen} ${a} L= ${b} ${|} Goto ${jeek} ${|}
  69. !insertmacro _L< ${a} ${b} `${jles}` `${jgtr}`
  70. !verbose pop
  71. !else
  72. Int64Cmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  73. !endif
  74. !macroend
  75. !macro IntPtrCmp a b jeek jles jgtr
  76. IntPtrCmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  77. !macroend
  78. !define Int32CmpU '!insertmacro Int32CmpU '
  79. !define Int64CmpU '!insertmacro Int64CmpU '
  80. !define IntPtrCmpU '!insertmacro IntPtrCmpU '
  81. !macro Int32CmpU a b jeek jles jgtr
  82. IntCmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  83. !macroend
  84. !macro Int64CmpUHelper
  85. ; This macro performs "$_LOGICLIB_TEMP = a < b ? -1 : a > b ? 1 : 0" but System::Int64Op does not support unsigned operations so we have to perform multiple steps
  86. !ifmacrondef _LOGICLIB_TEMP
  87. !include LogicLib.nsh
  88. !endif
  89. !insertmacro _LOGICLIB_TEMP
  90. Exch $2 ; b
  91. Exch
  92. Exch $1 ; a
  93. ; if (a == b) return 0;
  94. ; if (a < 0)
  95. ; {
  96. ; if (b >= 0) return 1
  97. ; }
  98. ; else
  99. ; {
  100. ; if (b < 0) return -1
  101. ; }
  102. ; return a < b ? -1 : 1
  103. System::Int64Op $1 ^ $2 ; Using xor so $_LOGICLIB_TEMP ends up as 0 when they are equal
  104. Pop $_LOGICLIB_TEMP
  105. StrCmp $_LOGICLIB_TEMP 0 ret ; NOTE: Must use StrCmp, IntCmp fails on "0x8000000000000001 Z> 1"
  106. System::Int64Op $1 < 0
  107. Pop $_LOGICLIB_TEMP
  108. StrCmp $_LOGICLIB_TEMP 0 checkNegOther
  109. System::Int64Op $2 < 0 ; System::Int64Op does not support the >= operator so we invert the operation
  110. Pop $_LOGICLIB_TEMP
  111. StrCmp $_LOGICLIB_TEMP 0 retPos finalCmp
  112. retPos:
  113. StrCpy $_LOGICLIB_TEMP "1"
  114. Goto ret
  115. checkNegOther:
  116. System::Int64Op $2 < 0
  117. Pop $_LOGICLIB_TEMP
  118. StrCmp $_LOGICLIB_TEMP 0 finalCmp retNeg
  119. retNeg:
  120. StrCpy $_LOGICLIB_TEMP "-1"
  121. Goto ret
  122. finalCmp:
  123. System::Int64Op $1 < $2
  124. Pop $_LOGICLIB_TEMP
  125. StrCmp $_LOGICLIB_TEMP 0 retPos retNeg
  126. ret:
  127. Pop $1
  128. Pop $2
  129. !macroend
  130. !macro Int64CmpU a b jeek jles jgtr
  131. !if ${NSIS_PTR_SIZE} <= 4
  132. !echo "Int64CmpU ${a}:${b} =${jeek}, <${jles}, >${jgtr}"
  133. !verbose push 2
  134. Push `${a}`
  135. Push `${b}`
  136. !insertmacro CallArtificialFunction Int64CmpUHelper
  137. IntCmp $_LOGICLIB_TEMP 0 `${jeek}` `${jles}` `${jgtr}`
  138. !verbose pop
  139. !else
  140. Int64CmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  141. !endif
  142. !macroend
  143. !macro IntPtrCmpU a b jeek jles jgtr
  144. IntPtrCmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}`
  145. !macroend
  146. !define MakeARPInstallDate "!insertmacro MakeARPInstallDate "
  147. !macro MakeARPInstallDate _outvar
  148. System::Call 'KERNEL32::GetDateFormat(i0x409,i0,p0,t"yyyyMMdd",t.s,i${NSIS_MAX_STRLEN})'
  149. Pop ${_outvar}
  150. !macroend
  151. !define /IfNDef SPI_GETHIGHCONTRAST 0x42
  152. !define /IfNDef HCF_HIGHCONTRASTON 0x01
  153. !define /IfNDef /math SYSSIZEOF_HIGHCONTRAST 8 + ${NSIS_PTR_SIZE}
  154. !define IsHighContrastModeActive '"" IsHighContrastModeActive ""'
  155. !macro _IsHighContrastModeActive _lhs _rhs _t _f
  156. !ifmacrondef _LOGICLIB_TEMP
  157. !include LogicLib.nsh
  158. !endif
  159. !insertmacro _LOGICLIB_TEMP
  160. Push $1
  161. System::Call '*(i${SYSSIZEOF_HIGHCONTRAST},i0,p)p.r1'
  162. System::Call 'USER32::SystemParametersInfo(i${SPI_GETHIGHCONTRAST},i${SYSSIZEOF_HIGHCONTRAST},pr1,i0)'
  163. System::Call '*$1(i,i.s)'
  164. Pop $_LOGICLIB_TEMP
  165. System::Free $1
  166. Pop $1
  167. !insertmacro _& $_LOGICLIB_TEMP ${HCF_HIGHCONTRASTON} `${_t}` `${_f}`
  168. !macroend
  169. !endif # !___UTIL__NSH___
  170. !verbose pop