2
* Copyright 2000, International Business Machines Corporation and others.
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
11
* INCLUDES _________________________________________________________________
15
#include <afs/param.h>
22
#include "volume_utils.h"
26
* DEFINITIONS _________________________________________________________________
30
static HWND hDriveList = 0;
31
static BOOL bCantCreate = FALSE;
32
static HLISTITEM hSelectedItem = 0;
34
// The idea for this var is that if the user clicks on a drive and the vice name
35
// hasn't been set by the user, then we will set the vice name to the drive letter
36
// selected. However, if the user sets the vice name, then clicking on a drive
37
// letter doesn't change the vice name. This var tells us whether it is ok to set
38
// the vice name or not.
39
static BOOL bAutoSetPartitionName = TRUE;
43
* PROTOTYPES _________________________________________________________________
46
static void OnInitDialog(HWND hwndDlg);
47
static void EnableDriveListCtrls(BOOL bEnable = TRUE);
48
static BOOL SavePartitionInfo(BOOL bValidate);
49
static void ShowPartitionInfo();
50
static void CheckEnableButtons();
51
static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms);
52
static void CantMakePartition(UINT nMsgID);
53
static void MustMakePartition();
54
static void OnPartitionName();
58
* EXPORTED FUNCTIONS _________________________________________________________________
63
* Dialog Proc _________________________________________________________________
67
* WndProc for our subclass of the wizard's dialog. We do this to detect
68
* the WM_ACTIVATEAPP message, which we use as a trigger to refresh the
69
* partition info that we display.
71
static BOOL CALLBACK WizardDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
73
if ((g_pWiz->GetState() == sidSTEP_EIGHT) && (uMsg == WM_ACTIVATEAPP) && wParam) {
78
return CallWindowProc((WNDPROC)Subclass_FindNextHook(hwndDlg, WizardDlgProc), hwndDlg, uMsg, wParam, lParam);
81
BOOL CALLBACK PartitionPageDlgProc(HWND hwndDlg, UINT msg, WPARAM wp, LPARAM lp)
83
if (WizStep_Common_DlgProc (hwndDlg, msg, wp, lp))
88
OnInitDialog(hwndDlg);
92
case WM_DESTROY_SHEET:
93
Subclass_RemoveHook(g_pWiz->GetWindow(), WizardDlgProc);
99
if (SavePartitionInfo(TRUE))
100
g_pWiz->SetState(sidSTEP_NINE);
104
if (SavePartitionInfo(FALSE))
105
g_pWiz->SetState(sidSTEP_SEVEN);
108
case IDC_CREATE_PARTITION:
109
g_CfgData.configPartition = CS_CONFIGURE;
110
CheckEnableButtons();
111
EnableDriveListCtrls();
114
case IDC_DONT_CREATE_PARTITION:
115
g_CfgData.configPartition = CS_DONT_CONFIGURE;
116
CheckEnableButtons();
117
EnableDriveListCtrls(FALSE);
120
case IDC_PARTITION_NAME:
121
if (HIWORD(wp) == EN_CHANGE) {
130
switch (((LPNMHDR)lp)->code) {
131
case FLN_ITEMSELECT: OnListSelection((LPFLN_ITEMSELECT_PARAMS)lp);
143
* STATIC FUNCTIONS _________________________________________________________________
148
* Event Handler Functions _________________________________________________________________
151
static void OnInitDialog(HWND hwndDlg)
157
hDriveList = GetDlgItem(hDlg, IDC_DRIVE_LIST);
159
g_pWiz->SetButtonText(IDNEXT, IDS_NEXT);
160
g_pWiz->SetDefaultControl(IDNEXT);
162
if (g_CfgData.configPartition == CS_ALREADY_CONFIGURED) {
163
CantMakePartition(IDS_PARTITION_ALREADY_CREATED);
167
// Should this step be disabled? Yes, if this machine is
168
// not configured as a file server.
169
if (!ConfiguredOrConfiguring(g_CfgData.configFS)) {
170
CantMakePartition(IDS_NOT_A_FS_SERVER);
171
EnableStep(g_CfgData.configPartition, FALSE);
175
// Do this in case it was disabled the last time
176
EnableStep(g_CfgData.configPartition);
178
switch (g_CfgData.configPartition) {
179
case CS_DONT_CONFIGURE:
180
SetCheck(hDlg, IDC_DONT_CREATE_PARTITION);
181
EnableDriveListCtrls(FALSE);
186
SetCheck(hDlg, IDC_CREATE_PARTITION);
187
EnableDriveListCtrls();
191
Subclass_AddHook(g_pWiz->GetWindow(), WizardDlgProc);
193
SetupDriveList(hDriveList);
197
if (g_CfgData.bFirstServer)
201
static void OnPartitionName()
203
TCHAR szBuf[MAX_PARTITION_NAME_LEN];
204
GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
206
bAutoSetPartitionName = szBuf[0] == 0;
208
CheckEnableButtons();
211
static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms)
217
if (pItemParms->hItem) {
218
LPARAM lParam = FastList_GetItemParam(hDriveList, pItemParms->hItem);
220
hSelectedItem = pItemParms->hItem;
222
if (bAutoSetPartitionName) {
223
LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
224
g_CfgData.szPartitionName[0] = _totlower(pDrive[0]);
225
g_CfgData.szPartitionName[1] = 0;
226
SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
228
// Must set this to true because the call to SetWndText will cause
229
// a call to OnPartitionName, which would incorrectly think that the
230
// Partition Name had been set by the user rather than by us, thus
231
// setting bAutoSetPartitionName to false.
232
bAutoSetPartitionName = TRUE;
237
CheckEnableButtons();
242
* Utility Functions _________________________________________________________________
245
static void CantMakePartition(UINT nMsgID)
247
TCHAR szMsg[cchRESOURCE];
249
GetString(szMsg, nMsgID);
251
ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
252
ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
253
ShowWnd(hDlg, IDC_ASK_CREATE_PARTITION, FALSE);
254
ShowWnd(hDlg, IDC_SELECT_DRIVE, FALSE);
255
ShowWnd(hDlg, IDC_DRIVE_LIST, FALSE);
256
ShowWnd(hDlg, IDC_NAME_LABEL, FALSE);
257
ShowWnd(hDlg, IDC_PARTITION_NAME, FALSE);
259
ShowWnd(hDlg, IDC_PARTITION_COVER);
260
HWND hMsg = GetDlgItem(hDlg, IDC_PARTITION_MSG);
261
ShowWindow(hMsg, SW_SHOW);
262
SetWindowText(hMsg, szMsg);
267
static void MustMakePartition()
269
TCHAR szMsg[cchRESOURCE];
271
GetString(szMsg, IDS_MUST_MAKE_PARTITION);
273
ShowWnd(hDlg, IDC_CREATE_PARTITION, FALSE);
274
ShowWnd(hDlg, IDC_DONT_CREATE_PARTITION, FALSE);
276
SetWndText(hDlg, IDC_ASK_CREATE_PARTITION, szMsg);
279
static void EnableDriveListCtrls(BOOL bEnable)
281
EnableWnd(hDlg, IDC_SELECT_DRIVE, bEnable);
282
EnableWnd(hDlg, IDC_DRIVE_LIST, bEnable);
283
EnableWnd(hDlg, IDC_NAME_LABEL, bEnable);
284
EnableWnd(hDlg, IDC_PARTITION_NAME, bEnable);
287
static BOOL SavePartitionInfo(BOOL bValidate)
292
if (GetButtonState(hDlg, IDC_CREATE_PARTITION) != BST_CHECKED) {
293
g_CfgData.szPartitionName[0] = 0;
294
bAutoSetPartitionName = TRUE;
296
GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), g_CfgData.szPartitionName, MAX_PARTITION_NAME_LEN);
297
if (bValidate && !Validation_IsValid(g_CfgData.szPartitionName, VALID_AFS_PARTITION_NAME))
301
if (hSelectedItem == 0)
302
g_CfgData.chDeviceName = 0;
304
LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
305
g_CfgData.chDeviceName = pDrive[0];
311
static void ShowPartitionInfo()
313
// The SetWndText call below will mess up our bAutoSetPartitionName variable.
314
// It will trigger the change event on the partition name field causing our
315
// OnPartitionName function to get called, and making it look to us like the
316
// user set the partition name. Therefore, we will save the current value,
317
// make the call, then restore the value.
318
BOOL bAutoSet = bAutoSetPartitionName;
319
SetWndText(hDlg, IDC_PARTITION_NAME, g_CfgData.szPartitionName);
320
bAutoSetPartitionName = bAutoSet;
322
if (g_CfgData.chDeviceName != 0) {
323
HLISTITEM hItem = NULL;
324
while ((hItem = FastList_FindNext(hDriveList, hItem)) != NULL) {
325
LPCTSTR pDrive = FastList_GetItemText(hDriveList, hItem, 0);
326
if (pDrive[0] == g_CfgData.chDeviceName) {
327
FastList_SelectItem(hDriveList, hItem, TRUE);
328
hSelectedItem = hItem;
335
static void CheckEnableButtons()
337
if (IsButtonChecked(hDlg, IDC_CREATE_PARTITION)) {
338
TCHAR szBuf[MAX_PARTITION_NAME_LEN];
340
GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
341
if ((hSelectedItem == 0) || (szBuf[0] == 0)) {
342
g_pWiz->EnableButtons(BACK_BUTTON);
343
g_pWiz->SetDefaultControl(IDBACK);
348
g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);