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