bigtest.nsi 8.1 KB

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