Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrcfg / create_partition_dlg.cpp
blobe9fd5681b6c9578a245031de0e212528cafd74f2
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
11 * INCLUDES ___________________________________________________________________
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
22 #include "afscfg.h" // Main header for this application
23 #include "resource.h"
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);
80 return bCreated;
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))
96 return TRUE;
98 switch (uMsg) {
99 case WM_INITDIALOG: OnInitDialog(hwndDlg);
100 break;
102 case WM_COMMAND:
103 switch (LOWORD(wParam)) {
104 case IDC_CLOSE:
105 OnClose();
106 break;
108 case IDC_CREATE:
109 OnCreate();
110 break;
112 case IDC_PARTITION_NAME:
113 if (HIWORD(wParam) == EN_CHANGE) {
114 OnPartitionName();
115 SetFocus((HWND)lParam);
117 break;
119 break;
121 case WM_NCACTIVATE: if (wParam)
122 UpdateDriveList();
123 break;
125 case WM_NOTIFY:
126 if ((((LPNMHDR)lParam)->code) == FLN_ITEMSELECT)
127 OnListSelection((LPFLN_ITEMSELECT_PARAMS)lParam);
128 break;
130 case WM_SIZE:
131 if (lParam != 0)
132 ResizeWindow(hwndDlg, arwDialog, rwaFixupGuts);
133 break;
137 return FALSE;
142 * Event Handler Functions ____________________________________________________
145 static void OnInitDialog(HWND hwndDlg)
147 hDlg = hwndDlg;
149 ResizeWindow(hDlg, arwDialog, rwaFixupGuts);
151 hDriveList = GetDlgItem(hDlg, IDC_DRIVE_LIST);
153 bAutoSetPartitionName = TRUE;
154 hSelectedItem = 0;
156 SetupDriveList(hDriveList);
158 bCreated = FALSE;
161 static void OnClose()
163 EndDialog(hDlg, IDCANCEL);
166 static void OnCreate()
168 ASSERT(g_hServer);
170 HLISTITEM hItem = FastList_FindFirstSelected(hDriveList);
171 _ASSERTE(hItem);
173 GetWindowText(GetDlgItem(hDlg, IDC_PARTITION_NAME), szPartitionName, sizeof(szPartitionName));
174 if (!Validation_IsValid(szPartitionName, VALID_AFS_PARTITION_NAME))
175 return;
177 lstrcpy(szDrive, FastList_GetItemText(hDriveList, hItem, 0));
178 lstrcpy(szSize, FastList_GetItemText(hDriveList, hItem, 2));
180 // Constuct the device name
181 char szDevNameA[] = "?:";
182 S2A drive(szDrive);
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);
191 return;
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);
198 if (!nResult) {
199 ShowError(hDlg, nStatus, IDS_CREATE_PARTITION_ERROR);
200 return;
203 MsgBox(hDlg, IDS_PARTITION_CREATED, GetAppTitleID(), MB_OK);
205 bCreated = TRUE;
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)
222 ASSERT(pItemParms);
224 hSelectedItem = 0;
226 if (pItemParms->hItem) {
227 LPARAM lParam = FastList_GetItemParam(hDriveList, pItemParms->hItem);
228 if (lParam == 0) {
229 hSelectedItem = pItemParms->hItem;
231 if (bAutoSetPartitionName) {
232 TCHAR szName[2];
233 LPCTSTR pDrive = FastList_GetItemText(hDriveList, hSelectedItem, 0);
234 szName[0] = _totlower(pDrive[0]);
235 szName[1] = 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))
265 es = ES_DISABLE;
267 SetEnable(hDlg, IDC_CREATE, es);