bigtest.nsi 7.5 KB

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