| 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 |
IntOp `${r}` `${a}` `${o}` ${b} |
| 50 |
!macroend |
| 51 |
!macro Int64Op r a o b |
| 52 |
!echo "Int64Op ${r}=${a}${o}${b}" |
| 53 |
!verbose push 2 |
| 54 |
System::Int64Op `${a}` `${o}` ${b} |
| 55 |
Pop ${r} |
| 56 |
!verbose pop |
| 57 |
!macroend |
| 58 |
!macro IntPtrOp r a o b |
| 59 |
IntPtrOp `${r}` `${a}` `${o}` `${b}` |
| 60 |
!macroend |
| 61 |
|
| 62 |
!define Int32Cmp '!insertmacro Int32Cmp ' |
| 63 |
!define Int64Cmp '!insertmacro Int64Cmp ' |
| 64 |
!define IntPtrCmp '!insertmacro IntPtrCmp ' |
| 65 |
!macro Int32Cmp a b jeek jles jgtr |
| 66 |
IntCmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 67 |
!macroend |
| 68 |
!macro Int64Cmp a b jeek jles jgtr |
| 69 |
!if ${NSIS_PTR_SIZE} <= 4 |
| 70 |
!ifmacrondef _LOGICLIB_TEMP |
| 71 |
!include LogicLib.nsh |
| 72 |
!endif |
| 73 |
!echo "Int64Cmp ${a}:${b} =${jeek}, <${jles}, >${jgtr}" |
| 74 |
!verbose push 2 |
| 75 |
${IfThen} ${a} L= ${b} ${|} Goto ${jeek} ${|} |
| 76 |
!insertmacro _L< ${a} ${b} `${jles}` `${jgtr}` |
| 77 |
!verbose pop |
| 78 |
!else |
| 79 |
Int64Cmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 80 |
!endif |
| 81 |
!macroend |
| 82 |
!macro IntPtrCmp a b jeek jles jgtr |
| 83 |
IntPtrCmp `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 84 |
!macroend |
| 85 |
|
| 86 |
!define Int32CmpU '!insertmacro Int32CmpU ' |
| 87 |
!define Int64CmpU '!insertmacro Int64CmpU ' |
| 88 |
!define IntPtrCmpU '!insertmacro IntPtrCmpU ' |
| 89 |
!macro Int32CmpU a b jeek jles jgtr |
| 90 |
IntCmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 91 |
!macroend |
| 92 |
!macro Int64CmpUHelper |
| 93 |
; 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 |
| 94 |
!ifmacrondef _LOGICLIB_TEMP |
| 95 |
!include LogicLib.nsh |
| 96 |
!endif |
| 97 |
!insertmacro _LOGICLIB_TEMP |
| 98 |
Exch $2 ; b |
| 99 |
Exch |
| 100 |
Exch $1 ; a |
| 101 |
; if (a == b) return 0; |
| 102 |
; if (a < 0) |
| 103 |
; { |
| 104 |
; if (b >= 0) return 1 |
| 105 |
; } |
| 106 |
; else |
| 107 |
; { |
| 108 |
; if (b < 0) return -1 |
| 109 |
; } |
| 110 |
; return a < b ? -1 : 1 |
| 111 |
System::Int64Op $1 ^ $2 ; Using xor so $_LOGICLIB_TEMP ends up as 0 when they are equal |
| 112 |
Pop $_LOGICLIB_TEMP |
| 113 |
StrCmp $_LOGICLIB_TEMP 0 ret ; NOTE: Must use StrCmp, IntCmp fails on "0x8000000000000001 Z> 1" |
| 114 |
System::Int64Op $1 < 0 |
| 115 |
Pop $_LOGICLIB_TEMP |
| 116 |
StrCmp $_LOGICLIB_TEMP 0 checkNegOther |
| 117 |
System::Int64Op $2 < 0 ; System::Int64Op does not support the >= operator so we invert the operation |
| 118 |
Pop $_LOGICLIB_TEMP |
| 119 |
StrCmp $_LOGICLIB_TEMP 0 retPos finalCmp |
| 120 |
retPos: |
| 121 |
StrCpy $_LOGICLIB_TEMP "1" |
| 122 |
Goto ret |
| 123 |
checkNegOther: |
| 124 |
System::Int64Op $2 < 0 |
| 125 |
Pop $_LOGICLIB_TEMP |
| 126 |
StrCmp $_LOGICLIB_TEMP 0 finalCmp retNeg |
| 127 |
retNeg: |
| 128 |
StrCpy $_LOGICLIB_TEMP "-1" |
| 129 |
Goto ret |
| 130 |
finalCmp: |
| 131 |
System::Int64Op $1 < $2 |
| 132 |
Pop $_LOGICLIB_TEMP |
| 133 |
StrCmp $_LOGICLIB_TEMP 0 retPos retNeg |
| 134 |
ret: |
| 135 |
Pop $1 |
| 136 |
Pop $2 |
| 137 |
!macroend |
| 138 |
!macro Int64CmpU a b jeek jles jgtr |
| 139 |
!if ${NSIS_PTR_SIZE} <= 4 |
| 140 |
!echo "Int64CmpU ${a}:${b} =${jeek}, <${jles}, >${jgtr}" |
| 141 |
!verbose push 2 |
| 142 |
Push `${a}` |
| 143 |
Push `${b}` |
| 144 |
!insertmacro CallArtificialFunction Int64CmpUHelper |
| 145 |
IntCmp $_LOGICLIB_TEMP 0 `${jeek}` `${jles}` `${jgtr}` |
| 146 |
!verbose pop |
| 147 |
!else |
| 148 |
Int64CmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 149 |
!endif |
| 150 |
!macroend |
| 151 |
!macro IntPtrCmpU a b jeek jles jgtr |
| 152 |
IntPtrCmpU `${a}` `${b}` `${jeek}` `${jles}` `${jgtr}` |
| 153 |
!macroend |
| 154 |
|
| 155 |
|
| 156 |
!define MakeARPInstallDate "!insertmacro MakeARPInstallDate " |
| 157 |
!macro MakeARPInstallDate _outvar |
| 158 |
System::Call 'KERNEL32::GetDateFormat(i0x409,i0,p0,t"yyyyMMdd",t.s,i${NSIS_MAX_STRLEN})' |
| 159 |
Pop ${_outvar} |
| 160 |
!macroend |
| 161 |
|
| 162 |
|
| 163 |
!define /IfNDef SPI_GETHIGHCONTRAST 0x42 |
| 164 |
!define /IfNDef HCF_HIGHCONTRASTON 0x01 |
| 165 |
!define /IfNDef /math SYSSIZEOF_HIGHCONTRAST 8 + ${NSIS_PTR_SIZE} |
| 166 |
!define IsHighContrastModeActive '"" IsHighContrastModeActive ""' |
| 167 |
!macro _IsHighContrastModeActive _lhs _rhs _t _f |
| 168 |
!ifmacrondef _LOGICLIB_TEMP |
| 169 |
!include LogicLib.nsh |
| 170 |
!endif |
| 171 |
!insertmacro _LOGICLIB_TEMP |
| 172 |
Push $1 |
| 173 |
System::Call '*(i${SYSSIZEOF_HIGHCONTRAST},i0,p)p.r1' |
| 174 |
System::Call 'USER32::SystemParametersInfo(i${SPI_GETHIGHCONTRAST},i${SYSSIZEOF_HIGHCONTRAST},pr1,i0)' |
| 175 |
System::Call '*$1(i,i.s)' |
| 176 |
Pop $_LOGICLIB_TEMP |
| 177 |
System::Free $1 |
| 178 |
Pop $1 |
| 179 |
!insertmacro _& $_LOGICLIB_TEMP ${HCF_HIGHCONTRASTON} `${_t}` `${_f}` |
| 180 |
!macroend |
| 181 |
|
| 182 |
|
| 183 |
!endif # !___UTIL__NSH___ |
| 184 |
!verbose pop |