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