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
14 #include <afs/param.h>
19 #include "set_restore.h"
20 #include "set_general.h"
21 #include "propcache.h"
23 #include "svr_window.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
);
66 else if (!ASSERT( psrp
->lpi
!= NULL
))
70 else if (!ASSERT( psrp
->szFileset
[0] != TEXT('\0') ))
74 else if (!ASSERT( psrp
->szFilename
[0] != TEXT('\0') ))
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
))
94 if (AfsAppLib_HandleHelp (IDD_SET_RESTORE
, hDlg
, msg
, wp
, lp
))
102 FastList_SetTextCallback (GetDlgItem (hDlg
, IDC_AGG_LIST
), GetItemText
, &gr
.viewAggRestore
);
103 Filesets_Restore_OnInitDialog (hDlg
, psrp
);
108 hList
= GetDlgItem (hDlg
, IDC_AGG_LIST
);
112 ptScreen
.x
= LOWORD(lp
);
113 ptScreen
.y
= HIWORD(lp
);
116 ScreenToClient (hList
, &ptClient
);
118 if (FL_HitTestForHeaderBar (hList
, ptClient
))
120 HMENU hm
= TaLocale_LoadMenu (MENU_COLUMNS
);
121 DisplayContextMenu (hm
, ptScreen
, hList
);
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
);
139 case WM_COLUMNS_CHANGED
:
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
);
151 EndDialog (hDlg
, LOWORD(wp
));
154 case IDC_RESTORE_INCREMENTAL
:
155 psrp
->fIncremental
= IsDlgButtonChecked (hDlg
, IDC_RESTORE_INCREMENTAL
);
158 case IDC_RESTORE_SERVER
:
159 if (HIWORD(wp
) == CBN_SELCHANGE
)
160 Filesets_Restore_OnSelectServer (hDlg
, psrp
);
163 case IDC_RESTORE_SETNAME
:
164 if (HIWORD(wp
) == EN_UPDATE
)
165 Filesets_Restore_OnSetName (hDlg
, psrp
);
168 case IDC_RESTORE_FILENAME
:
169 Filesets_Restore_OnFileName (hDlg
, psrp
);
172 case IDC_RESTORE_BROWSE
:
173 Filesets_Restore_OnBrowse (hDlg
, psrp
);
179 FL_StoreView (GetDlgItem (hDlg
, IDC_AGG_LIST
), &gr
.viewAggRestore
);
184 switch (((LPNMHDR
)lp
)->code
)
187 Filesets_Restore_OnAggregate (hDlg
, psrp
);
198 static LONG_PTR procFilesetsRestoreList
= 0;
200 LRESULT CALLBACK
Filesets_Restore_SubclassListProc (HWND hList
, UINT msg
, WPARAM wp
, LPARAM lp
)
204 if (procFilesetsRestoreList
== 0)
205 rc
= DefWindowProc (hList
, msg
, wp
, lp
);
207 rc
= (LRESULT
) CallWindowProc ((WNDPROC
)procFilesetsRestoreList
, hList
, msg
, wp
, lp
);
212 if (procFilesetsRestoreList
!= 0)
213 SetWindowLongPtr (hList
, GWLP_WNDPROC
, procFilesetsRestoreList
);
220 ShowColumnsDialog (GetParent (hList
), &gr
.viewAggRestore
);
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
));
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
)
305 psrp
->lpi
= (ptp
->rc
) ? TASKDATA(ptp
)->lpi
: NULL
;
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
);
318 if (szFileset
[0] == TEXT('\0'))
320 pszText
= CloneString (TEXT(""));
324 pszText
= FormatString (IDS_RESTORE_CREATESET
, TEXT("%s"), szFileset
);
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
);
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
)
392 if (psrp
->szFilename
[0] == TEXT('\0'))
395 if (psrp
->szFileset
[0] == TEXT('\0'))
398 if (!psrp
->lpi
|| psrp
->lpi
->fIsServer())
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
);
414 *pszFilter
= TEXT('\0');
417 TCHAR szFilename
[ MAX_PATH
];
418 GetDlgItemText (hDlg
, IDC_RESTORE_FILENAME
, szFilename
, MAX_PATH
);
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
);