home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / InstallOptions / testnotify.nsi < prev   
Text File  |  2004-01-27  |  5KB  |  136 lines

  1. ; InstallOptions script demonstrating custom buttons
  2. ;----------------------------------------------------
  3.  
  4. !include WinMessages.nsh
  5.  
  6. Var hwnd ; Window handle of the custom page
  7.  
  8. ; The name of the installer
  9. Name "InstallOptions Test"
  10.  
  11. ; The file to write
  12. OutFile "TestNotify.exe"
  13.  
  14. ; Show install details
  15. ShowInstDetails show
  16.  
  17. ; Called before anything else as installer initialises
  18. Function .onInit
  19.  
  20.   ; Extract InstallOptions files
  21.   ; $PLUGINSDIR will automatically be removed when the installer closes
  22.   InitPluginsDir
  23.   File /oname=$PLUGINSDIR\test.ini "testnotify.ini"
  24.  
  25. FunctionEnd
  26.  
  27. ; Our custom page
  28. Page custom ShowCustom LeaveCustom ": Testing InstallOptions"
  29.  
  30. Function ShowCustom
  31.  
  32.   ; Initialise the dialog but don't show it yet
  33.   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Test the right-to-left version?" IDNO +2
  34.     WriteINIStr "$PLUGINSDIR\test.ini" "Settings" "RTL" "1"
  35.   InstallOptions::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini"
  36.   ; In this mode InstallOptions returns the window handle so we can use it
  37.   Pop $hwnd
  38.   ; Now show the dialog and wait for it to finish
  39.   InstallOptions::show
  40.   ; Finally fetch the InstallOptions status value (we don't care what it is though)
  41.   Pop $0
  42.  
  43. FunctionEnd
  44.  
  45. Function LeaveCustom
  46.  
  47.   ; At this point the user has either pressed Next or one of our custom buttons
  48.   ; We find out which by reading from the INI file
  49.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Settings" "State"
  50.   StrCmp $0 0 validate  ; Next button?
  51.   StrCmp $0 2 supportx  ; "Install support for X"?
  52.   StrCmp $0 9 clearbtn  ; "Clear" button?
  53.   StrCmp $0 11 droplist ; "Show|Hide" drop-list?
  54.   Abort ; Return to the page
  55.  
  56. supportx:
  57.   ; Make the FileRequest field depend on the first checkbox
  58.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 2" "State"
  59.   GetDlgItem $1 $hwnd 1204 ; PathRequest control (1200 + field 5 - 1)
  60.   EnableWindow $1 $0
  61.   GetDlgItem $1 $hwnd 1205 ; ... button (the following control)
  62.   EnableWindow $1 $0
  63.   ; Add the disabled flag too so when we return to this page it's disabled again
  64.   StrCmp $0 0 0 +3
  65.  
  66.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 5" "Flags" "GROUP|FILE_MUST_EXIST|FILE_EXPLORER|FILE_HIDEREADONLY|DISABLED"
  67.     Goto +2
  68.  
  69.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 5" "Flags" "GROUP|FILE_MUST_EXIST|FILE_EXPLORER|FILE_HIDEREADONLY"
  70.   Abort ; Return to the page
  71.  
  72. clearbtn:
  73.   ; Clear all text fields
  74.   GetDlgItem $1 $hwnd 1204 ; PathRequest control (1200 + field 5 - 1)
  75.   SendMessage $1 ${WM_SETTEXT} 0 "STR:"
  76.   GetDlgItem $1 $hwnd 1206 ; DirRequest control (1200 + field 6 - 1 + 1 browse button)
  77.   SendMessage $1 ${WM_SETTEXT} 0 "STR:"
  78.   GetDlgItem $1 $hwnd 1209 ; Multiline control (1200 + field 8 - 1 + 2 browse buttons)
  79.   SendMessage $1 ${WM_SETTEXT} 0 "STR:"
  80.   Abort ; Return to the page
  81.  
  82. droplist:
  83.   ; Make the DirRequest field depend on the droplist
  84.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 11" "State"
  85.   StrCmp $0 "Show" +3
  86.     StrCpy $0 0
  87.   Goto +2
  88.     StrCpy $0 1
  89.   GetDlgItem $1 $hwnd 1206 ; DirRequest control (1200 + field 6 - 1 + 1 browse button)
  90.   EnableWindow $1 $0
  91.   GetDlgItem $1 $hwnd 1207 ; ... button (the following control)
  92.   EnableWindow $1 $0
  93.   ; Add the disabled flag too so when we return to this page it's disabled again
  94.   StrCmp $0 0 0 +3
  95.  
  96.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 6" "Flags" "DISABLED"
  97.     Goto +2
  98.  
  99.     WriteINIStr "$PLUGINSDIR\test.ini" "Field 6" "Flags" ""
  100.   Abort ; Return to the page
  101.  
  102. validate:
  103.   ; At this point we know the Next button was pressed, so perform any validation
  104.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 2" "State"
  105.   StrCmp $0 1 done
  106.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 3" "State"
  107.   StrCmp $0 1 done
  108.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 4" "State"
  109.   StrCmp $0 1 done
  110.     MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!"
  111.     Abort
  112. done:
  113.  
  114. FunctionEnd
  115.  
  116. ; Installation page
  117. Page instfiles
  118.  
  119. Section
  120.  
  121.   ;Get Install Options dialog user input
  122.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 2" "State"
  123.   DetailPrint "Install X=$0"
  124.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 3" "State"
  125.   DetailPrint "Install Y=$0"
  126.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 4" "State"
  127.   DetailPrint "Install Z=$0"
  128.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 5" "State"
  129.   DetailPrint "File=$0"
  130.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 6" "State"
  131.   DetailPrint "Dir=$0"
  132.   ReadINIStr $0 "$PLUGINSDIR\test.ini" "Field 8" "State"
  133.   DetailPrint "Info=$0"
  134.  
  135. SectionEnd
  136.