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