home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Examples / bigtest.nsi next >
Text File  |  2003-11-19  |  8KB  |  307 lines

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