Debian Codegraph @

Examples/bigtest.nsi

raw
1 ; bigtest.nsi
2 ;
3 ; This script attempts to test most of the functionality of the NSIS exehead.
4
5 ;--------------------------------
6
7 !ifdef HAVE_UPX
8 !packhdr tmp.dat "upx\upx -9 tmp.dat"
9 !endif
10
11 !ifdef NOCOMPRESS
12 SetCompress off
13 !endif
14
15 ;--------------------------------
16
17 Name "BigNSISTest"
18 Caption "NSIS Big Test"
19 Icon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-install.ico"
20 OutFile "bigtest.exe"
21
22 SetDateSave on
23 SetDatablockOptimize on
24 CRCCheck on
25 SilentInstall normal
26 BGGradient 000000 800000 FFFFFF
27 InstallColors FF8080 000030
28 XPStyle on
29
30 InstallDir "$PROGRAMFILES\NSISTest\BigNSISTest"
31 InstallDirRegKey HKLM "Software\NSISTest\BigNSISTest" "Install_Dir"
32
33 CheckBitmap "${NSISDIR}\Contrib\Graphics\Checks\classic-cross.bmp"
34
35 LicenseText "A test text, make sure it's all there"
36 LicenseData "bigtest.nsi"
37
38 RequestExecutionLevel admin
39 ManifestSupportedOS all
40
41 ;--------------------------------
42
43 Page license
44 Page components
45 Page directory
46 Page instfiles
47
48 UninstPage uninstConfirm
49 UninstPage instfiles
50
51 ;--------------------------------
52
53 !ifndef NOINSTTYPES ; only if not defined
54 InstType "Most"
55 InstType "Full"
56 InstType "More"
57 InstType "Base"
58 ;InstType /NOCUSTOM
59 ;InstType /COMPONENTSONLYONCUSTOM
60 !endif
61
62 AutoCloseWindow false
63 ShowInstDetails show
64
65 ;--------------------------------
66
67 Section "" ; empty string makes it hidden, so would starting with -
68
69 ; write reg info
70 StrCpy $1 "Hello World"
71 DetailPrint "I like to be able to see what is going on (debug) $1"
72 WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "Install_Dir" "$INSTDIR"
73
74 ; write uninstall strings
75 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "DisplayName" "BigNSISTest (remove only)"
76 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "UninstallString" '"$INSTDIR\bt-uninst.exe"'
77
78 SetOutPath $INSTDIR
79 File /a "silent.nsi"
80 CreateDirectory "$INSTDIR\MyProjectFamily\MyProject" ; 2 recursively create a directory for fun.
81 WriteUninstaller "$INSTDIR\bt-uninst.exe"
82
83 Nop ; for fun
84
85 SectionEnd
86
87 Section "TempTest"
88
89 SectionIn 1 2 3
90 Start: MessageBox MB_OK "Start:"
91
92 MessageBox MB_YESNO "Goto MyLabel" IDYES MyLabel
93
94 MessageBox MB_OK "Right before MyLabel:"
95
96 MyLabel: MessageBox MB_OK "MyLabel:"
97
98 MessageBox MB_OK "Right after MyLabel:"
99
100 MessageBox MB_YESNO "Goto Start:?" IDYES Start
101
102 SectionEnd
103
104 SectionGroup /e SectionGroup1
105
106 Section "Test Registry/INI functions"
107
108 SectionIn 1 4 3
109
110 WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "StrTest_INSTDIR" "$INSTDIR"
111 WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0xDEADBEEF" 0xdeadbeef
112 WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_123456" 123456
113 WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0123" 0123
114 WriteRegBin HKLM SOFTWARE\NSISTest\BigNSISTest "BinTest_deadbeef01f00dbeef" "DEADBEEF01F00DBEEF"
115 StrCpy $8 "$SYSDIR\IniTest"
116 WriteINIStr "$INSTDIR\test.ini" "MySection" "Value1" $8
117 WriteINIStr "$INSTDIR\test.ini" "MySectionIni" "Value1" $8
118 WriteINIStr "$INSTDIR\test.ini" "MySectionIni" "Value2" $8
119 WriteINIStr "$INSTDIR\test.ini" "IniOn" "Value1" $8
120
121 Call MyFunctionTest
122
123 DeleteINIStr "$INSTDIR\test.ini" "IniOn" "Value1"
124 DeleteINISec "$INSTDIR\test.ini" "MySectionIni"
125
126 ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
127 StrCmp $1 "" INIDelSuccess
128 MessageBox MB_OK "DeleteINISec failed"
129 INIDelSuccess:
130
131 ClearErrors
132 ReadRegStr $1 HKCR "software\microsoft" xyz_cc_does_not_exist
133 IfErrors 0 NoError
134 MessageBox MB_OK "could not read from HKCR\software\microsoft\xyz_cc_does_not_exist"
135 Goto ErrorYay
136 NoError:
137 MessageBox MB_OK "read '$1' from HKCR\software\microsoft\xyz_cc_does_not_exist"
138 ErrorYay:
139
140 SectionEnd
141
142 Section "Test CreateShortcut"
143
144 SectionIn 1 2 3
145
146 Call CSCTest
147
148 SectionEnd
149
150 SectionGroup Group2
151
152 !define ASSERT `!insertmacro ASSERT "${U+24}{__FILE__}" ${U+24}{__LINE__} `
153 !macro ASSERT __file __line __xpr
154 ${__xpr} +2
155 MessageBox MB_ICONSTOP `ASSERT: ${__xpr} (${__file}:${__line})`
156 !macroend
157
158 Section "Integer"
159 IntOp $0 0xffffffff >> 31
160 ${ASSERT} `IntCmpU $0 -1`
161 IntOp $0 0xffffffff >>> 31
162 ${ASSERT} `IntCmpU $0 1`
163 IntOp $0 1 << 31
164 ${ASSERT} `IntCmpU $0 0x80000000`
165 IntOp $0 0x80000000 ^ 0x40000000
166 ${ASSERT} `IntCmpU $0 0xC0000000`
167 ClearErrors
168 IntOp $0 1 / 0
169 ${ASSERT} `IfErrors ` ; Division by zero must set the error flag
170 ${ASSERT} `IntCmpU $0 0` ; Unspecified result, hopefully it's zero
171 SectionEnd
172
173 Section "Test Branching"
174
175 BeginTestSection:
176 SectionIn 1 2 3
177
178 SetOutPath $INSTDIR
179
180 IfFileExists "$INSTDIR\LogicLib.nsi" 0 BranchTest69
181
182 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to overwrite $INSTDIR\LogicLib.nsi?" IDNO NoOverwrite ; skipped if file doesn't exist
183
184 BranchTest69:
185
186 SetOverwrite ifnewer ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
187
188 NoOverwrite:
189
190 File "LogicLib.nsi" ; skipped if answered no
191 SetOverwrite try ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
192
193 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to skip the rest of this section?" IDYES EndTestBranch
194 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to go back to the beginning of this section?" IDYES BeginTestSection
195 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to hide the installer and wait five seconds?" IDNO NoHide
196
197 HideWindow
198 Sleep 5000
199 BringToFront
200
201 NoHide:
202
203 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to call the function 5 times?" IDNO NoRecurse
204
205 StrCpy $1 "x"
206
207 LoopTest:
208
209 Call myfunc
210 StrCpy $1 "x$1"
211 StrCmp $1 "xxxxxx" 0 LoopTest
212
213 NoRecurse:
214
215 EndTestBranch:
216
217 SectionEnd
218
219 SectionGroupEnd
220
221 Section "Test CopyFiles"
222
223 SectionIn 1 2 3
224
225 SetOutPath $INSTDIR\cpdest
226 CopyFiles "$WINDIR\*.ini" "$INSTDIR\cpdest" 0
227
228 SectionEnd
229
230 SectionGroupEnd
231
232 Section "Test Exec functions" TESTIDX
233
234 SectionIn 1 2 3
235
236 SearchPath $1 notepad.exe
237
238 MessageBox MB_OK "notepad.exe=$1"
239 Exec '"$1"'
240 ExecShell "open" '"$INSTDIR"'
241 Sleep 500
242 BringToFront
243
244 SectionEnd
245
246 Section "Test ActiveX control registration"
247
248 SectionIn 2
249
250 UnRegDLL "$SYSDIR\spin32.ocx"
251 Sleep 1000
252 RegDLL "$SYSDIR\spin32.ocx"
253 Sleep 1000
254
255 SectionEnd
256
257 ;--------------------------------
258
259 Function "CSCTest"
260
261 CreateDirectory "$SMPROGRAMS\Big NSIS Test"
262 SetOutPath $INSTDIR ; for working directory
263 CreateShortcut "$SMPROGRAMS\Big NSIS Test\Uninstall BIG NSIS Test.lnk" "$INSTDIR\bt-uninst.exe" ; use defaults for parameters, icon, etc.
264 ; this one will use notepad's icon, start it minimized, and give it a hotkey (of Ctrl+Shift+Q)
265 CreateShortcut "$SMPROGRAMS\Big NSIS Test\silent.nsi.lnk" "$INSTDIR\silent.nsi" "" "$WINDIR\notepad.exe" 0 SW_SHOWMINIMIZED CONTROL|SHIFT|Q
266 CreateShortcut "$SMPROGRAMS\Big NSIS Test\TheDir.lnk" "$INSTDIR\" "" "" 0 SW_SHOWMAXIMIZED CONTROL|SHIFT|Z
267
268 FunctionEnd
269
270 Function myfunc
271
272 StrCpy $2 "MyTestVar=$1"
273 MessageBox MB_OK "myfunc: $2"
274
275 FunctionEnd
276
277 Function MyFunctionTest
278
279 ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
280 StrCmp $1 $8 NoFailedMsg
281 MessageBox MB_OK "WriteINIStr failed"
282
283 NoFailedMsg:
284
285 FunctionEnd
286
287 Function .onSelChange
288
289 SectionGetText ${TESTIDX} $0
290 StrCmp $0 "" e
291 SectionSetText ${TESTIDX} ""
292 Goto e2
293 e:
294 SectionSetText ${TESTIDX} "TextInSection"
295 e2:
296
297 FunctionEnd
298
299 ;--------------------------------
300
301 ; Uninstaller
302
303 UninstallText "This will uninstall example2. Hit next to continue."
304 UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-uninstall.ico"
305
306 Section "Uninstall"
307
308 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest"
309 DeleteRegKey HKLM "SOFTWARE\NSISTest\BigNSISTest"
310 Delete "$INSTDIR\silent.nsi"
311 Delete "$INSTDIR\LogicLib.nsi"
312 Delete "$INSTDIR\bt-uninst.exe"
313 Delete "$INSTDIR\test.ini"
314 Delete "$SMPROGRAMS\Big NSIS Test\*.*"
315 RMDir "$SMPROGRAMS\BiG NSIS Test"
316
317 MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR\cpdest?" IDNO NoDelete
318 Delete "$INSTDIR\cpdest\*.*"
319 RMDir "$INSTDIR\cpdest" ; skipped if no
320 NoDelete:
321
322 RMDir "$INSTDIR\MyProjectFamily\MyProject"
323 RMDir "$INSTDIR\MyProjectFamily"
324 RMDir "$INSTDIR"
325
326 IfFileExists "$INSTDIR" 0 NoErrorMsg
327 MessageBox MB_OK "Note: $INSTDIR could not be removed!" IDOK 0 ; skipped if file doesn't exist
328 NoErrorMsg:
329
330 SectionEnd