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" ""
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
 
;--------------------------------
39
 
40
 
Page license
41
 
Page components
42
 
Page directory
43
 
Page instfiles
44
 
45
 
UninstPage uninstConfirm
46
 
UninstPage instfiles
47
 
48
 
;--------------------------------
49
 
50
  
  
!ifndef NOINSTTYPES ; only if not defined
51
 
  InstType "Most"
52
 
  InstType "Full"
53
 
  InstType "More"
54
 
  InstType "Base"
55
 
  ;InstType /NOCUSTOM
56
 
  ;InstType /COMPONENTSONLYONCUSTOM
57
 
!endif
58
 
59
 
AutoCloseWindow false
60
 
ShowInstDetails show
61
 
62
 
;--------------------------------
63
 
64
  
  
Section "" ; empty string makes it hidden, so would starting with -
65
 
66
 
  ; write reg info
67
 
  StrCpy $1 "POOOOOOOOOOOP"
68
 
  DetailPrint "I like to be able to see what is going on (debug) $1"
69
 
  WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "Install_Dir" "$INSTDIR"
70
 
71
 
  ; write uninstall strings
72
 
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "DisplayName" "BigNSISTest (remove only)"
73
 
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest" "UninstallString" '"$INSTDIR\bt-uninst.exe"'
74
 
75
 
  SetOutPath $INSTDIR
76
 
  File /a "silent.nsi"
77
 
  CreateDirectory "$INSTDIR\MyProjectFamily\MyProject" ; 2 recursively create a directory for fun.
78
 
  WriteUninstaller "bt-uninst.exe"
79
 
  
80
 
  Nop ; for fun
81
 
82
 
SectionEnd
83
 
84
  
  
Section "TempTest"
85
 
86
 
SectionIn 1 2 3
87
 
  Start: MessageBox MB_OK "Start:"
88
 
89
 
  MessageBox MB_YESNO "Goto MyLabel" IDYES MyLabel
90
 
91
 
  MessageBox MB_OK "Right before MyLabel:"
92
 
93
 
  MyLabel: MessageBox MB_OK "MyLabel:"
94
 
  
95
 
  MessageBox MB_OK "Right after MyLabel:"
96
 
97
 
  MessageBox MB_YESNO "Goto Start:?" IDYES Start
98
 
99
 
SectionEnd
100
 
101
  
  
SectionGroup /e SectionGroup1
102
 
103
  
  
Section "Test Registry/INI functions"
104
 
105
 
SectionIn 1 4 3
106
 
107
 
  WriteRegStr HKLM SOFTWARE\NSISTest\BigNSISTest "StrTest_INSTDIR" "$INSTDIR"
108
 
  WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0xDEADBEEF" 0xdeadbeef
109
 
  WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_123456" 123456
110
 
  WriteRegDword HKLM SOFTWARE\NSISTest\BigNSISTest "DwordTest_0123" 0123
111
 
  WriteRegBin HKLM SOFTWARE\NSISTest\BigNSISTest "BinTest_deadbeef01f00dbeef" "DEADBEEF01F00DBEEF"
112
 
  StrCpy $8 "$SYSDIR\IniTest"
113
 
  WriteINIStr "$INSTDIR\test.ini"  "MySection" "Value1" $8
114
 
  WriteINIStr "$INSTDIR\test.ini"  "MySectionIni" "Value1" $8
115
 
  WriteINIStr "$INSTDIR\test.ini"  "MySectionIni" "Value2" $8
116
 
  WriteINIStr "$INSTDIR\test.ini"  "IniOn" "Value1" $8
117
 
118
 
  Call MyFunctionTest
119
 
120
 
  DeleteINIStr "$INSTDIR\test.ini" "IniOn" "Value1"
121
 
  DeleteINISec "$INSTDIR\test.ini" "MySectionIni"
122
 
123
 
  ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
124
 
  StrCmp $1 "" INIDelSuccess
