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>
19 #include "afscfg.h" // Main header for this application
21 #include "create_partition_dlg.h"
22 #include "volume_utils.h"
23 #include "partition_utils.h"
27 * DEFINITIONS ________________________________________________________________
30 static HWND hDlg = 0; // This dialog's HWND
31 static HWND hDriveList = 0;
32 static BOOL bAutoSetPartitionName = TRUE;
33 static HLISTITEM hSelectedItem = 0;
34 static BOOL bCreated; // TRUE if a partition was created
36 static const UINT IDD = IDD_CREATE_PARTITION; // Dialog's resource ID
38 static TCHAR szPartitionName[MAX_PARTITION_NAME_LEN];
39 static TCHAR szDrive[4];
40 static TCHAR szSize[32];
42 static rwWindowData arwDialog[] = {
43 { IDC_TITLE, raSizeX | raRepaint, 0, 0 },
44 { IDC_DRIVE_LIST, raSizeX | raSizeY, MAKELONG(350, 150), 0 },
45 { IDC_ARGS_FRAME, raSizeX | raMoveY, 0, 0 },
46 { IDC_NAME_STATIC, raMoveY | raRepaint, 0, 0 },
47 { IDC_VICEP_STATIC, raMoveY | raRepaint, 0, 0 },
48 { IDC_PARTITION_NAME, raMoveY | raRepaint, 0, 0 },
49 { IDC_CREATE, raMoveX | raMoveY, 0, 0 },
50 { IDC_CLOSE, raMoveX | raMoveY, 0, 0 },
51 { 9, raMoveX | raMoveY, 0, 0 },
52 { idENDLIST, 0, 0, 0 }
57 * PROTOTYPES _________________________________________________________________
60 static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
61 static void OnInitDialog(HWND hwndDlg);
62 static void OnClose();
63 static void OnCreate();
64 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms);
65 static void OnPartitionName();
66 static void CheckEnableButtons();
70 * EXPORTED FUNCTIONS _________________________________________________________
73 BOOL CreatePartition(HWND hParent)
75 ModalDialog(IDD, hParent, (DLGPROC)DlgProc);
82 * STATIC FUNCTIONS ___________________________________________________________
87 * Dialog Proc ________________________________________________________________
90 static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
92 if (AfsAppLib_HandleHelp(IDD_CREATE_PARTITION, hwndDlg, uMsg, wParam, lParam))
96 case WM_INITDIALOG: OnInitDialog(hwndDlg);
99 case WM_COMMAND: switch (LOWORD(wParam)) {
100 case IDC_CLOSE: OnClose();
103 case IDC_CREATE: OnCreate();
106 case IDC_PARTITION_NAME:
107 if (HIWORD(wParam) == EN_CHANGE) {
109 SetFocus((HWND)lParam);
115 case WM_NCACTIVATE: if (wParam)
119 case WM_NOTIFY: if ((((LPNMHDR)lParam)->code) == FLN_ITEMSELECT)
120 OnListSelection((LPFLN_ITEMSELECT_PARAMS)lParam);
123 case WM_SIZE: if (lParam != 0)
124 ResizeWindow(hwndDlg, arwDialog, rwaFixupGuts);
134 * Event Handler Functions ____________________________________________________
137 static void OnInitDialog(HWND hwndDlg)
141 ResizeWindow(hDlg, arwDialog, rwaFixupGuts);
143 hDriveList = GetDlgItem(hDlg, IDC_DRIVE_LIST);
145 bAutoSetPartitionName = TRUE;
148 SetupDriveList(hDriveList);
153 static void OnClose()
155 EndDialog(hDlg, IDCANCEL);
158 static void OnCreate()
162 HLISTITEM hItem = FastList_FindFirstSelected(hDriveList);
165 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szPartitionName, sizeof(szPartitionName));
166 if (!Validation_IsValid(szPartitionName, VALID_AFS_PARTITION_NAME))
169 lstrcpy(szDrive, FastList_GetItemText(hDriveList, hItem, 0));
170 lstrcpy(szSize, FastList_GetItemText(hDriveList, hItem, 2));
172 // Constuct the device name
173 char szDevNameA[] = "?:";
175 szDevNameA[0] = ((char*)drive)[0];
177 // Construct the partition name
178 char szPartNameA[9] = "/vicep";
179 strncat(szPartNameA, (char *)S2A(szPartitionName), 2);
181 if (DoesPartitionExist(A2S(szPartNameA))) {
182 MsgBox(hDlg, IDS_PARTITION_EXISTS, GetAppTitleID(), MB_OK | MB_ICONSTOP);
186 g_LogFile.Write("Adding an AFS partition on device '%s' with name '%s'.\r\n", szDevNameA, szPartNameA);
188 afs_status_t nStatus;
189 int nResult = cfg_HostPartitionTableAddEntry(g_hServer, szPartNameA, szDevNameA, &nStatus);
191 ShowError(hDlg, nStatus, IDS_CREATE_PARTITION_ERROR);
195 MsgBox(hDlg, IDS_PARTITION_CREATED, GetAppTitleID(), MB_OK);
199 SetWndText(hDlg, IDC_PARTITION_NAME, TEXT(""));
202 static void OnPartitionName()
204 TCHAR szBuf[MAX_PARTITION_NAME_LEN];
205 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
207 bAutoSetPartitionName = szBuf[0] == 0;
209 CheckEnableButtons();
212 static void OnListSelection(LPFLN_ITEMSELECT_PARAMS pItemParms)
218 if (pItemParms->hItem) {
219 LPARAM lParam = FastList_GetItemParam(hDriveList, pItemParms->hItem);
221 hSelectedItem = pItemParms->hItem;
223 if (bAutoSetPartitionName) {
225 LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
226 szName[0] = _totlower(pDrive[0]);
229 TCHAR szFullName[6] = TEXT("vice");
230 lstrcat(szFullName, szName);
232 if (!DoesPartitionExist(szFullName)) {
233 SetWndText(hDlg, IDC_PARTITION_NAME, szName);
235 // Must set this to true because the call to SetWndText will cause
236 // a call to OnPartitionName, which would incorrectly think that the
237 // Partition Name had been set by the user rather than by us, thus
238 // setting bAutoSetPartitionName to false.
239 bAutoSetPartitionName = TRUE;
245 CheckEnableButtons();
248 static void CheckEnableButtons()
250 TCHAR szBuf[MAX_PARTITION_NAME_LEN];
252 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szBuf, MAX_PARTITION_NAME_LEN);
254 ENABLE_STATE es = ES_ENABLE;
256 if ((hSelectedItem == 0) || (szBuf[0] == 0))
259 SetEnable(hDlg, IDC_CREATE, es);