Debian Codegraph @

Examples/FileFuncTest.nsi

raw
1 ;_____________________________________________________________________________
2 ;
3 ; File Functions Test
4 ;_____________________________________________________________________________
5 ;
6 ; 2006 Shengalts Aleksander aka Instructor ([email protected])
7
8 Name "File Functions Test"
9 OutFile "FileFuncTest.exe"
10 Caption "$(^Name)"
11 ShowInstDetails show
12 XPStyle on
13 RequestExecutionLevel user
14
15 Var FUNCTION
16 Var OUT1
17 Var OUT2
18 Var OUT3
19 Var OUT4
20 Var OUT5
21 Var OUT6
22 Var OUT7
23
24 !include "FileFunc.nsh"
25 !include "LogicLib.nsh"
26
27 ;############### INSTALL ###############
28
29 !define StackVerificationStart `!insertmacro StackVerificationStart`
30 !macro StackVerificationStart _FUNCTION
31 StrCpy $FUNCTION ${_FUNCTION}
32 Call StackVerificationStart
33 !macroend
34
35 !define StackVerificationEnd `!insertmacro StackVerificationEnd`
36 !macro StackVerificationEnd
37 Call StackVerificationEnd
38 !macroend
39
40 Function StackVerificationStart
41 StrCpy $0 !0
42 StrCpy $1 !1
43 StrCpy $2 !2
44 StrCpy $3 !3
45 StrCpy $4 !4
46 StrCpy $5 !5
47 StrCpy $6 !6
48 StrCpy $7 !7
49 StrCpy $8 !8
50 StrCpy $9 !9
51 StrCpy $R0 !R0
52 StrCpy $R1 !R1
53 StrCpy $R2 !R2
54 StrCpy $R3 !R3
55 StrCpy $R4 !R4
56 StrCpy $R5 !R5
57 StrCpy $R6 !R6
58 StrCpy $R7 !R7
59 StrCpy $R8 !R8
60 StrCpy $R9 !R9
61 FunctionEnd
62
63 Function StackVerificationEnd
64 IfErrors +3
65 DetailPrint 'PASSED $FUNCTION no errors'
66 goto +2
67 DetailPrint 'FAILED $FUNCTION error'
68
69 StrCmp $0 '!0' 0 error
70 StrCmp $1 '!1' 0 error
71 StrCmp $2 '!2' 0 error
72 StrCmp $3 '!3' 0 error
73 StrCmp $4 '!4' 0 error
74 StrCmp $5 '!5' 0 error
75 StrCmp $6 '!6' 0 error
76 StrCmp $7 '!7' 0 error
77 StrCmp $8 '!8' 0 error
78 StrCmp $9 '!9' 0 error
79 StrCmp $R0 '!R0' 0 error
80 StrCmp $R1 '!R1' 0 error
81 StrCmp $R2 '!R2' 0 error
82 StrCmp $R3 '!R3' 0 error
83 StrCmp $R4 '!R4' 0 error
84 StrCmp $R5 '!R5' 0 error
85 StrCmp $R6 '!R6' 0 error
86 StrCmp $R7 '!R7' 0 error
87 StrCmp $R8 '!R8' 0 error
88 StrCmp $R9 '!R9' 0 error
89 DetailPrint 'PASSED $FUNCTION stack'
90 goto end
91
92 error:
93 DetailPrint 'FAILED $FUNCTION stack'
94 ; MessageBox MB_OKCANCEL '$$0={$0}$\n$$1={$1}$\n$$2={$2}$\n$$3={$3}$\n$$4={$4}$\n$$5={$5}$\n$$6={$6}$\n$$7={$7}$\n$$8={$8}$\n$$9={$9}$\n$$R0={$R0}$\n$$R1={$R1}$\n$$R2={$R2}$\n$$R3={$R3}$\n$$R4={$R4}$\n$$R5={$R5}$\n$$R6={$R6}$\n$$R7={$R7}$\n$$R8={$R8}$\n$$R9={$R9}' IDOK +2
95 ; quit
96
97 end:
98 FunctionEnd
99
100
101
102 Section Locate
103 ${StackVerificationStart} Locate
104
105 ${Locate} '$DOCUMENTS' '/L=FD /M=*.* /S=0B /G=0' 'LocateCallback'
106
107 ${StackVerificationEnd}
108 SectionEnd
109
110 Function LocateCallback
111 ; MessageBox MB_YESNO '$$0={$0}$\n$$1={$1}$\n$$2={$2}$\n$$3={$3}$\n$$4={$4}$\n$$5={$5}$\n$$6={$6}$\n$$7={$7}$\n$$8={$8}$\n$$9={$9}$\n$$R0={$R0}$\n$$R1={$R1}$\n$$R2={$R2}$\n$$R3={$R3}$\n$$R4={$R4}$\n$$R5={$R5}$\n$$R6={$R6}$\n$$R7={$R7}$\n$$R8={$R8}$\n$$R9={$R9}$\n$\nContinue?' IDYES +2
112 ; StrCpy $0 StopLocate
113
114 Push $0
115 FunctionEnd
116
117
118 Section GetSize
119 ${StackVerificationStart} GetSize
120
121 ${GetSize} '$WINDIR' '/M=Explorer.exe /S=0K /G=0' $OUT1 $OUT2 $OUT3
122
123 ${StackVerificationEnd}
124 SectionEnd
125
126
127 Section DriveSpace
128 ${StackVerificationStart} DriveSpace
129
130 ${DriveSpace} 'C:\' '/D=F /S=M' $OUT1
131
132 ${StackVerificationEnd}
133 SectionEnd
134
135
136 Section GetDrives
137 ${StackVerificationStart} GetDrives
138
139 ${GetDrives} 'FDD+CDROM' 'GetDrivesCallback'
140
141 ${StackVerificationEnd}
142 SectionEnd
143
144 Function GetDrivesCallback
145 ; MessageBox MB_YESNO '$$0={$0}$\n$$1={$1}$\n$$2={$2}$\n$$3={$3}$\n$$4={$4}$\n$$5={$5}$\n$$6={$6}$\n$$7={$7}$\n$$8={$8}$\n$$9={$9}$\n$$R0={$R0}$\n$$R1={$R1}$\n$$R2={$R2}$\n$$R3={$R3}$\n$$R4={$R4}$\n$$R5={$R5}$\n$$R6={$R6}$\n$$R7={$R7}$\n$$R8={$R8}$\n$$R9={$R9}$\n$\nContinue?' IDYES +2
146 ; StrCpy $0 StopGetDrives
147
148 Push $0
149 FunctionEnd
150
151
152 Section GetTime
153 ${StackVerificationStart} GetTime
154
155 ${GetTime} '' 'L' $OUT1 $OUT2 $OUT3 $OUT4 $OUT5 $OUT6 $OUT7
156
157 ${StackVerificationEnd}
158 SectionEnd
159
160
161 Section GetFileAttributes
162 ${StackVerificationStart} GetFileAttributes
163
164 ${GetFileAttributes} '$WINDIR\explorer.exe' 'ALL' $OUT1
165
166 ${StackVerificationEnd}
167 SectionEnd
168
169
170 Section GetFileVersion
171 ${StackVerificationStart} GetFileVersion
172
173 ${GetFileVersion} '$WINDIR\explorer.exe' $OUT1
174
175 ${StackVerificationEnd}
176 SectionEnd
177
178
179 Section GetExeName
180 ${StackVerificationStart} GetExeName
181
182 ${GetExeName} $OUT1
183
184 ${StackVerificationEnd}
185 SectionEnd
186
187
188 Section GetExePath
189 ${StackVerificationStart} GetExePath
190
191 ${GetExePath} $OUT1
192
193 ${StackVerificationEnd}
194 SectionEnd
195
196
197 Section GetParameters
198 ${StackVerificationStart} GetParameters
199
200 # basic stuff
201
202 StrCpy $CMDLINE '"$PROGRAMFILES\Something\Hello.exe"'
203 ${GetParameters} $OUT1
204 StrCpy $CMDLINE '"$PROGRAMFILES\Something\Hello.exe" test'
205 ${GetParameters} $OUT2
206 StrCpy $CMDLINE '"$PROGRAMFILES\Something\Hello.exe" "test"'
207 ${GetParameters} $OUT3
208 StrCpy $CMDLINE 'C:\Hello.exe'
209 ${GetParameters} $OUT4
210 StrCpy $CMDLINE 'C:\Hello.exe test'
211 ${GetParameters} $OUT5
212 StrCpy $CMDLINE 'C:\Hello.exe "test"'
213 ${GetParameters} $OUT6
214 StrCpy $CMDLINE 'C:\Hello.exe test test '
215 ${GetParameters} $OUT7
216
217 ${If} $OUT1 != ""
218 ${OrIf} $OUT2 != "test"
219 ${OrIf} $OUT3 != '"test"'
220 ${OrIf} $OUT4 != ""
221 ${OrIf} $OUT5 != "test"
222 ${OrIf} $OUT6 != '"test"'
223 ${OrIf} $OUT7 != 'test test'
224 SetErrors
225 ${EndIf}
226
227 # some corner cases
228
229 StrCpy $CMDLINE ''
230 ${GetParameters} $OUT1
231 StrCpy $CMDLINE '"'
232 ${GetParameters} $OUT2
233 StrCpy $CMDLINE '""'
234 ${GetParameters} $OUT3
235 StrCpy $CMDLINE '"" test'
236 ${GetParameters} $OUT4
237 StrCpy $CMDLINE ' test'
238 ${GetParameters} $OUT5
239 StrCpy $CMDLINE ' test' # left over bug(?) from old GetParameters
240 # it starts looking for ' ' from the third char
241 ${GetParameters} $OUT6
242 StrCpy $CMDLINE ' '
243 ${GetParameters} $OUT7
244
245 ${If} $OUT1 != ""
246 ${OrIf} $OUT2 != ""
247 ${OrIf} $OUT3 != ""
248 ${OrIf} $OUT4 != ""
249 ${OrIf} $OUT5 != ""
250 ${OrIf} $OUT6 != ""
251 ${OrIf} $OUT7 != ""
252 SetErrors
253 ${EndIf}
254
255 ${StackVerificationEnd}
256 SectionEnd
257
258
259 Section GetOptions
260 ${StackVerificationStart} GetOptions
261
262 ${GetOptions} '/INSTDIR=C:\Program Files\Common Files /SILENT=yes' '/INSTDIR=' $OUT1
263 StrCmp $OUT1 'C:\Program Files\Common Files' 0 error
264
265 ${GetOptions} '-TMP=temp.tmp -INSTDIR="C:/Program Files/Common Files" -SILENT=yes' '-INSTDIR=' $OUT1
266 StrCmp $OUT1 'C:/Program Files/Common Files' 0 error
267
268 ${GetOptions} "/INSTDIR='C:/Program Files/Common Files' /SILENT=yes" '/INSTDIR=' $OUT1
269 StrCmp $OUT1 'C:/Program Files/Common Files' 0 error
270
271 StrCpy $OUT1 '/INSTDIR=`C:/Program Files/Common Files` /SILENT=yes'
272 ${GetOptions} '$OUT1' '/INSTDIR=' $OUT1
273 StrCmp $OUT1 'C:/Program Files/Common Files' 0 error
274
275 ${GetOptions} '/SILENT=yes /INSTDIR=C:\Program Files\Common Files' '/INSTDIR=' $OUT1
276 StrCmp $OUT1 'C:\Program Files\Common Files' 0 error
277
278 ${GetOptions} "/INSTDIR=common directory: 'C:\Program Files\Common Files' /SILENT=yes" '/INSTDIR=' $OUT1
279 StrCmp $OUT1 "common directory: 'C:\Program Files\Common Files'" 0 error
280
281 ${GetOptions} '/INSTDIR=WxxxW /SILENT=yes' '/INSTDIR=' $OUT1
282 StrCmp $OUT1 'WxxxW' 0 error
283
284 ${GetOptions} "/Prm='/D=True' /D=1" '/D=' $OUT1
285 StrCmp $OUT1 "1" 0 error
286
287 ${GetOptions} "/D=1 /Prm='/D=True'" '/Prm=' $OUT1
288 StrCmp $OUT1 "/D=True" 0 error
289
290 ${GetOptions} `/D=1 /Prm='/D="True" /S="/Temp"'` '/Prm=' $OUT1
291 StrCmp $OUT1 '/D="True" /S="/Temp"' 0 error
292
293 ${GetOptions} `/INSTDIR='"C:/Program Files/Common Files"' /SILENT=yes` '/INSTDIR=' $OUT1
294 StrCmp $OUT1 '"C:/Program Files/Common Files"' 0 error
295
296 ${GetOptions} `/INSTDIR='"C:/Program Files/Common Files"' /SILENT=yes` '/INSTDIR*=' $OUT1
297 IfErrors 0 error
298 StrCmp $OUT1 '' 0 error
299
300 ${GetOptions} `/INSTDIR="C:/Program Files/Common Files" /SILENT=yes` '' $OUT1
301 IfErrors 0 error
302 StrCmp $OUT1 '' 0 error
303
304 ${GetOptionsS} '/INSTDIR=C:\Program Files\Common Files /SILENT' '/SILENT' $OUT1
305 IfErrors error
306 StrCmp $OUT1 '' 0 error
307
308 goto +2
309 error:
310 SetErrors
311
312 ${StackVerificationEnd}
313 SectionEnd
314
315
316 Section GetOptionsS
317 ${StackVerificationStart} GetOptionsS
318
319 ${GetOptionsS} '/INSTDIR=C:\Program Files\Common Files /SILENT=yes' '/INSTDIR=' $OUT1
320 IfErrors error
321 StrCmp $OUT1 'C:\Program Files\Common Files' 0 error
322
323 ${GetOptionsS} '/INSTDIR=C:\Program Files\Common Files /SILENT=yes' '/Instdir=' $OUT1
324 IfErrors 0 error
325 StrCmp $OUT1 '' 0 error
326
327 ${GetOptionsS} '/INSTDIR=C:\Program Files\Common Files /SILENT' '/SILENT' $OUT1
328 IfErrors error
329 StrCmp $OUT1 '' 0 error
330
331 goto +2
332 error:
333 SetErrors
334
335 ${StackVerificationEnd}
336 SectionEnd
337
338
339 Section GetRoot
340 ${StackVerificationStart} GetRoot
341
342 ${GetRoot} 'C:\Program Files\NSIS' $OUT1
343 StrCmp $OUT1 'C:' 0 error
344
345 ${GetRoot} '\\SuperPimp\NSIS\Source\exehead\Ui.c' $OUT1
346 StrCmp $OUT1 '\\SuperPimp\NSIS' 0 error
347
348 ${GetRoot} '\\Program Files\NSIS' $OUT1
349 StrCmp $OUT1 '\\Program Files\NSIS' 0 error
350
351 ${GetRoot} '\\Program Files\NSIS\' $OUT1
352 StrCmp $OUT1 '\\Program Files\NSIS' 0 error
353
354 ${GetRoot} '\\Program Files\NSIS\Source\exehead\Ui.c' $OUT1
355 StrCmp $OUT1 '\\Program Files\NSIS' 0 error
356
357 ${GetRoot} '\Program Files\NSIS' $OUT1
358 StrCmp $OUT1 '' 0 error
359
360 goto +2
361 error:
362 SetErrors
363
364 ${StackVerificationEnd}
365 SectionEnd
366
367
368 Section GetParent
369 ${StackVerificationStart} GetParent
370
371 ${GetParent} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
372 StrCmp $OUT1 'C:\Program Files\Winamp' 0 error
373
374 ${GetParent} 'C:\Program Files\Winamp\plugins' $OUT1
375 StrCmp $OUT1 'C:\Program Files\Winamp' 0 error
376
377 ${GetParent} 'C:\Program Files\Winamp\plugins\' $OUT1
378 StrCmp $OUT1 'C:\Program Files\Winamp' 0 error
379
380 ${GetParent} 'C:\' $OUT1
381 StrCmp $OUT1 '' 0 error
382
383 goto +2
384 error:
385 SetErrors
386
387 ${StackVerificationEnd}
388 SectionEnd
389
390
391 Section GetFileName
392 ${StackVerificationStart} GetFileName
393
394 ${GetFileName} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
395 StrCmp $OUT1 'uninstwa.exe' 0 error
396
397 ${GetFileName} 'uninstwa.exe' $OUT1
398 StrCmp $OUT1 'uninstwa.exe' 0 error
399
400 ${GetFileName} 'C:\Program Files\Winamp\plugins' $OUT1
401 StrCmp $OUT1 'plugins' 0 error
402
403 ${GetFileName} 'C:\Program Files\Winamp\plugins\' $OUT1
404 StrCmp $OUT1 'plugins' 0 error
405
406 goto +2
407 error:
408 SetErrors
409
410 ${StackVerificationEnd}
411 SectionEnd
412
413
414 Section GetBaseName
415 ${StackVerificationStart} GetBaseName
416
417 ${GetBaseName} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
418 StrCmp $OUT1 'uninstwa' 0 error
419
420 ${GetBaseName} 'uninstwa.exe' $OUT1
421 StrCmp $OUT1 'uninstwa' 0 error
422
423 ${GetBaseName} 'C:\Program Files\Winamp\plugins' $OUT1
424 StrCmp $OUT1 'plugins' 0 error
425
426 ${GetBaseName} 'C:\Program Files\Winamp\plugins\' $OUT1
427 StrCmp $OUT1 '' 0 error
428
429 goto +2
430 error:
431 SetErrors
432
433 ${StackVerificationEnd}
434 SectionEnd
435
436
437 Section GetFileExt
438 ${StackVerificationStart} GetFileExt
439
440 ${GetFileExt} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
441 StrCmp $OUT1 'exe' 0 error
442
443 ${GetFileExt} 'uninstwa.exe' $OUT1
444 StrCmp $OUT1 'exe' 0 error
445
446 ${GetFileExt} 'C:\Program Files\Winamp\plugins' $OUT1
447 StrCmp $OUT1 '' 0 error
448
449 ${GetFileExt} 'C:\Program Files\Winamp\plugins\' $OUT1
450 StrCmp $OUT1 '' 0 error
451
452 goto +2
453 error:
454 SetErrors
455
456 ${StackVerificationEnd}
457 SectionEnd
458
459
460 Section BannerTrimPath
461 ${StackVerificationStart} BannerTrimPath
462
463 ${BannerTrimPath} 'C:\Server\Documents\Terminal\license.htm' '35A' $OUT1
464 StrCmp $OUT1 'C:\Server\...\Terminal\license.htm' 0 error
465
466 ${BannerTrimPath} 'C:\12\3456\789' '3A' $OUT1
467 StrCmp $OUT1 '' 0 error
468
469 ${BannerTrimPath} 'C:\12\3456\789' '4A' $OUT1
470 StrCmp $OUT1 'C...' 0 error
471
472 ${BannerTrimPath} 'C:\12\3456\789' '11A' $OUT1
473 StrCmp $OUT1 'C:\12\...' 0 error
474
475 ${BannerTrimPath} 'C:\12\3456\789' '13A' $OUT1
476 StrCmp $OUT1 'C:\12\...\789' 0 error
477
478 ${BannerTrimPath} 'C:\12\3456\789' '14A' $OUT1
479 StrCmp $OUT1 'C:\12\3456\789' 0 error
480
481 ${BannerTrimPath} 'C:\12\3456\789' '14A' $OUT1
482 StrCmp $OUT1 'C:\12\3456\789' 0 error
483
484 ${BannerTrimPath} 'C:\12\3456\789' '11B' $OUT1
485 StrCmp $OUT1 'C:\12\...' 0 error
486
487 ${BannerTrimPath} 'C:\12\3456\789' '5B' $OUT1
488 StrCmp $OUT1 'C:...' 0 error
489
490 ${BannerTrimPath} 'C:\12\3456\789' '5B' $OUT1
491 StrCmp $OUT1 'C:...' 0 error
492
493 ${BannerTrimPath} 'C:\12\3456\789' '11C' $OUT1
494 StrCmp $OUT1 'C:\12\34...' 0 error
495
496 ${BannerTrimPath} 'C:\12\3456\789' '9D' $OUT1
497 StrCmp $OUT1 'C:\12\...' 0 error
498
499 ${BannerTrimPath} 'C:\12\3456\789' '10D' $OUT1
500 StrCmp $OUT1 'C:\...\789' 0 error
501
502 ${BannerTrimPath} 'C:\12\3456\789' '11D' $OUT1
503 StrCmp $OUT1 'C:\1...\789' 0 error
504
505 ${BannerTrimPath} '123456789' '5D' $OUT1
506 StrCmp $OUT1 '12...' 0 error
507
508 goto +2
509 error:
510 SetErrors
511
512 ${StackVerificationEnd}
513 SectionEnd
514
515
516 Section DirState
517 ${StackVerificationStart} DirState
518
519 ${DirState} '$TEMP' $OUT1
520
521 ${StackVerificationEnd}
522 SectionEnd
523
524
525 Section RefreshShellIcons
526 ${StackVerificationStart} RefreshShellIcons
527
528 ${RefreshShellIcons}
529
530 ${StackVerificationEnd}
531 SectionEnd
532
533
534 Section WriteUninstaller
535 goto +2
536 WriteUninstaller '$EXEDIR\un.FileFuncTest.exe'
537 SectionEnd
538
539
540
541 ;############### UNINSTALL ###############
542
543 Section un.Uninstall
544 ${Locate} '$DOCUMENTS' '/L=FD /M=*.* /S=0B /G=0' 'un.LocateCallback'
545 ${GetSize} '$WINDIR' '/M=Explorer.exe /S=0K /G=0' $OUT1 $OUT2 $OUT3
546 ${DriveSpace} 'C:\' '/D=F /S=M' $OUT1
547 ${GetDrives} 'FDD+CDROM' 'un.GetDrivesCallback'
548 ${GetTime} '' 'L' $OUT1 $OUT2 $OUT3 $OUT4 $OUT5 $OUT6 $OUT7
549 ${GetFileAttributes} '$WINDIR\explorer.exe' 'ALL' $OUT1
550 ${GetFileVersion} '$WINDIR\explorer.exe' $OUT1
551 ${GetExeName} $OUT1
552 ${GetExePath} $OUT1
553 ${GetParameters} $OUT1
554 ${GetOptions} '/INSTDIR=C:\Program Files\Common Files /SILENT=yes' '/INSTDIR=' $OUT1
555 ${GetOptionsS} '/INSTDIR=C:\Program Files\Common Files /SILENT=yes' '/INSTDIR=' $OUT1
556 ${GetRoot} 'C:\Program Files\NSIS' $OUT1
557 ${GetParent} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
558 ${GetFileName} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
559 ${GetBaseName} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
560 ${GetFileExt} 'C:\Program Files\Winamp\uninstwa.exe' $OUT1
561 ${BannerTrimPath} 'C:\Server\Documents\Terminal\license.htm' '35A' $OUT1
562 ${DirState} '$TEMP' $OUT1
563 ${RefreshShellIcons}
564 SectionEnd
565
566 Function un.LocateCallback
567 Push $0
568 FunctionEnd
569
570 Function un.GetDrivesCallback
571 Push $0
572 FunctionEnd