Statistiques
| Révision :

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

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