pages/DatabaseConfig.nsi
changeset 0 67e1cc6cd929
child 2 0c0d5dadfca3
equal deleted inserted replaced
-1:000000000000 0:67e1cc6cd929
       
     1 !macro ShowRange hwnd low high value
       
     2   !define tmp_id ${__LINE__}
       
     3   StrCpy $R0 ${low}
       
     4   loop.${tmp_id}:
       
     5     GetDlgItem $R1 ${hwnd} $R0
       
     6     ShowWindow $R1 ${value}
       
     7     IntOp $R0 $R0 + 1
       
     8     IntCmp $R0 ${high} loop.${tmp_id} loop.${tmp_id}
       
     9     
       
    10   !undef tmp_id
       
    11 !macroend
       
    12 !define ShowRange "!insertmacro ShowRange"
       
    13 
       
    14 Page custom DatabaseConfigCreate DatabaseConfigLeave " - Database configuration"
       
    15 
       
    16 Function DatabaseConfigCreate
       
    17   StrCmp $XPUI_ABORTED 1 0 +2
       
    18     Return
       
    19   !insertmacro XPUI_INSTALLOPTIONS_EXTRACT_AS "pages\DatabaseConfig.ini" "DatabaseConfig.ini"
       
    20   !insertmacro XPUI_HEADER_TEXT "Database configuration" "Configure how $(^Name) will access your database."
       
    21   WriteINIStr "$PLUGINSDIR\DatabaseConfig.ini" "Field 9" "Text" \
       
    22     "$(^Name) needs database access to work properly. Setup can create a database for you if you provide \
       
    23      $db_dbmsname's administration password, or you can choose to enter credentials for a database that already exists."
       
    24 
       
    25   !insertmacro XPUI_INSTALLOPTIONS_INITDIALOG "DatabaseConfig.ini"
       
    26   Pop $XPUI_HWND
       
    27 
       
    28   ${ShowRange} $XPUI_HWND 1204 1207 ${SW_HIDE}
       
    29   ${ShowRange} $XPUI_HWND 1210 1213 ${SW_HIDE}
       
    30 
       
    31   !insertmacro XPUI_INSTALLOPTIONS_SHOW
       
    32 FunctionEnd
       
    33 
       
    34 Function DatabaseConfigLeave
       
    35   StrCmp $XPUI_ABORTED 1 0 +2
       
    36     Return
       
    37     
       
    38   ReadINIStr $0 "$PLUGINSDIR\DatabaseConfig.ini" "Settings" "State"
       
    39   StrCmp $0 1 RadioButtonClicked
       
    40   StrCmp $0 2 RadioButtonClicked
       
    41   StrCmp $0 3 UseManualClicked
       
    42   Goto NextClicked
       
    43   
       
    44   RadioButtonClicked:
       
    45     LockWindow on
       
    46     ReadINIStr $0 "$PLUGINSDIR\DatabaseConfig.ini" "Field 1" "State"
       
    47     IntCmp $0 0 SetUseExisting
       
    48     
       
    49       ; Show root password
       
    50       GetDlgItem $0 $XPUI_HWND 1203
       
    51       ShowWindow $0 ${SW_SHOW}
       
    52       GetDlgItem $0 $XPUI_HWND 1209
       
    53       ShowWindow $0 ${SW_SHOW}
       
    54     
       
    55       GetDlgItem $0 $XPUI_HWND 1202 ; Checkbox
       
    56       SendMessage $0 ${BM_SETCHECK} ${BST_UNCHECKED} 0
       
    57       EnableWindow $0 1
       
    58       ${ShowRange} $XPUI_HWND 1204 1207 ${SW_HIDE}
       
    59       ${ShowRange} $XPUI_HWND 1210 1213 ${SW_HIDE}
       
    60       LockWindow off
       
    61       Abort
       
    62     
       
    63     SetUseExisting:
       
    64     
       
    65       ; Hide root password
       
    66       GetDlgItem $0 $XPUI_HWND 1203
       
    67       ShowWindow $0 ${SW_HIDE}
       
    68       GetDlgItem $0 $XPUI_HWND 1209
       
    69       ShowWindow $0 ${SW_HIDE}
       
    70       
       
    71       GetDlgItem $0 $XPUI_HWND 1202 ; Checkbox
       
    72       SendMessage $0 ${BM_SETCHECK} ${BST_CHECKED} 0
       
    73       EnableWindow $0 0
       
    74       ${ShowRange} $XPUI_HWND 1204 1207 ${SW_SHOW}
       
    75       ${ShowRange} $XPUI_HWND 1210 1213 ${SW_SHOW}
       
    76       LockWindow off
       
    77       Abort
       
    78     
       
    79   UseManualClicked:
       
    80     ReadINIStr $0 "$PLUGINSDIR\DatabaseConfig.ini" "Field 3" "State"
       
    81     IntOp $0 $0 * ${SW_SHOW}
       
    82     ${ShowRange} $XPUI_HWND 1204 1207 $0
       
    83     ${ShowRange} $XPUI_HWND 1210 1213 $0
       
    84     Abort
       
    85   
       
    86   NextClicked:
       
    87 
       
    88     ; Figure out how we want to go about this.
       
    89     StrCpy $db_needroot 0
       
    90     ReadINIStr $0 "$PLUGINSDIR\DatabaseConfig.ini" "Field 1" "State"
       
    91     IntCmp $0 0 UseCustomLogin
       
    92     
       
    93       ; Validate based on root password.
       
    94       StrCpy $db_needroot 1
       
    95       ReadINIStr $db_rootpass "$PLUGINSDIR\DatabaseConfig.ini" "Field 4" "State"
       
    96       ${db_connect} $1 "$db_rootuser" "$db_rootpass"
       
    97       IntCmp $1 0 +3
       
    98         MessageBox MB_OK|MB_ICONEXCLAMATION "The $db_dbmsname root password you entered is incorrect. Please re-enter it."
       
    99         Abort
       
   100         
       
   101       ; Does the user have their own credentials?
       
   102       ReadINIStr $0 "$PLUGINSDIR\DatabaseConfig.ini" "Field 3" "State"
       
   103       IntCmp $0 0 GenerateRandomLogin
       
   104     
       
   105     UseCustomLogin:
       
   106     
       
   107       ; Pull database settings from dialog
       
   108       ReadINIStr $db_name "$PLUGINSDIR\DatabaseConfig.ini" "Field 5" "State"
       
   109       ReadINIStr $db_user "$PLUGINSDIR\DatabaseConfig.ini" "Field 6" "State"
       
   110       ReadINIStr $db_password "$PLUGINSDIR\DatabaseConfig.ini" "Field 7" "State"
       
   111       ReadINIStr $R0 "$PLUGINSDIR\DatabaseConfig.ini" "Field 8" "State"
       
   112       
       
   113       ; Check password length
       
   114       ; but don't if the user entered credentials that already exist
       
   115       IntCmp $db_needroot 0 SkipLengthCheck
       
   116         StrLen $R1 $R0
       
   117         IntCmp $R1 6 +3 0 +3
       
   118           MessageBox MB_OK|MB_ICONEXCLAMATION "Please choose a database password that is at least 6 characters in length."
       
   119           Abort
       
   120           
       
   121       SkipLengthCheck:
       
   122       ; Check password/confirm fields
       
   123       StrCmp $db_password $R0 +3
       
   124         MessageBox MB_OK|MB_ICONEXCLAMATION "The passwords you entered do not match. Please enter them again."
       
   125         Abort
       
   126         
       
   127       ; If we're root, we can assume the login doesn't exist yet, so skip the validation
       
   128       IntCmp $db_needroot 0 +2
       
   129         Return
       
   130         
       
   131       ${db_connect} $R0 $db_user $db_password
       
   132       IntCmp $R0 0 +3
       
   133         ; Database auth failed
       
   134         MessageBox MB_OK|MB_ICONEXCLAMATION "The username and password you entered are invalid. Please enter them again."
       
   135         Abort
       
   136         
       
   137       ; This can be an error-prone process because entering credentials manually will keep
       
   138       ; the installer from touching the database. If tables already exist, Enano's installer
       
   139       ; will throw an error. Confirm this with the user.
       
   140       MessageBox MB_YESNO|MB_ICONQUESTION "Do you really want to use manual database settings?$\r$\n\
       
   141                                            $\r$\n\
       
   142                                            Setup will not attempt to modify your existing database. If there is \
       
   143                                            already an installation of $(^Name) in the database, the installer will \
       
   144                                            fail. This option is recommended only for advanced users." IDYES +2
       
   145         Abort ; on No
       
   146       
       
   147       Return
       
   148       
       
   149     GenerateRandomLogin:
       
   150       StrCpy $db_name "bn_enanocms"
       
   151       StrCpy $db_user "bn_enanocms"
       
   152       Call GenerateRandomPassword
       
   153       Pop $db_password
       
   154       Return
       
   155   
       
   156 FunctionEnd
       
   157 
       
   158 Function GenerateRandomPassword
       
   159   SetOutPath $PLUGINSDIR
       
   160   File "inst-resources\randompass.php"
       
   161   nsExec::ExecToStack '"$stack_instdir\php\php.exe" "$PLUGINSDIR\randompass.php"'
       
   162   Pop $R0
       
   163 FunctionEnd