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 ___________________________________________________________________
18 #include <afs/param.h>
22 #include "afscfg.h" // Main header for this application
24 #include "create_partition_dlg.h"
25 #include "volume_utils.h"
26 #include "partition_utils.h"
30 * DEFINITIONS ________________________________________________________________
33 static HWND hDlg
= 0; // This dialog's HWND
34 static HWND hDriveList
= 0;
35 static BOOL bAutoSetPartitionName
= TRUE
;
36 static HLISTITEM hSelectedItem
= 0;
37 static BOOL bCreated
; // TRUE if a partition was created
39 static const UINT IDD
= IDD_CREATE_PARTITION
; // Dialog's resource ID
41 static TCHAR szPartitionName
[MAX_PARTITION_NAME_LEN
];
42 static TCHAR szDrive
[4];
43 static TCHAR szSize
[32];
45 static rwWindowData arwDialog
[] = {
46 { IDC_TITLE
, raSizeX
| raRepaint
, 0, 0 },
47 { IDC_DRIVE_LIST
, raSizeX
| raSizeY
, MAKELONG(350, 150), 0 },
48 { IDC_ARGS_FRAME
, raSizeX
| raMoveY
, 0, 0 },
49 { IDC_NAME_STATIC
, raMoveY
| raRepaint
, 0, 0 },
50 { IDC_VICEP_STATIC
, raMoveY
| raRepaint
, 0, 0 },
51 { IDC_PARTITION_NAME
, raMoveY
| raRepaint
, 0, 0 },
52 { IDC_CREATE
, raMoveX
| raMoveY
, 0, 0 },
53 { IDC_CLOSE
, raMoveX
| raMoveY
, 0, 0 },
54 { 9, raMoveX
| raMoveY
, 0, 0 },
55 { idENDLIST
, 0, 0, 0 }
60 * PROTOTYPES _________________________________________________________________
63 static BOOL CALLBACK
DlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
64 static void OnInitDialog(HWND hwndDlg
);
65 static void OnClose();
66 static void OnCreate();
67 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms
);
68 static void OnPartitionName();
69 static void CheckEnableButtons();
73 * EXPORTED FUNCTIONS _________________________________________________________
76 BOOL
CreatePartition(HWND hParent
)
78 ModalDialog(IDD
, hParent
, (DLGPROC
)DlgProc
);
85 * STATIC FUNCTIONS ___________________________________________________________
90 * Dialog Proc ________________________________________________________________
93 static BOOL CALLBACK
DlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
95 if (AfsAppLib_HandleHelp(IDD_CREATE_PARTITION
, hwndDlg
, uMsg
, wParam
, lParam
))
99 case WM_INITDIALOG
: OnInitDialog(hwndDlg
);
103 switch (LOWORD(wParam
)) {
112 case IDC_PARTITION_NAME
:
113 if (HIWORD(wParam
) == EN_CHANGE
) {
115 SetFocus((HWND
)lParam
);
121 case WM_NCACTIVATE
: if (wParam
)
126 if ((((LPNMHDR
)lParam
)->code
) == FLN_ITEMSELECT
)
127 OnListSelection((LPFLN_ITEMSELECT_PARAMS
)lParam
);
132 ResizeWindow(hwndDlg
, arwDialog
, rwaFixupGuts
);
142 * Event Handler Functions ____________________________________________________
145 static void OnInitDialog(HWND hwndDlg
)
149 ResizeWindow(hDlg
, arwDialog
, rwaFixupGuts
);
151 hDriveList
= GetDlgItem(hDlg
, IDC_DRIVE_LIST
);
153 bAutoSetPartitionName
= TRUE
;
156 SetupDriveList(hDriveList
);
161 static void OnClose()
163 EndDialog(hDlg
, IDCANCEL
);
166 static void OnCreate()
170 HLISTITEM hItem
= FastList_FindFirstSelected(hDriveList
);
173 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), szPartitionName
, sizeof(szPartitionName
));
174 if (!Validation_IsValid(szPartitionName
, VALID_AFS_PARTITION_NAME
))
177 lstrcpy(szDrive
, FastList_GetItemText(hDriveList
, hItem
, 0));
178 lstrcpy(szSize
, FastList_GetItemText(hDriveList
, hItem
, 2));
180 // Constuct the device name
181 char szDevNameA
[] = "?:";
183 szDevNameA
[0] = ((char*)drive
)[0];
185 // Construct the partition name
186 char szPartNameA
[9] = "/vicep";
187 strncat(szPartNameA
, (char *)S2A(szPartitionName
), 2);
189 if (DoesPartitionExist(A2S(szPartNameA
))) {
190 MsgBox(hDlg
, IDS_PARTITION_EXISTS
, GetAppTitleID(), MB_OK
| MB_ICONSTOP
);
194 g_LogFile
.Write("Adding an AFS partition on device '%s' with name '%s'.\r\n", szDevNameA
, szPartNameA
);
196 afs_status_t nStatus
;
197 int nResult
= cfg_HostPartitionTableAddEntry(g_hServer
, szPartNameA
, szDevNameA
, &nStatus
);
199 ShowError(hDlg
, nStatus
, IDS_CREATE_PARTITION_ERROR
);
203 MsgBox(hDlg
, IDS_PARTITION_CREATED
, GetAppTitleID(), MB_OK
);
207 SetWndText(hDlg
, IDC_PARTITION_NAME
, TEXT(""));
210 static void OnPartitionName()
212 TCHAR szBuf
[MAX_PARTITION_NAME_LEN
];
213 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), szBuf
, MAX_PARTITION_NAME_LEN
);
215 bAutoSetPartitionName
= szBuf
[0] == 0;
217 CheckEnableButtons();
220 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms
)
226 if (pItemParms
->hItem
) {
227 LPARAM lParam
= FastList_GetItemParam(hDriveList
, pItemParms
->hItem
);
229 hSelectedItem
= pItemParms
->hItem
;
231 if (bAutoSetPartitionName
) {
233 LPCTSTR pDrive
= FastList_GetItemText(hDriveList
, hSelectedItem
, 0);
234 szName
[0] = _totlower(pDrive
[0]);
237 TCHAR szFullName
[6] = TEXT("vice");
238 lstrcat(szFullName
, szName
);
240 if (!DoesPartitionExist(szFullName
)) {
241 SetWndText(hDlg
, IDC_PARTITION_NAME
, szName
);
243 // Must set this to true because the call to SetWndText will cause
244 // a call to OnPartitionName, which would incorrectly think that the
245 // Partition Name had been set by the user rather than by us, thus
246 // setting bAutoSetPartitionName to false.
247 bAutoSetPartitionName
= TRUE
;
253 CheckEnableButtons();
256 static void CheckEnableButtons()
258 TCHAR szBuf
[MAX_PARTITION_NAME_LEN
];
260 GetWindowText(GetDlgItem(hDlg
, IDC_PARTITION_NAME
), szBuf
, MAX_PARTITION_NAME_LEN
);
262 ENABLE_STATE es
= ES_ENABLE
;
264 if ((hSelectedItem
== 0) || (szBuf
[0] == 0))
267 SetEnable(hDlg
, IDC_CREATE
, es
);