Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / set_restore.cpp
blobd30f43dd1340320749cacf16b40e4ba3d2bb7fa7
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_restore.h"
20 #include "set_general.h"
21 #include "propcache.h"
22 #include "columns.h"
23 #include "svr_window.h"
24 #include "display.h"
28 * PROTOTYPES _________________________________________________________________
32 BOOL CALLBACK Filesets_Restore_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
33 void Filesets_Restore_OnInitDialog (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
34 void Filesets_Restore_OnEndTask_LookupFileset (HWND hDlg, LPTASKPACKET ptp, LPSET_RESTORE_PARAMS psrp);
35 void Filesets_Restore_OnEndTask_EnumServers (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
36 void Filesets_Restore_OnEndTask_EnumAggregates (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
37 void Filesets_Restore_OnSelectServer (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
38 void Filesets_Restore_OnSetName (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
39 void Filesets_Restore_OnFileName (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
40 void Filesets_Restore_OnAggregate (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
41 void Filesets_Restore_OnBrowse (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
42 void Filesets_Restore_EnableOK (HWND hDlg, LPSET_RESTORE_PARAMS psrp);
46 * ROUTINES ___________________________________________________________________
50 void Filesets_Restore (LPIDENT lpiParent)
52 LPSET_RESTORE_PARAMS psrp = New (SET_RESTORE_PARAMS);
53 psrp->lpi = lpiParent;
54 psrp->szFileset[0] = TEXT('\0');
55 psrp->szFilename[0] = TEXT('\0');
56 psrp->fIncremental = FALSE;
58 if (lpiParent && lpiParent->fIsFileset())
59 lpiParent->GetFilesetName (psrp->szFileset);
61 INT_PTR rc = ModalDialogParam (IDD_SET_RESTORE, GetActiveWindow(), (DLGPROC)Filesets_Restore_DlgProc, (LPARAM)psrp);
62 if (rc != IDOK)
64 Delete (psrp);
66 else if (!ASSERT( psrp->lpi != NULL ))
68 Delete (psrp);
70 else if (!ASSERT( psrp->szFileset[0] != TEXT('\0') ))
72 Delete (psrp);
74 else if (!ASSERT( psrp->szFilename[0] != TEXT('\0') ))
76 Delete (psrp);
78 else
80 StartTask (taskSET_RESTORE, NULL, psrp);
85 BOOL CALLBACK Filesets_Restore_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
87 static LPSET_RESTORE_PARAMS psrp = NULL;
88 if (msg == WM_INITDIALOG)
89 psrp = (LPSET_RESTORE_PARAMS)lp;
91 if (HandleColumnNotify (hDlg, msg, wp, lp, &gr.viewAggRestore))
92 return FALSE;
94 if (AfsAppLib_HandleHelp (IDD_SET_RESTORE, hDlg, msg, wp, lp))
95 return TRUE;
97 if (psrp != NULL)
99 switch (msg)
101 case WM_INITDIALOG:
102 FastList_SetTextCallback (GetDlgItem (hDlg, IDC_AGG_LIST), GetItemText, &gr.viewAggRestore);
103 Filesets_Restore_OnInitDialog (hDlg, psrp);
104 break;
106 case WM_CONTEXTMENU:
107 HWND hList;
108 hList = GetDlgItem (hDlg, IDC_AGG_LIST);
110 POINT ptScreen;
111 POINT ptClient;
112 ptScreen.x = LOWORD(lp);
113 ptScreen.y = HIWORD(lp);
115 ptClient = ptScreen;
116 ScreenToClient (hList, &ptClient);
118 if (FL_HitTestForHeaderBar (hList, ptClient))
120 HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
121 DisplayContextMenu (hm, ptScreen, hList);
123 break;
125 case WM_ENDTASK:
126 LPTASKPACKET ptp;
127 if ((ptp = (LPTASKPACKET)lp) != NULL)
129 if (ptp->idTask == taskSET_LOOKUP)
130 Filesets_Restore_OnEndTask_LookupFileset (hDlg, ptp, psrp);
131 else if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
132 Filesets_Restore_OnEndTask_EnumServers (hDlg, psrp);
133 else if (ptp->idTask == taskAGG_ENUM_TO_LISTVIEW)
134 Filesets_Restore_OnEndTask_EnumAggregates (hDlg, psrp);
135 FreeTaskPacket (ptp);
137 break;
139 case WM_COLUMNS_CHANGED:
140 LPARAM lpSel;
141 lpSel = FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST));
142 FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggRestore);
143 Filesets_Restore_OnSelectServer (hDlg, psrp);
144 break;
146 case WM_COMMAND:
147 switch (LOWORD(wp))
149 case IDOK:
150 case IDCANCEL:
151 EndDialog (hDlg, LOWORD(wp));
152 break;
154 case IDC_RESTORE_INCREMENTAL:
155 psrp->fIncremental = IsDlgButtonChecked (hDlg, IDC_RESTORE_INCREMENTAL);
156 break;
158 case IDC_RESTORE_SERVER:
159 if (HIWORD(wp) == CBN_SELCHANGE)
160 Filesets_Restore_OnSelectServer (hDlg, psrp);
161 break;
163 case IDC_RESTORE_SETNAME:
164 if (HIWORD(wp) == EN_UPDATE)
165 Filesets_Restore_OnSetName (hDlg, psrp);
166 break;
168 case IDC_RESTORE_FILENAME:
169 Filesets_Restore_OnFileName (hDlg, psrp);
170 break;
172 case IDC_RESTORE_BROWSE:
173 Filesets_Restore_OnBrowse (hDlg, psrp);
174 break;
176 break;
178 case WM_DESTROY:
179 FL_StoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggRestore);
180 psrp = NULL;
181 break;
183 case WM_NOTIFY:
184 switch (((LPNMHDR)lp)->code)
186 case FLN_ITEMSELECT:
187 Filesets_Restore_OnAggregate (hDlg, psrp);
188 break;
190 break;
194 return FALSE;
198 static LONG_PTR procFilesetsRestoreList = 0;
200 LRESULT CALLBACK Filesets_Restore_SubclassListProc (HWND hList, UINT msg, WPARAM wp, LPARAM lp)
202 LRESULT rc;
204 if (procFilesetsRestoreList == 0)
205 rc = DefWindowProc (hList, msg, wp, lp);
206 else
207 rc = (LRESULT) CallWindowProc ((WNDPROC)procFilesetsRestoreList, hList, msg, wp, lp);
209 switch (msg)
211 case WM_DESTROY:
212 if (procFilesetsRestoreList != 0)
213 SetWindowLongPtr (hList, GWLP_WNDPROC, procFilesetsRestoreList);
214 break;
216 case WM_COMMAND:
217 switch (LOWORD(wp))
219 case M_COLUMNS:
220 ShowColumnsDialog (GetParent (hList), &gr.viewAggRestore);
221 break;
223 break;
226 return rc;
230 void Filesets_Restore_OnInitDialog (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
232 HWND hList = GetDlgItem (hDlg, IDC_AGG_LIST);
233 if (procFilesetsRestoreList == 0)
234 procFilesetsRestoreList = GetWindowLongPtr (hList, GWLP_WNDPROC);
235 SetWindowLongPtr (hList, GWLP_WNDPROC, (LONG_PTR)Filesets_Restore_SubclassListProc);
237 if (gr.viewAggRestore.lvsView == 0) // never initialized this?
239 if (gr.viewAggMove.lvsView != 0)
240 memcpy (&gr.viewAggRestore, &gr.viewAggMove, sizeof(VIEWINFO));
241 else if (gr.viewAggCreate.lvsView != 0)
242 memcpy (&gr.viewAggRestore, &gr.viewAggCreate, sizeof(VIEWINFO));
243 else
244 memcpy (&gr.viewAggRestore, &gr.viewAgg, sizeof(VIEWINFO));
247 FL_RestoreView (GetDlgItem (hDlg, IDC_AGG_LIST), &gr.viewAggRestore);
249 SetDlgItemText (hDlg, IDC_RESTORE_FILENAME, psrp->szFilename);
250 SetDlgItemText (hDlg, IDC_RESTORE_SETNAME, psrp->szFileset);
252 SetDlgItemText (hDlg, IDC_RESTORE_CREATE, TEXT(""));
253 Filesets_Restore_OnEndTask_LookupFileset (hDlg, NULL, psrp);
255 CheckDlgButton (hDlg, IDC_RESTORE_INCREMENTAL, psrp->fIncremental);
257 // Fill in the Servers combobox, and select the default server
258 // (if one was specified).
260 LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
261 lpp->hCombo = GetDlgItem (hDlg, IDC_RESTORE_SERVER);
262 lpp->lpiSelect = (psrp->lpi) ? psrp->lpi->GetServer() : NULL;
263 StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);
267 void Filesets_Restore_OnSelectServer (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
269 LPIDENT lpiServerNew = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_RESTORE_SERVER));
271 LPIDENT lpiSelect = NULL;
272 if (psrp->lpi && !psrp->lpi->fIsServer())
274 if (psrp->lpi->GetServer() == lpiServerNew)
275 lpiSelect = psrp->lpi->GetAggregate();
278 SetWindowLongPtr (hDlg, DWLP_USER, (LONG_PTR)lpiServerNew);
280 LPAGG_ENUM_TO_LISTVIEW_PACKET lpp = New (AGG_ENUM_TO_LISTVIEW_PACKET);
281 lpp->lpiServer = lpiServerNew;
282 lpp->hList = GetDlgItem (hDlg, IDC_AGG_LIST);
283 lpp->lpiSelect = lpiSelect;
284 lpp->lpvi = &gr.viewAggRestore;
285 StartTask (taskAGG_ENUM_TO_LISTVIEW, hDlg, lpp);
289 void Filesets_Restore_OnEndTask_EnumServers (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
291 Filesets_Restore_OnSelectServer (hDlg, psrp);
295 void Filesets_Restore_OnEndTask_EnumAggregates (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
301 void Filesets_Restore_OnEndTask_LookupFileset (HWND hDlg, LPTASKPACKET ptp, LPSET_RESTORE_PARAMS psrp)
303 if (ptp)
305 psrp->lpi = (ptp->rc) ? TASKDATA(ptp)->lpi : NULL;
307 if (!psrp->lpi)
309 psrp->lpi = (LPIDENT)FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST));
312 BOOL fCreate = (psrp->lpi && psrp->lpi->fIsFileset()) ? FALSE : TRUE;
314 TCHAR szFileset[ cchNAME ];
315 GetDlgItemText (hDlg, IDC_RESTORE_SETNAME, szFileset, cchNAME);
317 LPTSTR pszText;
318 if (szFileset[0] == TEXT('\0'))
320 pszText = CloneString (TEXT(""));
322 else if (fCreate)
324 pszText = FormatString (IDS_RESTORE_CREATESET, TEXT("%s"), szFileset);
326 else
328 TCHAR szServer[ cchNAME ];
329 TCHAR szAggregate[ cchNAME ];
330 psrp->lpi->GetServerName (szServer);
331 psrp->lpi->GetAggregateName (szAggregate);
332 pszText = FormatString (IDS_RESTORE_OVERWRITESET, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
334 SetDlgItemText (hDlg, IDC_RESTORE_CREATE, pszText);
335 FreeString (pszText);
337 EnableWindow (GetDlgItem (hDlg, IDC_RESTORE_SERVER), fCreate);
338 EnableWindow (GetDlgItem (hDlg, IDC_AGG_LIST), fCreate);
340 if (psrp->lpi)
342 LPIDENT lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_RESTORE_SERVER));
344 if (psrp->lpi->GetServer() != lpiServer)
346 CB_SetSelectedByData (GetDlgItem (hDlg, IDC_RESTORE_SERVER), (LPARAM)psrp->lpi->GetServer());
347 Filesets_Restore_OnSelectServer (hDlg, psrp);
349 else if (!psrp->lpi->fIsServer())
351 FL_SetSelectedByData (GetDlgItem (hDlg, IDC_AGG_LIST), (LPARAM)psrp->lpi->GetAggregate());
355 Filesets_Restore_EnableOK (hDlg, psrp);
359 void Filesets_Restore_OnFileName (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
361 GetDlgItemText (hDlg, IDC_RESTORE_FILENAME, psrp->szFilename, MAX_PATH);
362 Filesets_Restore_EnableOK (hDlg, psrp);
366 void Filesets_Restore_OnSetName (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
368 GetDlgItemText (hDlg, IDC_RESTORE_SETNAME, psrp->szFileset, cchNAME);
369 EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
371 LPSET_LOOKUP_PACKET lpp = New (SET_LOOKUP_PACKET);
372 lstrcpy (lpp->szFileset, psrp->szFileset);
373 StartTask (taskSET_LOOKUP, hDlg, lpp);
377 void Filesets_Restore_OnAggregate (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
379 if (!( psrp->lpi && psrp->lpi->fIsFileset() ))
381 psrp->lpi = (LPIDENT)FL_GetSelectedData (GetDlgItem (hDlg, IDC_AGG_LIST));
384 Filesets_Restore_EnableOK (hDlg, psrp);
388 void Filesets_Restore_EnableOK (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
390 BOOL fEnable = TRUE;
392 if (psrp->szFilename[0] == TEXT('\0'))
393 fEnable = FALSE;
395 if (psrp->szFileset[0] == TEXT('\0'))
396 fEnable = FALSE;
398 if (!psrp->lpi || psrp->lpi->fIsServer())
399 fEnable = FALSE;
401 EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
405 void Filesets_Restore_OnBrowse (HWND hDlg, LPSET_RESTORE_PARAMS psrp)
407 TCHAR szFilter[ cchRESOURCE ];
408 GetString (szFilter, IDS_RESTORE_FILTER);
409 TCHAR chFilter = szFilter[ lstrlen(szFilter)-1 ];
410 for (LPTSTR pszFilter = szFilter;
411 (*pszFilter) && ((pszFilter = (LPTSTR)lstrchr (pszFilter, chFilter)) != NULL);
412 ++pszFilter)
414 *pszFilter = TEXT('\0');
417 TCHAR szFilename[ MAX_PATH ];
418 GetDlgItemText (hDlg, IDC_RESTORE_FILENAME, szFilename, MAX_PATH);
420 OPENFILENAME ofn;
421 memset (&ofn, 0x00, sizeof(ofn));
422 ofn.lStructSize = sizeof(ofn);
423 ofn.hwndOwner = hDlg;
424 ofn.hInstance = THIS_HINST;
425 ofn.lpstrFilter = szFilter;
426 ofn.nFilterIndex = 1;
427 ofn.lpstrFile = szFilename;
428 ofn.nMaxFile = MAX_PATH;
429 ofn.Flags = OFN_HIDEREADONLY | OFN_NOREADONLYRETURN |
430 OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
431 ofn.lpstrDefExt = TEXT("dmp");
433 if (GetOpenFileName (&ofn))
435 SetDlgItemText (hDlg, IDC_RESTORE_FILENAME, szFilename);
436 Filesets_Restore_OnFileName (hDlg, psrp);