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>
16 #include <afs/fs_utils.h>
23 * VARIABLES __________________________________________________________________
34 * PROTOTYPES _________________________________________________________________
38 void Mount_OnInitDialog (HWND hDlg
);
39 void Mount_OnUpdate (HWND hDlg
, BOOL fOnInitDialog
= FALSE
);
40 void Mount_OnSelect (HWND hDlg
);
41 void Mount_OnCheck (HWND hDlg
);
42 void Mount_OnRemove (HWND hDlg
);
43 void Mount_OnAdd (HWND hDlg
);
44 void Mount_OnEdit (HWND hDlg
);
46 void Mount_AdjustMapping (HWND hDlg
, int iDrive
);
47 int Mount_DriveFromItem (HWND hDlg
, int iItem
);
49 BOOL CALLBACK
Mapping_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
50 void Mapping_OnInitDialog (HWND hDlg
);
51 void Mapping_OnOK (HWND hDlg
);
52 void Mapping_OnEnable (HWND hDlg
);
56 * ROUTINES ___________________________________________________________________
60 BOOL CALLBACK
Mount_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
66 GetClientRect (GetParent(hDlg
), &rTab
);
67 TabCtrl_AdjustRect (GetParent (hDlg
), FALSE
, &rTab
);
68 SetWindowPos (hDlg
, NULL
, rTab
.left
, rTab
.top
, 0, 0, SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
70 Mount_OnInitDialog (hDlg
);
85 Mount_OnRemove (hDlg
);
89 if (HIWORD(wp
) == LBN_CLICKED
)
91 else if ((HIWORD(wp
) == LBN_SELCHANGE
) || (HIWORD(wp
) == LBN_SELCANCEL
))
92 Mount_OnSelect (hDlg
);
96 Mount_DlgProc (hDlg
, WM_HELP
, 0, 0);
102 WinHelp (hDlg
, g
.szHelpFile
, HELP_CONTEXT
, IDH_AFSCREDS_TAB_DRIVES
);
109 void Mount_OnInitDialog (HWND hDlg
)
112 SendDlgItemMessage (hDlg
, IDC_LIST
, LB_SETTABSTOPS
, 1, (LPARAM
)&xTabStop
);
114 Mount_OnUpdate (hDlg
, TRUE
);
118 void Mount_OnUpdate (HWND hDlg
, BOOL fOnInitDialog
)
121 memset(&List
, 0, sizeof(DRIVEMAPLIST
));
122 QueryDriveMapList (&List
);
124 HWND hList
= GetDlgItem (hDlg
, IDC_LIST
);
125 int iItemSel
= LB_GetSelected(hList
);
126 int iDataSel
= Mount_DriveFromItem (hDlg
, iItemSel
);
129 if (fOnInitDialog
&& (iDataSel
== -1))
130 iDataSel
= l
.iDriveSelectLast
;
132 LB_StartChange(hList
, TRUE
);
134 for (int iDrive
= 25; iDrive
>= 0; --iDrive
)
136 if (!List
.aDriveMap
[ iDrive
].szMapping
[0])
139 TCHAR szAfsPath
[ MAX_PATH
];
140 AdjustAfsPath (szAfsPath
, List
.aDriveMap
[ iDrive
].szMapping
, TRUE
, FALSE
);
142 LPTSTR psz
= FormatString (IDS_DRIVE_MAP
, TEXT("%c%s"), List
.aDriveMap
[ iDrive
].chDrive
, szAfsPath
);
143 int iItem
= LB_AddItem(hList
, psz
, List
.aDriveMap
[ iDrive
].fActive
);
146 int iCount
= SendMessage(hList
, LB_GETCOUNT
, 0, 0);
148 /* This really shouldn't work except that we are adding
149 * the strings in alphabetical order. Otherwise, we could
150 * identify an index value for a string that could then change.
152 if (iDrive
== iDataSel
)
156 LB_EndChange(hList
, NULL
);
158 LB_SetSelected(hList
, iItemSel
);
160 Mount_OnSelect (hDlg
);
161 FreeDriveMapList (&List
);
165 void Mount_OnSelect (HWND hDlg
)
167 BOOL fServiceRunning
= IsServiceRunning();
169 HWND hList
= GetDlgItem (hDlg
, IDC_LIST
);
170 int iItemSel
= LB_GetSelected(hList
);
171 int iDataSel
= Mount_DriveFromItem (hDlg
, iItemSel
);
173 l
.iDriveSelectLast
= iDataSel
;
175 EnableWindow (GetDlgItem (hDlg
, IDC_ADD
), fServiceRunning
);
176 EnableWindow (GetDlgItem (hDlg
, IDC_EDIT
), fServiceRunning
&& (iDataSel
!= -1));
177 EnableWindow (GetDlgItem (hDlg
, IDC_REMOVE
), fServiceRunning
&& (iDataSel
!= -1));
181 void Mount_OnCheck (HWND hDlg
)
184 QueryDriveMapList (&List
);
186 HWND hList
= GetDlgItem (hDlg
, IDC_LIST
);
187 int iItemSel
= LB_GetSelected(hList
);
188 int iDriveSel
= Mount_DriveFromItem (hDlg
, iItemSel
);
189 BOOL fChecked
= SendMessage (hList
, LB_GETITEMDATA
, iItemSel
, 0);
194 if (fChecked
&& List
.aDriveMap
[ iDriveSel
].szMapping
[0] && !List
.aDriveMap
[ iDriveSel
].fActive
)
196 if (!ActivateDriveMap (List
.aDriveMap
[ iDriveSel
].chDrive
, List
.aDriveMap
[ iDriveSel
].szMapping
, List
.aDriveMap
[ iDriveSel
].szSubmount
, List
.aDriveMap
[ iDriveSel
].fPersistent
, &dwStatus
))
197 Message (MB_OK
| MB_ICONHAND
, IDS_ERROR_MAP
, IDS_ERROR_MAP_DESC
, TEXT("%08lX"), dwStatus
);
198 Mount_OnUpdate (hDlg
);
200 else if (!fChecked
&& List
.aDriveMap
[ iDriveSel
].fActive
)
202 if (!InactivateDriveMap (List
.aDriveMap
[ iDriveSel
].chDrive
, &dwStatus
))
203 Message (MB_OK
| MB_ICONHAND
, IDS_ERROR_UNMAP
, IDS_ERROR_UNMAP_DESC
, TEXT("%08lX"), dwStatus
);
204 Mount_OnUpdate (hDlg
);
206 WriteActiveMap(List
.aDriveMap
[ iDriveSel
].chDrive
, fChecked
&& List
.aDriveMap
[ iDriveSel
].fPersistent
);
209 FreeDriveMapList (&List
);
213 void Mount_OnRemove (HWND hDlg
)
215 HWND hList
= GetDlgItem (hDlg
, IDC_LIST
);
216 int iItemSel
= LB_GetSelected(hList
);
217 int iDriveSel
= Mount_DriveFromItem (hDlg
, iItemSel
);
222 QueryDriveMapList (&List
);
224 if (List
.aDriveMap
[ iDriveSel
].szMapping
[0])
226 if (List
.aDriveMap
[ iDriveSel
].fActive
)
229 if (!InactivateDriveMap (List
.aDriveMap
[ iDriveSel
].chDrive
, &dwStatus
))
231 Message (MB_OK
| MB_ICONHAND
, IDS_ERROR_UNMAP
, IDS_ERROR_UNMAP_DESC
, TEXT("%08lX"), dwStatus
);
235 List
.aDriveMap
[ iDriveSel
].szMapping
[0] = TEXT('\0');
236 WriteDriveMappings (&List
);
238 Mount_OnUpdate (hDlg
);
240 WriteActiveMap(List
.aDriveMap
[ iDriveSel
].chDrive
, FALSE
);
241 FreeDriveMapList (&List
);
246 void Mount_OnAdd (HWND hDlg
)
248 Mount_AdjustMapping (hDlg
, -1);
252 void Mount_OnEdit (HWND hDlg
)
254 HWND hList
= GetDlgItem (hDlg
, IDC_LIST
);
255 int iItemSel
= LB_GetSelected(hList
);
256 int iDriveSel
= Mount_DriveFromItem (hDlg
, iItemSel
);
258 Mount_AdjustMapping (hDlg
, iDriveSel
);
262 void Mount_AdjustMapping (HWND hDlg
, int iDrive
)
265 QueryDriveMapList (&List
);
267 DRIVEMAP DriveMapOrig
;
268 memset (&DriveMapOrig
, 0x00, sizeof(DRIVEMAP
));
272 memcpy (&DriveMapOrig
, &List
.aDriveMap
[ iDrive
], sizeof(DRIVEMAP
));
276 memcpy (&DriveMap
, &DriveMapOrig
, sizeof(DRIVEMAP
));
278 if (ModalDialogParam (IDD_MAPPING
, hDlg
, (DLGPROC
)Mapping_DlgProc
, (LPARAM
)&DriveMap
) == IDOK
)
280 TCHAR szAfsPathOrig
[ MAX_PATH
];
282 AdjustAfsPath (szAfsPathOrig
, DriveMapOrig
.szMapping
, TRUE
, TRUE
);
284 TCHAR szAfsPathNew
[ MAX_PATH
];
285 AdjustAfsPath (szAfsPathNew
, DriveMap
.szMapping
, TRUE
, TRUE
);
287 if ( (lstrcmpi (szAfsPathOrig
, szAfsPathNew
)) ||
288 (lstrcmpi (DriveMapOrig
.szSubmount
, DriveMap
.szSubmount
)) ||
289 (DriveMapOrig
.chDrive
!= DriveMap
.chDrive
) ||
290 (DriveMapOrig
.fPersistent
!= DriveMap
.fPersistent
) )
294 if ((iDrive
!= -1) && (DriveMapOrig
.fActive
))
296 if (!InactivateDriveMap (DriveMapOrig
.chDrive
, &dwStatus
))
298 Message (MB_OK
| MB_ICONHAND
, IDS_ERROR_UNMAP
, IDS_ERROR_UNMAP_DESC
, TEXT("%08lX"), dwStatus
);
299 Mount_OnUpdate (hDlg
);
304 if (!ActivateDriveMap (DriveMap
.chDrive
, szAfsPathNew
, DriveMap
.szSubmount
, DriveMap
.fPersistent
, &dwStatus
))
306 Message (MB_OK
| MB_ICONHAND
, IDS_ERROR_MAP
, IDS_ERROR_MAP_DESC
, TEXT("%08lX"), dwStatus
);
307 Mount_OnUpdate (hDlg
);
311 if (DriveMap
.szSubmount
[0])
313 TCHAR szSubmountNow
[ MAX_PATH
];
314 if (GetDriveSubmount (DriveMap
.chDrive
, szSubmountNow
))
316 if (lstrcmpi (DriveMap
.szSubmount
, szSubmountNow
))
318 int idsTitle
= (g
.fIsWinNT
) ? IDS_NEWSUB_TITLE
: IDS_NEWSUB_TITLE_95
;
319 Message (MB_OK
| MB_ICONASTERISK
, idsTitle
, IDS_NEWSUB_DESC
);
325 memset (&List
.aDriveMap
[ iDrive
], 0x00, sizeof(DRIVEMAP
));
326 memcpy (&List
.aDriveMap
[ DriveMap
.chDrive
-chDRIVE_A
], &DriveMap
, sizeof(DRIVEMAP
));
327 lstrcpy (List
.aDriveMap
[ DriveMap
.chDrive
-chDRIVE_A
].szMapping
, szAfsPathNew
);
328 WriteDriveMappings (&List
);
330 Mount_OnUpdate (hDlg
);
336 int Mount_DriveFromItem (HWND hDlg
, int iItem
)
338 TCHAR szItem
[ 1024 ] = TEXT("");
339 SendDlgItemMessage (hDlg
, IDC_LIST
, LB_GETTEXT
, iItem
, (LPARAM
)szItem
);
342 if ((pch
= (LPTSTR
)lstrchr (szItem
, TEXT(':'))) != NULL
)
347 if ((*pch
>= TEXT('A')) && (*pch
<= TEXT('Z')))
348 return (*pch
) - TEXT('A');
356 BOOL CALLBACK
Mapping_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
361 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
362 Mapping_OnInitDialog (hDlg
);
373 EndDialog (hDlg
, IDCANCEL
);
377 Mapping_OnEnable (hDlg
);
381 Mapping_DlgProc (hDlg
, WM_HELP
, 0, 0);
387 WinHelp (hDlg
, g
.szHelpFile
, HELP_CONTEXT
, IDH_AFSCREDS_MAPDRIVE
);
394 void Mapping_OnInitDialog (HWND hDlg
)
396 PDRIVEMAP pMap
= (PDRIVEMAP
)GetWindowLongPtr (hDlg
, DWLP_USER
);
398 // Fill in the combo box
400 DWORD dwDrives
= GetLogicalDrives() | 0x07; // Always pretend A,B,C: are used
402 if (pMap
->chDrive
!= 0)
403 dwDrives
&= ~( 1 << (pMap
->chDrive
- chDRIVE_A
) );
406 HWND hCombo
= GetDlgItem (hDlg
, IDC_MAP_LETTER
);
407 SendMessage (hCombo
, WM_SETREDRAW
, FALSE
, 0);
409 for (int ii
= 0; ii
< 26; ++ii
)
411 if (!(dwDrives
& (1<<ii
)))
413 TCHAR szText
[ cchRESOURCE
];
414 GetString (szText
, IDS_MAP_LETTER
);
417 if ((pch
= (LPTSTR
)lstrchr (szText
, TEXT('*'))) != NULL
)
418 *pch
= TEXT('A') + ii
;
420 int iItem
= SendMessage (hCombo
, CB_ADDSTRING
, 0, (LPARAM
)szText
);
421 SendMessage (hCombo
, CB_SETITEMDATA
, iItem
, ii
);
422 if (pMap
->chDrive
&& (ii
== pMap
->chDrive
- chDRIVE_A
))
424 else if ((!pMap
->chDrive
) && (iItemSel
== -1))
429 SendMessage (hCombo
, WM_SETREDRAW
, TRUE
, 0);
430 SendMessage (hCombo
, CB_SETCURSEL
, iItemSel
, 0);
432 TCHAR szMapping
[ MAX_PATH
];
433 AdjustAfsPath (szMapping
, ((pMap
->szMapping
[0]) ? pMap
->szMapping
: cm_slash_mount_root
), TRUE
, FALSE
);
434 CHAR msg
[256], msgf
[256];
435 if (GetDlgItemText(hDlg
,IDC_STATICSUBMOUNT
,(LPSTR
)msg
,sizeof(msg
)-1)>0)
437 wsprintf(msgf
,msg
,cm_back_slash_mount_root
,cm_back_slash_mount_root
);
438 SetDlgItemText (hDlg
, IDC_STATICSUBMOUNT
, msgf
);
440 SetDlgItemText (hDlg
, IDC_MAP_PATH
, szMapping
);
441 SetDlgItemText (hDlg
, IDC_MAP_DESC
, pMap
->szSubmount
);
443 CheckDlgButton (hDlg
, IDC_MAP_PERSISTENT
, (pMap
->chDrive
== 0) ? TRUE
: (pMap
->fPersistent
));
445 Mapping_OnEnable (hDlg
);
449 void Mapping_OnOK (HWND hDlg
)
451 PDRIVEMAP pMap
= (PDRIVEMAP
)GetWindowLongPtr (hDlg
, DWLP_USER
);
453 int iItem
= SendDlgItemMessage (hDlg
, IDC_MAP_LETTER
, CB_GETCURSEL
, 0, 0);
454 int iDrive
= SendDlgItemMessage (hDlg
, IDC_MAP_LETTER
, CB_GETITEMDATA
, iItem
, 0);
456 pMap
->chDrive
= chDRIVE_A
+ iDrive
;
457 GetDlgItemText (hDlg
, IDC_MAP_PATH
, pMap
->szMapping
, MAX_PATH
);
458 GetDlgItemText (hDlg
, IDC_MAP_DESC
, pMap
->szSubmount
, MAX_PATH
);
459 pMap
->fPersistent
= IsDlgButtonChecked (hDlg
, IDC_MAP_PERSISTENT
);
461 if (pMap
->szSubmount
[0] && !IsValidSubmountName (pMap
->szSubmount
))
463 int idsTitle
= (g
.fIsWinNT
) ? IDS_BADSUB_TITLE
: IDS_BADSUB_TITLE_95
;
464 Message (MB_ICONHAND
, idsTitle
, IDS_BADSUB_DESC
);
468 if ( (lstrncmpi (pMap
->szMapping
, cm_slash_mount_root
, lstrlen(cm_slash_mount_root
))) && /*TEXT("/afs")*/
469 (lstrncmpi (pMap
->szMapping
, cm_back_slash_mount_root
, lstrlen(cm_back_slash_mount_root
))) ) /*TEXT("\\afs")*/
471 Message (MB_ICONHAND
, IDS_BADMAP_TITLE
, IDS_BADMAP_DESC
);
475 WriteActiveMap(pMap
->chDrive
, pMap
->fPersistent
);
476 EndDialog (hDlg
, IDOK
);
480 void Mapping_OnEnable (HWND hDlg
)
482 TCHAR szPath
[ MAX_PATH
];
483 GetDlgItemText (hDlg
, IDC_MAP_PATH
, szPath
, MAX_PATH
);
484 EnableWindow (GetDlgItem (hDlg
, IDOK
), (szPath
[0] != TEXT('\0')));