125
 
    MessageBox MB_OK "DeleteINISec failed"
126
 
  INIDelSuccess:
127
 
128
 
  ClearErrors
129
 
  ReadRegStr $1 HKCR "software\microsoft" xyz_¢¢_does_not_exist
130
 
  IfErrors 0 NoError
131
 
    MessageBox MB_OK "could not read from HKCR\software\microsoft\xyz_¢¢_does_not_exist"
132
 
    Goto ErrorYay
133
 
  NoError:
134
 
    MessageBox MB_OK "read '$1' from HKCR\software\microsoft\xyz_¢¢_does_not_exist"
135
 
  ErrorYay:
136
 
  
137
 
SectionEnd
138
 
139
  
  
Section "Test CreateShortCut"
140
 
141
 
  SectionIn 1 2 3
142
 
143
 
  Call CSCTest
144
 
145
 
SectionEnd
146
 
147
  
  
SectionGroup Group2
148
 
149
  
  
Section "Test Branching" 
150
 
  
151
 
  BeginTestSection:
152
 
  SectionIn 1 2 3
153
 
 
154
 
  SetOutPath $INSTDIR
155
 
156
 
  IfFileExists "$INSTDIR\LogicLib.nsi" 0 BranchTest69
157
 
    
158
 
    MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to overwrite $INSTDIR\LogicLib.nsi?" IDNO NoOverwrite ; skipped if file doesn't exist
159
 
160
 
    BranchTest69:
161
 
  
162
 
    SetOverwrite ifnewer ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
163
 
164
 
  NoOverwrite:
165
 
166
 
  File "LogicLib.nsi" ; skipped if answered no
167
 
  SetOverwrite try ; NOT AN INSTRUCTION, NOT COUNTED IN SKIPPINGS
168
 
169
 
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to skip the rest of this section?" IDYES EndTestBranch
170
 
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to go back to the beginning of this section?" IDYES BeginTestSection
171
 
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to hide the installer and wait five seconds?" IDNO NoHide
172
 
173
 
    HideWindow
174
 
    Sleep 5000
175
 
    BringToFront
176
 
177
 
  NoHide:
178
 
179
 
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to call the function 5 times?" IDNO NoRecurse
180
 
181
 
    StrCpy $1 "x"
182
 
183
 
  LoopTest: 
184
 
      
185
 
    Call myfunc
186
 
    StrCpy $1 "x$1"
187
 
    StrCmp $1 "xxxxxx" 0 LoopTest
188
 
      
189
 
  NoRecurse:
190
 
191
 
  EndTestBranch:
192
 
193
 
SectionEnd
194
 
195
 
SectionGroupEnd
196
 
197
  
  
Section "Test CopyFiles"
198
 
199
 
  SectionIn 1 2 3
200
 
201
 
  SetOutPath $INSTDIR\cpdest
202
 
  CopyFiles "$WINDIR\*.ini" "$INSTDIR\cpdest" 0
203
 
204
 
SectionEnd
205
 
206
 
SectionGroupEnd
207
 
208
  
  
Section "Test Exec functions" TESTIDX
209
 
210
 
  SectionIn 1 2 3
211
 
  
212
 
  SearchPath $1 notepad.exe
213
 
214
 
  MessageBox MB_OK "notepad.exe=$1"
215
 
  Exec '"$1"'
216
 
  ExecShell "open" '"$INSTDIR"'
217
 
  Sleep 500
218
 
  BringToFront
219
 
220
 
SectionEnd
221
 
222
  
  
Section "Test ActiveX control registration"
223
 
224
 
  SectionIn 2
225
 
226
 
  UnRegDLL "$SYSDIR\spin32.ocx"
227
 
  Sleep 1000
228
 
  RegDLL "$SYSDIR\spin32.ocx"
229
 
  Sleep 1000
230
 
  
231
 
SectionEnd
232
 
233
 
;--------------------------------
234
 
