SysFunc.nsh 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. ; Some useful functions based on System plugin
  2. ;
  3. ; (c) brainsucker, 2002
  4. ; (r) BSForce
  5. !verbose push 3
  6. !ifndef SysFunc.NSH.Included
  7. !define SysFunc.NSH.Included
  8. !include "System.nsh"
  9. !include "WinMessages.nsh"
  10. ; ================= GetInstallerExeName implementation =================
  11. ; Adopted Get Parameter function -> now it gets full installer.exe path
  12. ; input - nothing, output -> full path at the top of the stack
  13. Function GetInstallerExeName
  14. Push $R0
  15. Push $R1
  16. Push $R2
  17. StrCpy $R0 $CMDLINE 1
  18. StrCpy $R1 '"'
  19. StrCpy $R2 1
  20. StrCmp $R0 '"' loop
  21. StrCpy $R1 ' ' ; we're scanning for a space instead of a quote
  22. loop:
  23. StrCpy $R0 $CMDLINE 1 $R2
  24. StrCmp $R0 $R1 loop2
  25. StrCmp $R0 "" loop2
  26. IntOp $R2 $R2 + 1
  27. Goto loop
  28. loop2:
  29. ; Ok, have we found last exename character or string end?
  30. StrCmp $R0 "" "" +2
  31. IntOp $R2 $R2 - 1 ; last exename char
  32. StrCmp $R1 ' ' +3 ; was first character the '"', or something other?
  33. StrCpy $R1 1 ; it was quote
  34. Goto +2
  35. StrCpy $R1 0
  36. IntOp $R2 $R2 - $R1
  37. StrCpy $R0 $CMDLINE $R2 $R1
  38. SearchPath $R0 $R0 ; expand file name to full path
  39. Pop $R2
  40. Pop $R1
  41. Exch $R0
  42. FunctionEnd
  43. ; ================= systemGetFileSysTime implementation =================
  44. !macro smGetFileSysTime FILENAME
  45. Push ${FILENAME}
  46. Call systemGetFileSysTime
  47. Pop $R0
  48. !macroend
  49. ; -----------------------------------------------------------------
  50. ; systemGetFileSysTime (params on stack):
  51. ; FILENAME - name of file to get file time
  52. ; returns to stack (SYSTEMTIME struct addr)
  53. ; -----------------------------------------------------------------
  54. ; uses original method from NSIS
  55. Function systemGetFileSysTime
  56. System::Store "s r1"
  57. StrCpy $R0 0
  58. ; create WIN32_FIND_DATA struct
  59. System::Call '*${stWIN32_FIND_DATA} .r2'
  60. ; Find file info
  61. System::Call '${sysFindFirstFile}(r1, r2) .r3'
  62. ; ok?
  63. IntCmp $3 ${INVALID_HANDLE_VALUE} sgfst_exit
  64. ; close file search
  65. System::Call '${sysFindClose}(r3)'
  66. ; Create systemtime struct for local time
  67. System::Call '*${stSYSTEMTIME} .R0'
  68. ; Get File time
  69. System::Call '*$2${stWIN32_FIND_DATA} (,,, .r3)'
  70. ; Convert file time (UTC) to local file time
  71. System::Call '${sysFileTimeToLocalFileTime}(r3, .r1)'
  72. ; Convert file time to system time
  73. System::Call '${sysFileTimeToSystemTime}(r1, R0)'
  74. sgfst_exit:
  75. ; free used memory for WIN32_FIND_DATA struct
  76. System::Free $2
  77. System::Store "P0 l"
  78. FunctionEnd
  79. ; ================= systemMessageBox implementation =================
  80. ; return to $R0
  81. !macro smMessageBox MODULE MSG CAPTION STYLE ICON
  82. Push "${ICON}"
  83. Push "${STYLE}"
  84. Push "${CAPTION}"
  85. Push "${MSG}"
  86. Push "${MODULE}"
  87. Call systemMessageBox
  88. Pop $R0
  89. !macroend
  90. ; -----------------------------------------------------------------
  91. ; systemMessageBox (params on stack):
  92. ; Module: either handle ("i HANDLE", HANDLE could be 0) or "modulename"
  93. ; Msg: text of message
  94. ; Caption: caption of message box window
  95. ; Style: style, buttons etc
  96. ; Icon: either icon handle ("i HANDLE") or resource name
  97. ; returns to stack
  98. ; -----------------------------------------------------------------
  99. Function systemMessageBox
  100. System::Store "s r2r3r4r5r6"
  101. ; may be Module is module handle?
  102. StrCpy $1 $2
  103. IntCmp $1 0 0 smbnext smbnext
  104. ; Get module handle
  105. System::Call '${sysGetModuleHandle}($2) .r1'
  106. IntCmp $1 0 loadlib libnotloaded libnotloaded
  107. loadlib:
  108. ; Load module and get handle
  109. System::Call '${sysLoadLibrary}($2) .r1'
  110. IntCmp $1 0 0 smbnext smbnext
  111. libnotloaded:
  112. ; Indicate that LoadLibrary wasn't used
  113. StrCpy $2 1
  114. smbnext:
  115. ; Create MSGBOXPARAMS structure
  116. System::Call '*${stMSGBOXPARAMS}(, $HWNDPARENT, r1, r3, r4, "$5|${MB_USERICON}", $6, _) .r0'
  117. ; call MessageBoxIndirect
  118. System::Call '${sysMessageBoxIndirect}(r0) .R0'
  119. ; free MSGBOXPARAMS structure
  120. System::Free $0
  121. ; have we used load library at start?
  122. IntCmp $2 0 0 smbskipfree smbskipfree
  123. ; No, then free the module
  124. System::Call '${sysFreeLibrary}(r1)'
  125. smbskipfree:
  126. System::Store "P0 l"
  127. FunctionEnd
  128. ; ================= systemSplash implementation =================
  129. ; returns to $R0
  130. !macro smSystemSplash DELAY FILE
  131. Push ${FILE}
  132. Push ${DELAY}
  133. call systemSplash
  134. Pop $R0
  135. !macroend
  136. ; -----------------------------------------------------------------
  137. ; systemSplash (params on stack):
  138. ; Delay - time in ms to show the splash
  139. ; File - bitmap (& audio) file name (without extension)
  140. ; returns to stack
  141. ; -----------------------------------------------------------------
  142. Function _systemSplashWndCB
  143. ; Callback receives 4 values
  144. System::Store "s r2r5r7r9"
  145. ; Message branching
  146. IntCmp $5 ${WM_CLOSE} m_Close
  147. IntCmp $5 ${WM_TIMER} m_Timer
  148. IntCmp $5 ${WM_LBUTTONDOWN} m_Lbtn
  149. IntCmp $5 ${WM_CREATE} m_Create
  150. IntCmp $5 ${WM_PAINT} m_Paint
  151. goto default
  152. m_Create:
  153. ; Create structures
  154. System::Call "*${stRECT} (_) .R8"
  155. System::Call "*${stBITMAP} (_, &l0 .R7) .R9"
  156. ; Get bitmap info
  157. System::Call "${sysGetObject} (r6, R7, R9)"
  158. ; Get desktop info
  159. System::Call "${sysSystemParametersInfo} (${SPI_GETWORKAREA}, 0, R8, 0)"
  160. ; Style (callbacked)
  161. System::Call "${sysSetWindowLong} (r2, ${GWL_STYLE}, 0) .s"
  162. !insertmacro SINGLE_CALLBACK 5 $R7 1 _systemSplashWndCB
  163. ; Calculate and set window pos
  164. ; Get bmWidth(R2) and bmHeight(R3)
  165. System::Call "*$R9${stBITMAP} (,.R2,.R3)"
  166. ; Get left(R4), top(R5), right(R6), bottom(R7)
  167. System::Call "*$R8${stRECT} (.R4,.R5,.R6,.R7)"
  168. ; Left pos
  169. IntOp $R0 $R6 - $R4
  170. IntOp $R0 $R0 - $R2
  171. IntOp $R0 $R0 / 2
  172. IntOp $R0 $R0 + $R4
  173. ; Top pos
  174. IntOp $R1 $R7 - $R5
  175. IntOp $R1 $R1 - $R3
  176. IntOp $R1 $R1 / 2
  177. IntOp $R1 $R1 + $R5
  178. System::Call "${sysSetWindowPos} (r2, 0, R0, R1, R2, R3, ${SWP_NOZORDER}) .s"
  179. !insertmacro SINGLE_CALLBACK 6 $R7 1 _systemSplashWndCB
  180. ; Show window
  181. System::Call "${sysShowWindow} (r2, ${SW_SHOW}) .s"
  182. !insertmacro SINGLE_CALLBACK 7 $R7 1 _systemSplashWndCB
  183. ; Set Timer
  184. System::Call "${sysSetTimer} (r2, 1, r8,)"
  185. ; Free used memory
  186. System::Free $R8
  187. System::Free $R9
  188. StrCpy $R0 0
  189. goto exit
  190. m_Paint:
  191. ; Create structures
  192. System::Call "*${stRECT} (_) .R8"
  193. System::Call "*${stPAINTSTRUCT} (_) .R9"
  194. ; Begin Paint
  195. System::Call "${sysBeginPaint} (r2, R9) .R7"
  196. ; CreateCompatibleDC
  197. System::Call "${sysCreateCompatibleDC} (R7) .R6"
  198. ; GetClientRect
  199. System::Call "${sysGetClientRect} (r2, R8)"
  200. ; Select new bitmap
  201. System::Call "${sysSelectObject} (R6, r6) .R5"
  202. ; Get left(R0), top(R1), right(R2), bottom(R3)
  203. System::Call "*$R8${stRECT} (.R0,.R1,.R2,.R3)"
  204. ; width=right-left
  205. IntOp $R2 $R2 - $R0
  206. ; height=bottom-top
  207. IntOp $R3 $R3 - $R1
  208. System::Call "${sysBitBlt} (R7, R0, R1, R2, R3, R6, 0, 0, ${SRCCOPY})"
  209. ; Select old bitmap
  210. System::Call "${sysSelectObject} (R6, R5)"
  211. ; Delete compatible DC
  212. System::Call "${sysDeleteDC} (R6)"
  213. ; End Paint
  214. System::Call "${sysEndPaint} (r2, R9)"
  215. ; Free used memory
  216. System::Free $R8
  217. System::Free $R9
  218. StrCpy $R0 0
  219. goto exit
  220. m_Timer:
  221. m_Lbtn:
  222. StrCpy $4 0
  223. IntCmp $5 ${WM_TIMER} destroy
  224. StrCpy $4 1
  225. destroy:
  226. System::Call "${sysDestroyWindow} (r2) .s"
  227. !insertmacro SINGLE_CALLBACK 12 $R4 1 _systemSplashWndCB
  228. default:
  229. ; Default
  230. System::Call "${sysDefWindowProc} (r2, r5, r7, r9) .s"
  231. !insertmacro SINGLE_CALLBACK 14 $R0 1 _systemSplashWndCB
  232. goto exit
  233. m_Close:
  234. StrCpy $R0 0
  235. goto exit
  236. exit:
  237. ; Restore
  238. System::Store "p4P0 l R0r4"
  239. ; Return from callback
  240. System::Call "$3" $R0
  241. FunctionEnd
  242. Function systemSplash
  243. ; Save registers and get input
  244. System::Store "s r8r9"
  245. ; Get module instance
  246. System::Call "${sysGetModuleHandle} (p) .r7"
  247. ; Get arrow cursor
  248. System::Call "${sysLoadCursor} (0, p ${IDC_ARROW}) .R9"
  249. ; Get callback
  250. System::Get "${sysWNDPROC}"
  251. Pop $3
  252. ; Create window class
  253. System::Call "*${stWNDCLASS} (0,r3,0,0,r7,0,R9,0,p 0,'_sp') .R9"
  254. ; Register window class
  255. System::Call "${sysRegisterClass} (R9) .R9"
  256. IntCmp $R9 0 errorexit ; Class registered ok?
  257. ; Load Image (LR_CREATEDIBSECTION|LR_LOADFROMFILE = 0x2010)
  258. System::Call '${sysLoadImage} (, s, ${IMAGE_BITMAP}, 0, 0, ${LR_CREATEDIBSECTION}|${LR_LOADFROMFILE}) .r6' "$9.bmp"
  259. IntCmp $6 0 errorexit ; Image loaded ok?
  260. ; Start the sound (SND_ASYNC|SND_FILENAME|SND_NODEFAULT = 0x20003)
  261. System::Call "${sysPlaySound} (s,,${SND_ASYNC}|${SND_FILENAME}|${SND_NODEFAULT})" "$9.wav"
  262. ; Create window
  263. System::Call "${sysCreateWindowEx} (${WS_EX_TOOLWINDOW}, s, s,,,,,, $HWNDPARENT,,r7,) .s" "_sp" "_sp"
  264. !insertmacro SINGLE_CALLBACK 1 $5 1 _systemSplashWndCB
  265. ; Create MSG struct
  266. System::Call "*${stMSG} (_) p.R9"
  267. ; -------------------------
  268. repeat:
  269. ; Check for window
  270. System::Call "${sysIsWindow} (r5) .s"
  271. !insertmacro SINGLE_CALLBACK 2 $R8 1 _systemSplashWndCB
  272. IntCmp $R8 0 finish
  273. ; Get message
  274. System::Call "${sysGetMessage} (R9, r5,_) .s"
  275. !insertmacro SINGLE_CALLBACK 3 $R8 1 _systemSplashWndCB
  276. IntCmp $R8 0 finish
  277. ; Dispatch message
  278. System::Call "${sysDispatchMessage} (R9) .s"
  279. !insertmacro SINGLE_CALLBACK 4 $R8 1 _systemSplashWndCB
  280. ; Repeat dispatch cycle
  281. goto repeat
  282. ; -------------------------
  283. finish:
  284. ; Stop the sound
  285. System::Call "${sysPlaySound} (p 0, p 0, i 0)"
  286. ; Delete bitmap object
  287. System::Call "${sysDeleteObject} (r6)"
  288. ; Delete the callback queue
  289. System::Free $3
  290. ; Dialog return
  291. StrCpy $R0 $4
  292. goto exit
  293. ; Exit in case of error
  294. errorexit:
  295. StrCpy $R0 -1
  296. goto exit
  297. exit:
  298. ; Restore register and put output
  299. System::Store "P0 l"
  300. FunctionEnd
  301. !endif
  302. !verbose pop