Statistiques
| Révision :

root / tmp / org.txm.setups / nsis / Examples / bigtest.nsi @ 3107

Historique | Voir | Annoter | Télécharger (8,43 ko)

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