Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / set_clone.cpp
blobe73a29c141647e007b83ba1e7eff02eb859b9073
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "set_clone.h"
20 #include "propcache.h"
24 * DEFINITIONS ________________________________________________________________
30 * PROTOTYPES _________________________________________________________________
34 BOOL CALLBACK Filesets_Clone_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
35 void Filesets_Clone_OnInitDialog (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
37 BOOL CALLBACK Filesets_Clonesys_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
38 void Filesets_Clonesys_OnInitDialog (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
39 void Filesets_Clonesys_OnOK (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
40 void Filesets_Clonesys_OnSelect (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
41 void Filesets_Clonesys_OnSelectServer (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
42 void Filesets_Clonesys_OnEndTask_EnumServers (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
43 void Filesets_Clonesys_OnEndTask_EnumAggregs (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp);
47 * ROUTINES ___________________________________________________________________
51 void Filesets_Clone (LPIDENT lpi)
53 LPSET_CLONESYS_PARAMS pcsp = New (SET_CLONESYS_PARAMS);
54 memset (pcsp, 0x00, sizeof(SET_CLONESYS_PARAMS));
55 pcsp->lpi = (lpi == NULL) ? g.lpiCell : lpi;
57 INT_PTR rc;
58 if (pcsp->lpi && pcsp->lpi->fIsFileset())
59 rc = ModalDialogParam (IDD_SET_CLONE, NULL, (DLGPROC)Filesets_Clone_DlgProc, (LPARAM)pcsp);
60 else
61 rc = ModalDialogParam (IDD_SET_CLONESYS, NULL, (DLGPROC)Filesets_Clonesys_DlgProc, (LPARAM)pcsp);
63 if ((rc != IDOK) || (!pcsp->lpi))
65 Delete (pcsp);
67 else if (pcsp->lpi->fIsFileset()) // clone one fileset?
69 StartTask (taskSET_CLONE, NULL, pcsp->lpi);
70 Delete (pcsp);
72 else // or clone lots of filesets?
74 StartTask (taskSET_CLONESYS, NULL, pcsp);
75 // don't delete pcsp--it'll be freed by the StartTask handler
81 BOOL CALLBACK Filesets_Clone_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
83 if (AfsAppLib_HandleHelp (IDD_SET_CLONE, hDlg, msg, wp, lp))
84 return TRUE;
86 if (msg == WM_INITDIALOG)
87 SetWindowLongPtr (hDlg, DWLP_USER, lp);
89 LPSET_CLONESYS_PARAMS pcsp = (LPSET_CLONESYS_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER);
91 if (pcsp != NULL)
93 switch (msg)
95 case WM_INITDIALOG:
96 PropCache_Add (pcSET_CLONE, NULL, hDlg);
97 Filesets_Clone_OnInitDialog (hDlg, pcsp);
98 break;
100 case WM_COMMAND:
101 switch (LOWORD(wp))
103 case IDOK:
104 case IDCANCEL:
105 EndDialog (hDlg, LOWORD(wp));
106 break;
108 break;
110 case WM_DESTROY:
111 PropCache_Delete (pcSET_CLONE, NULL);
112 break;
116 return FALSE;
120 void Filesets_Clone_OnInitDialog (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
122 TCHAR szServer[ cchNAME ];
123 TCHAR szAggregate[ cchNAME ];
124 TCHAR szFileset[ cchNAME ];
125 pcsp->lpi->GetServerName (szServer);
126 pcsp->lpi->GetAggregateName (szAggregate);
127 pcsp->lpi->GetFilesetName (szFileset);
129 TCHAR szText[ cchRESOURCE ];
130 GetDlgItemText (hDlg, IDC_CLONE_DESC, szText, cchRESOURCE);
132 LPTSTR pszText = FormatString (szText, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
133 SetDlgItemText (hDlg, IDC_CLONE_DESC, pszText);
134 FreeString (pszText);
138 BOOL CALLBACK Filesets_Clonesys_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
140 if (AfsAppLib_HandleHelp (IDD_SET_CLONESYS, hDlg, msg, wp, lp))
141 return TRUE;
143 if (msg == WM_INITDIALOG)
144 SetWindowLongPtr (hDlg, DWLP_USER, lp);
146 LPSET_CLONESYS_PARAMS pcsp = (LPSET_CLONESYS_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER);
148 if (pcsp != NULL)
150 switch (msg)
152 case WM_INITDIALOG:
153 PropCache_Add (pcSET_CLONE, NULL, hDlg);
154 Filesets_Clonesys_OnInitDialog (hDlg, pcsp);
155 break;
157 case WM_ENDTASK:
158 LPTASKPACKET ptp;
159 if ((ptp = (LPTASKPACKET)lp) != NULL)
161 if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
163 Filesets_Clonesys_OnEndTask_EnumServers (hDlg, pcsp);
165 else if (ptp->idTask == taskAGG_ENUM_TO_COMBOBOX)
167 Filesets_Clonesys_OnEndTask_EnumAggregs (hDlg, pcsp);
169 FreeTaskPacket (ptp);
171 break;
173 case WM_COMMAND:
174 switch (LOWORD(wp))
176 case IDOK:
177 Filesets_Clonesys_OnOK (hDlg, pcsp);
178 EndDialog (hDlg, IDOK);
179 break;
181 case IDCANCEL:
182 EndDialog (hDlg, IDCANCEL);
183 break;
185 case IDC_CLONE_ALL:
186 case IDC_CLONE_SOME:
187 case IDC_CLONE_SVR_LIMIT:
188 case IDC_CLONE_AGG_LIMIT:
189 case IDC_CLONE_PREFIX_LIMIT:
190 Filesets_Clonesys_OnSelect (hDlg, pcsp);
191 break;
193 case IDC_CLONE_SVR:
194 if (HIWORD(wp) == CBN_SELCHANGE)
196 Filesets_Clonesys_OnSelectServer (hDlg, pcsp);
198 break;
200 break;
202 case WM_DESTROY:
203 PropCache_Delete (pcSET_CLONE, NULL);
204 break;
208 return FALSE;
212 void Filesets_Clonesys_OnInitDialog (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
214 CheckDlgButton (hDlg, IDC_CLONE_ALL, pcsp->lpi->fIsCell());
215 CheckDlgButton (hDlg, IDC_CLONE_SOME, !pcsp->lpi->fIsCell());
216 CheckDlgButton (hDlg, IDC_CLONE_SVR_LIMIT, !pcsp->lpi->fIsCell());
217 CheckDlgButton (hDlg, IDC_CLONE_AGG_LIMIT, pcsp->lpi->fIsAggregate());
219 pcsp->fEnumedServers = FALSE;
220 pcsp->fEnumedAggregs = FALSE;
221 Filesets_Clonesys_OnSelect (hDlg, pcsp);
223 LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
224 lpp->hCombo = GetDlgItem (hDlg, IDC_CLONE_SVR);
225 lpp->lpiSelect = (pcsp->lpi && !pcsp->lpi->fIsCell()) ? pcsp->lpi->GetServer() : NULL;
226 StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);
230 void Filesets_Clonesys_OnOK (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
232 if (IsDlgButtonChecked (hDlg, IDC_CLONE_ALL))
234 pcsp->lpi = g.lpiCell;
235 pcsp->fUsePrefix = FALSE;
236 pcsp->szPrefix[0] = TEXT('\0');
238 else // (IsDlgButtonChecked (hDlg, IDC_CLONE_SOME))
240 if (IsDlgButtonChecked (hDlg, IDC_CLONE_AGG_LIMIT))
241 pcsp->lpi = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_CLONE_AGG));
242 else if (IsDlgButtonChecked (hDlg, IDC_CLONE_SVR_LIMIT))
243 pcsp->lpi = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_CLONE_SVR));
244 else
245 pcsp->lpi = g.lpiCell;
247 pcsp->fUsePrefix = IsDlgButtonChecked (hDlg, IDC_CLONE_PREFIX_LIMIT);
248 GetDlgItemText (hDlg, IDC_CLONE_PREFIX, pcsp->szPrefix, MAX_PATH);
250 if (pcsp->fUsePrefix && (pcsp->szPrefix[0] == TEXT('!')))
252 TCHAR szPrefixNoBang[ cchRESOURCE ];
253 lstrcpy (szPrefixNoBang, &pcsp->szPrefix[1]);
254 lstrcpy (pcsp->szPrefix, szPrefixNoBang);
255 pcsp->fExcludePrefix = TRUE;
261 void Filesets_Clonesys_OnSelect (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
263 BOOL fCloneAll = (IsDlgButtonChecked (hDlg, IDC_CLONE_ALL)) ? TRUE : FALSE;
265 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_SVR_LIMIT), !fCloneAll);
266 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_AGG_LIMIT), !fCloneAll);
267 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_PREFIX_LIMIT), !fCloneAll);
269 if (fCloneAll)
271 CheckDlgButton (hDlg, IDC_CLONE_SVR_LIMIT, FALSE);
272 CheckDlgButton (hDlg, IDC_CLONE_AGG_LIMIT, FALSE);
273 CheckDlgButton (hDlg, IDC_CLONE_PREFIX_LIMIT, FALSE);
276 BOOL fEnable;
278 fEnable = IsDlgButtonChecked (hDlg, IDC_CLONE_SVR_LIMIT) && pcsp->fEnumedServers;
279 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_SVR), fEnable);
281 fEnable = IsDlgButtonChecked (hDlg, IDC_CLONE_SVR_LIMIT);
282 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_AGG_LIMIT), fEnable);
283 if (!fEnable)
284 CheckDlgButton (hDlg, IDC_CLONE_AGG_LIMIT, FALSE);
286 fEnable = fEnable && IsDlgButtonChecked (hDlg, IDC_CLONE_AGG_LIMIT) && pcsp->fEnumedAggregs;
287 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_AGG), fEnable);
289 fEnable = IsDlgButtonChecked (hDlg, IDC_CLONE_PREFIX_LIMIT);
290 EnableWindow (GetDlgItem (hDlg, IDC_CLONE_PREFIX), fEnable);
292 fEnable = TRUE;
293 if (IsDlgButtonChecked (hDlg, IDC_CLONE_SVR_LIMIT) && !pcsp->fEnumedServers)
294 fEnable = FALSE;
295 if (IsDlgButtonChecked (hDlg, IDC_CLONE_AGG_LIMIT) && !pcsp->fEnumedAggregs)
296 fEnable = FALSE;
297 EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
301 void Filesets_Clonesys_OnSelectServer (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
303 pcsp->fEnumedAggregs = FALSE;
304 Filesets_Clonesys_OnSelect (hDlg, pcsp);
306 LPAGG_ENUM_TO_COMBOBOX_PACKET lpp = New (AGG_ENUM_TO_COMBOBOX_PACKET);
307 lpp->hCombo = GetDlgItem (hDlg, IDC_CLONE_AGG);
308 lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_CLONE_SVR));
309 lpp->lpiSelect = (pcsp->lpi->fIsAggregate() && (pcsp->lpi->GetServer() == lpp->lpiServer)) ? pcsp->lpi : NULL;
310 StartTask (taskAGG_ENUM_TO_COMBOBOX, hDlg, lpp);
314 void Filesets_Clonesys_OnEndTask_EnumServers (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
316 pcsp->fEnumedServers = TRUE;
317 Filesets_Clonesys_OnSelectServer (hDlg, pcsp);
321 void Filesets_Clonesys_OnEndTask_EnumAggregs (HWND hDlg, LPSET_CLONESYS_PARAMS pcsp)
323 pcsp->fEnumedAggregs = TRUE;
324 Filesets_Clonesys_OnSelect (hDlg, pcsp);