fix-memory-alloc-srv-cfg-wizard-20031206
[openafs.git] / src / WINNT / afssvrcfg / root_afs_page.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * INCLUDES _________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afscfg.h"
20 #include "resource.h"
21
22
23 /*
24  * DEFINITIONS _________________________________________________________________
25  *
26  */
27 static HWND hDlg = 0;
28
29
30 /*
31  * PROTOTYPES _________________________________________________________________
32  *
33  */
34 static void OnInitDialog(HWND hwndDlg);
35 static void ShowStatusMsg(UINT nMsgID);
36
37
38 /*
39  * EXPORTED FUNCTIONS __________________________________________________________
40  *
41  */
42
43 /*
44  * Dialog Proc _________________________________________________________________
45  *
46  */
47 BOOL CALLBACK RootAfsPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
48 {
49         if (WizStep_Common_DlgProc (hwndDlg, msg, wp, lp))
50                 return FALSE;
51
52         switch (msg) {
53                 case WM_INITDIALOG:
54                  OnInitDialog(hwndDlg);
55                      break;
56
57                 case WM_COMMAND:
58                         switch (LOWORD(wp)) {
59                                 case IDNEXT:
60                                         g_pWiz->SetState(sidSTEP_TEN);
61                                         break;
62
63                                 case IDBACK:
64                                    g_pWiz->SetState(sidSTEP_EIGHT);
65                                    break;
66
67                                 case IDC_DONT_CREATE_ROOT_VOLUMES:
68                                         g_CfgData.configRootVolumes = CS_DONT_CONFIGURE;
69                                         break;
70
71                                 case IDC_CREATE_ROOT_VOLUMES:
72                                         g_CfgData.configRootVolumes = CS_CONFIGURE;
73                                         break;
74                         }
75                 break;
76
77         }
78
79         return FALSE;
80 }
81
82
83
84 /*
85  * STATIC FUNCTIONS _________________________________________________________________
86  *
87  */
88
89 /*
90  * Event Handler Functions _________________________________________________________________
91  *
92  */
93 static void OnInitDialog(HWND hwndDlg)
94 {
95         hDlg = hwndDlg;
96
97         g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
98         g_pWiz->SetButtonText(IDNEXT, IDS_NEXT);
99         g_pWiz->SetDefaultControl(IDNEXT);
100
101         if (g_CfgData.bFirstServer) {
102                 ShowStatusMsg(IDS_MUST_CREATE_ROOT_AFS);
103                 g_CfgData.configRootVolumes = CS_CONFIGURE;
104                 return;
105         }
106
107         if (g_CfgData.configRootVolumes == CS_ALREADY_CONFIGURED) {
108                 ShowStatusMsg(IDS_ROOT_AFS_ALREADY_EXISTS);
109         return;
110         }
111
112         // If the existence of the root volumes could not be determined, we'll
113         // ask the user if they want to create them if they don't already exist.
114         if (!g_CfgData.bRootVolumesExistanceKnown) {
115         SetWndText(hDlg, IDC_ROOT_AFS_QUESTION, IDS_CREATE_ROOT_VOLUMES_IF_NECESSARY_PROMPT);
116                 SetCheck(hDlg, IDC_CREATE_ROOT_VOLUMES);
117         g_CfgData.configRootVolumes = CS_CONFIGURE;
118         return;
119         }
120
121         // Should this step be disabled?  Yes, if this machine does
122         // not have a partition to make root.afs on.
123         if (!ConfiguredOrConfiguring(g_CfgData.configPartition)) {
124                 ShowStatusMsg(IDS_NO_PARTITION_EXISTS);
125                 EnableStep(g_CfgData.configRootVolumes, FALSE);
126                 return;
127         }
128
129     // If root.afs exists already but root.cell does not exist, then 
130     // the wizard cannot make root.cell and must disable this option.  
131     // However, since the root volumes don't both exist, we will leave 
132     // this option enabled, and only disable the yes check box.
133     // TODO:  We should handle this better in a future version where we can
134     // add new messages.  The message catalog is frozen for this version
135     // so we have to handle this case without adding new messages.
136         if (g_CfgData.bRootAfsExists && !g_CfgData.bRootCellExists) {
137         EnableWnd(hDlg, IDC_CREATE_ROOT_VOLUMES, FALSE);
138                 SetCheck(hDlg, IDC_DONT_CREATE_ROOT_VOLUMES);
139         g_CfgData.configRootVolumes = CS_DONT_CONFIGURE;
140         return;
141         }
142
143         // Must do this in case it was disabled on the last run through
144         EnableStep(g_CfgData.configRootVolumes);
145
146         if (g_CfgData.configRootVolumes == CS_DONT_CONFIGURE)
147                 SetCheck(hDlg, IDC_DONT_CREATE_ROOT_VOLUMES);
148         else
149                 SetCheck(hDlg, IDC_CREATE_ROOT_VOLUMES);
150 }
151
152
153 /*
154  * Utility Functions _________________________________________________________________
155  *
156  */
157 static void ShowStatusMsg(UINT nMsgID)
158 {
159         TCHAR szMsg[cchRESOURCE];
160
161         GetString(szMsg, nMsgID);
162
163         // Hide the controls that are at the same position as the message
164         ShowWnd(hDlg, IDC_ROOT_AFS_QUESTION, FALSE);
165         ShowWnd(hDlg, IDC_CREATE_ROOT_VOLUMES, FALSE);
166         ShowWnd(hDlg, IDC_DONT_CREATE_ROOT_VOLUMES, FALSE);
167         
168         SetWndText(hDlg, IDC_ROOT_AFS_MSG, szMsg);
169         ShowWnd(hDlg, IDC_ROOT_AFS_MSG);
170 }
171