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