235
  
  
Function "CSCTest"
236
 
  
237
 
  CreateDirectory "$SMPROGRAMS\Big NSIS Test"
238
 
  SetOutPath $INSTDIR ; for working directory
239
 
  CreateShortCut "$SMPROGRAMS\Big NSIS Test\Uninstall BIG NSIS Test.lnk" "$INSTDIR\bt-uninst.exe" ; use defaults for parameters, icon, etc.
240
 
  ; this one will use notepad's icon, start it minimized, and give it a hotkey (of Ctrl+Shift+Q)
241
 
  CreateShortCut "$SMPROGRAMS\Big NSIS Test\silent.nsi.lnk" "$INSTDIR\silent.nsi" "" "$WINDIR\notepad.exe" 0 SW_SHOWMINIMIZED CONTROL|SHIFT|Q
242
 
  CreateShortCut "$SMPROGRAMS\Big NSIS Test\TheDir.lnk" "$INSTDIR\" "" "" 0 SW_SHOWMAXIMIZED CONTROL|SHIFT|Z
243
 
244
 
FunctionEnd
245
 
246
  
  
Function myfunc
247
 
248
 
  StrCpy $2 "MyTestVar=$1"
249
 
  MessageBox MB_OK "myfunc: $2"
250
 
251
 
FunctionEnd
252
 
253
  
  
Function MyFunctionTest
254
 
255
 
  ReadINIStr $1 "$INSTDIR\test.ini" "MySectionIni" "Value1"
256
 
  StrCmp $1 $8 NoFailedMsg
257
 
    MessageBox MB_OK "WriteINIStr failed"
258
 
  
259
 
  NoFailedMsg:
260
 
261
 
FunctionEnd
262
 
263
  
  
Function .onSelChange
264
 
265
 
  SectionGetText ${TESTIDX} $0
266
 
  StrCmp $0 "" e
267
 
    SectionSetText ${TESTIDX} ""
268
 
  Goto e2
269
 
e:
270
 
  SectionSetText ${TESTIDX} "TextInSection"
271
 
e2:
272
 
273
 
FunctionEnd
274
 
275
 
;--------------------------------
276
 
277
 
; Uninstaller
278
 
279
 
UninstallText "This will uninstall example2. Hit next to continue."
280
 
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\nsis1-uninstall.ico"
281
 
282
  
  
Section "Uninstall"
283
 
284
 
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BigNSISTest"
285
 
  DeleteRegKey HKLM "SOFTWARE\NSISTest\BigNSISTest"
286
 
  Delete "$INSTDIR\silent.nsi"
287
 
  Delete "$INSTDIR\LogicLib.nsi"
288
 
  Delete "$INSTDIR\bt-uninst.exe"
289
 
  Delete "$INSTDIR\test.ini"
290
 
  Delete "$SMPROGRAMS\Big NSIS Test\*.*"
291
 
  RMDir "$SMPROGRAMS\BiG NSIS Test"
292
 
  
293
 
  MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to remove the directory $INSTDIR\cpdest?" IDNO NoDelete
294
 
    Delete "$INSTDIR\cpdest\*.*"
295
 
    RMDir "$INSTDIR\cpdest" ; skipped if no
296
 
  NoDelete:
297
 
  
298
 
  RMDir "$INSTDIR\MyProjectFamily\MyProject"
299
 
  RMDir "$INSTDIR\MyProjectFamily"
300
 
  RMDir "$INSTDIR"
301
 
302
 
  IfFileExists "$INSTDIR" 0 NoErrorMsg
303
 
    MessageBox MB_OK "Note: $INSTDIR could not be removed!" IDOK 0 ; skipped if file doesn't exist
304
 
  NoErrorMsg:
305
 
306
 
SectionEnd
307
 
   
  

Exported as HTML from EclipseNSIS (http://eclipsensis.sf.net)
Copyright © 2004-2010 Sunil Kamath (IcemanK). All rights reserved.