Debian Codegraph @

Contrib/System/SysFunc.nsh

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