home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Programming / nsis-2.46-setup.exe / Examples / InstallOptions / testnotify.nsi < prev   
Encoding:
Text File  |  2008-12-20  |  4.3 KB  |  134 lines

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