Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

812 lines
18 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. vvolbase.cxx
  7. Contains the base dialog for used by the delete volume dialog
  8. the volume management dialog and the edit volume dialog.
  9. FILE HISTORY:
  10. NarenG 11/11/92 Stole and modified sharestp.cxx
  11. */
  12. #define INCL_WINDOWS_GDI
  13. #define INCL_WINDOWS
  14. #define INCL_DOSERRORS
  15. #define INCL_NETERRORS
  16. #define INCL_NETSHARE
  17. #define INCL_NETSERVER
  18. #define INCL_NETCONS
  19. #define INCL_NETLIB
  20. #include <lmui.hxx>
  21. #define INCL_BLT_WINDOW
  22. #define INCL_BLT_DIALOG
  23. #define INCL_BLT_CONTROL
  24. #define INCL_BLT_MISC
  25. #define INCL_BLT_CLIENT
  26. #define INCL_BLT_MSGPOPUP
  27. #include <blt.hxx>
  28. extern "C"
  29. {
  30. #include <afpmgr.h>
  31. #include <macfile.h>
  32. }
  33. #include <ellipsis.hxx>
  34. #include <string.hxx>
  35. #include <uitrace.hxx>
  36. #include <strnumer.hxx>
  37. #include "curusers.hxx"
  38. #include "vvolbase.hxx"
  39. /*******************************************************************
  40. NAME: VIEW_VOLUMES_LBI::VIEW_VOLUMES_LBI
  41. SYNOPSIS: Listbox items used in the VIEW_VOLUMES_LISTBOX
  42. ENTRY: dwVolumeId - Id of this volume.
  43. pszVolumeName - Name of volume.
  44. pszVolumePath - Path of volume.
  45. fGoodVolume - If this volume was successfully shared.
  46. EXIT:
  47. RETURNS:
  48. NOTES:
  49. HISTORY:
  50. NarenG 11/11/92 Modified for AFPMGR
  51. ********************************************************************/
  52. VIEW_VOLUMES_LBI::VIEW_VOLUMES_LBI( DWORD dwVolumeId,
  53. const TCHAR * pszVolumeName,
  54. const TCHAR * pszVolumePath,
  55. BOOL fGoodVolume )
  56. : _dwVolumeId( dwVolumeId ),
  57. _nlsVolumeName( pszVolumeName ),
  58. _nlsVolumePath( pszVolumePath ),
  59. _fGoodVolume( fGoodVolume )
  60. {
  61. if ( QueryError() != NERR_Success )
  62. return;
  63. APIERR err;
  64. if ( (( err = _nlsVolumeName.QueryError()) != NERR_Success )
  65. || (( err = _nlsVolumePath.QueryError()) != NERR_Success ))
  66. {
  67. ReportError( err );
  68. return;
  69. }
  70. }
  71. /*******************************************************************
  72. NAME: VIEW_VOLUMES_LBI::~VIEW_VOLUMES_LBI
  73. SYNOPSIS: Destructor
  74. ENTRY:
  75. EXIT:
  76. RETURNS:
  77. NOTES:
  78. HISTORY:
  79. NarenG 11/11/92 Modified for AFPMGR
  80. ********************************************************************/
  81. VIEW_VOLUMES_LBI::~VIEW_VOLUMES_LBI()
  82. {
  83. //
  84. // This space intentionally left blank
  85. //
  86. }
  87. /*******************************************************************
  88. NAME: VIEW_VOLUMES_LBI::QueryLeadingChar
  89. SYNOPSIS: Returns the leading character of the listbox item.
  90. The enables shortcut keys in the listbox
  91. ENTRY:
  92. EXIT:
  93. RETURNS: Returns the first char of the volume name
  94. NOTES:
  95. HISTORY:
  96. NarenG 11/11/92 Modified for AFPMGR
  97. ********************************************************************/
  98. WCHAR VIEW_VOLUMES_LBI::QueryLeadingChar( VOID ) const
  99. {
  100. ISTR istr( _nlsVolumeName );
  101. return _nlsVolumeName.QueryChar( istr );
  102. }
  103. /*******************************************************************
  104. NAME: VIEW_VOLUMES_LBI::Paint
  105. SYNOPSIS: Redefine Paint() method of LBI class
  106. ENTRY:
  107. EXIT:
  108. RETURNS:
  109. NOTES:
  110. HISTORY:
  111. NarenG 11/11/92 Modified for AFPMGR
  112. ********************************************************************/
  113. VOID VIEW_VOLUMES_LBI::Paint( LISTBOX *plb,
  114. HDC hdc,
  115. const RECT *prect,
  116. GUILTT_INFO *pGUILTT ) const
  117. {
  118. STR_DTE_ELLIPSIS strdteVolumeName( _nlsVolumeName.QueryPch(),
  119. plb, ELLIPSIS_RIGHT );
  120. STR_DTE_ELLIPSIS strdteVolumePath( _nlsVolumePath, plb, ELLIPSIS_PATH );
  121. DISPLAY_TABLE dt(COLS_VV_LB_VOLUMES,
  122. ((VIEW_VOLUMES_LISTBOX *) plb)->QueryColumnWidths() );
  123. dt[0] = _fGoodVolume
  124. ? ((VIEW_VOLUMES_LISTBOX *) plb)->QueryGoodVolumeBitmap()
  125. : ((VIEW_VOLUMES_LISTBOX *) plb)->QueryBadVolumeBitmap();
  126. dt[1] = &strdteVolumeName;
  127. dt[2] = &strdteVolumePath;
  128. dt.Paint( plb, hdc, prect, pGUILTT );
  129. }
  130. /*******************************************************************
  131. NAME: VIEW_VOLUMES_LBI::Compare
  132. SYNOPSIS: Redefine Compare() method of LBI class
  133. We compare the share names of two LBIs.
  134. ENTRY: plbi - pointer to the LBI to compare with
  135. EXIT:
  136. RETURNS:
  137. NOTES:
  138. HISTORY:
  139. NarenG 11/11/92 Modified for AFPMGR
  140. ********************************************************************/
  141. INT VIEW_VOLUMES_LBI::Compare( const LBI *plbi ) const
  142. {
  143. return( _nlsVolumeName._stricmp(
  144. ((const VIEW_VOLUMES_LBI *)plbi)->_nlsVolumeName ));
  145. }
  146. /*******************************************************************
  147. NAME: VIEW_VOLUMES_LISTBOX::VIEW_VOLUMES_LISTBOX
  148. SYNOPSIS: Constructor
  149. ENTRY: powin - owner window
  150. cid - resource id of the share listbox
  151. EXIT:
  152. RETURNS:
  153. NOTES:
  154. HISTORY:
  155. NarenG 11/11/92 Modified for AFPMGR
  156. ********************************************************************/
  157. VIEW_VOLUMES_LISTBOX::VIEW_VOLUMES_LISTBOX(
  158. OWNER_WINDOW *powin,
  159. BOOL fDisplayBadVolumes,
  160. CID cid,
  161. AFP_SERVER_HANDLE hServer )
  162. : BLT_LISTBOX( powin, cid ),
  163. _hServer( hServer ),
  164. _fDisplayBadVolumes( fDisplayBadVolumes ),
  165. _dmdteGoodVolume( IDBM_LB_GOOD_VOLUME ),
  166. _dmdteBadVolume( IDBM_LB_BAD_VOLUME )
  167. {
  168. if ( QueryError() != NERR_Success )
  169. return;
  170. APIERR err = NERR_Success;
  171. if ( ((err = _dmdteGoodVolume.QueryError()) != NERR_Success ) ||
  172. ((err = _dmdteBadVolume.QueryError()) != NERR_Success ))
  173. {
  174. ReportError( err );
  175. return;
  176. }
  177. if ( ( err = DISPLAY_TABLE::CalcColumnWidths( _adx,
  178. COLS_VV_LB_VOLUMES,
  179. powin,
  180. cid,
  181. TRUE ) ) != NERR_Success )
  182. {
  183. ReportError( err );
  184. return;
  185. }
  186. }
  187. /*******************************************************************
  188. NAME: VIEW_VOLUMES_LISTBOX::~VIEW_VOLUMES_LISTBOX
  189. SYNOPSIS: Destructor
  190. ENTRY:
  191. EXIT:
  192. RETURNS:
  193. NOTES:
  194. HISTORY:
  195. NarenG 11/11/92 Modified for AFPMGR
  196. ********************************************************************/
  197. VIEW_VOLUMES_LISTBOX::~VIEW_VOLUMES_LISTBOX()
  198. {
  199. //
  200. // This space intentionally left blank
  201. //
  202. }
  203. /*******************************************************************
  204. NAME: VIEW_VOLUMES_LISTBOX::Refresh
  205. SYNOPSIS: Update the volumes in the listbox
  206. ENTRY: hServer - handle to the target server.
  207. EXIT:
  208. RETURNS:
  209. NOTES:
  210. HISTORY:
  211. NarenG 11/11/92 Modified for AFPMGR
  212. *******************************************************************/
  213. DWORD VIEW_VOLUMES_LISTBOX::Refresh( VOID )
  214. {
  215. //
  216. // Enumerate all successfully shared volumes.
  217. //
  218. PAFP_VOLUME_INFO pAfpVolumes;
  219. DWORD cgvEntriesRead;
  220. DWORD cTotalAvail;
  221. DWORD err = ::AfpAdminVolumeEnum( _hServer,
  222. (LPBYTE*)&pAfpVolumes,
  223. (DWORD)-1, // Get all volumes
  224. &cgvEntriesRead,
  225. &cTotalAvail,
  226. NULL );
  227. //
  228. // See if the volumes are available.
  229. //
  230. if( err != NO_ERROR )
  231. {
  232. return err;
  233. }
  234. //
  235. // Get all the bad volumes if so requested.
  236. //
  237. PAFP_VOLUME_INFO pAfpBadVolumes;
  238. DWORD cbvEntriesRead;
  239. if ( _fDisplayBadVolumes )
  240. {
  241. err = ::AfpAdminInvalidVolumeEnum( _hServer,
  242. (LPBYTE*)&pAfpBadVolumes,
  243. &cbvEntriesRead );
  244. if( err != NO_ERROR )
  245. {
  246. return err;
  247. }
  248. }
  249. //
  250. // Now that we know the volume info is available,
  251. // let's nuke everything in the listbox.
  252. //
  253. SetRedraw( FALSE );
  254. DeleteAllItems();
  255. //
  256. // For iterating volumes
  257. //
  258. PAFP_VOLUME_INFO pVolIter = pAfpVolumes;
  259. //
  260. // Iterate the volumes adding them to the listbox.
  261. //
  262. err = NO_ERROR;
  263. while( ( err == NO_ERROR ) && ( cgvEntriesRead-- ) )
  264. {
  265. VIEW_VOLUMES_LBI * plbi = new VIEW_VOLUMES_LBI(
  266. pVolIter->afpvol_id,
  267. pVolIter->afpvol_name,
  268. pVolIter->afpvol_path,
  269. TRUE );
  270. if( AddItem( plbi ) < 0 )
  271. {
  272. //
  273. // CODEWORK: What should we do in error conditions?
  274. // As currently spec'd, we do nothing. If the data
  275. // cannot be retrieved, we display "n/a" in the
  276. // statistics strings. Should we hide the listbox
  277. // and display a message a'la WINNET??
  278. //
  279. err = ERROR_NOT_ENOUGH_MEMORY;
  280. }
  281. pVolIter++;
  282. }
  283. ::AfpAdminBufferFree( pAfpVolumes );
  284. //
  285. // If we have to display bad volumes.
  286. //
  287. if ( _fDisplayBadVolumes && ( err == NO_ERROR ) )
  288. {
  289. pVolIter = pAfpBadVolumes;
  290. //
  291. // Iterate the volumes adding them to the listbox.
  292. //
  293. while( ( err == NO_ERROR ) && ( cbvEntriesRead-- ) )
  294. {
  295. VIEW_VOLUMES_LBI * plbi = new VIEW_VOLUMES_LBI(
  296. pVolIter->afpvol_id,
  297. pVolIter->afpvol_name,
  298. pVolIter->afpvol_path,
  299. FALSE );
  300. if( AddItem( plbi ) < 0 )
  301. {
  302. //
  303. // CODEWORK: What should we do in error conditions?
  304. // As currently spec'd, we do nothing. If the data
  305. // cannot be retrieved, we display "n/a" in the
  306. // statistics strings. Should we hide the listbox
  307. // and display a message a'la WINNET??
  308. //
  309. err = ERROR_NOT_ENOUGH_MEMORY;
  310. }
  311. pVolIter++;
  312. }
  313. ::AfpAdminBufferFree( pAfpBadVolumes );
  314. }
  315. SetRedraw( TRUE );
  316. Invalidate( TRUE );
  317. return err;
  318. }
  319. /*******************************************************************
  320. NAME: VIEW_VOLUMES_DIALOG_BASE::VIEW_VOLUMES_DIALOG_BASE
  321. SYNOPSIS: Constructor
  322. ENTRY:
  323. idrsrcDialog - dialog resources id
  324. hwndOwner - handle of the parent
  325. pszServerName - current focus server
  326. ulHelpContextBase - the base help context
  327. EXIT:
  328. RETURNS:
  329. NOTES:
  330. HISTORY:
  331. NarenG 11/11/92 Modified for AFPMGR
  332. ********************************************************************/
  333. VIEW_VOLUMES_DIALOG_BASE::VIEW_VOLUMES_DIALOG_BASE(
  334. const IDRESOURCE &idrsrcDialog,
  335. const PWND2HWND &hwndOwner,
  336. AFP_SERVER_HANDLE hServer,
  337. const TCHAR *pszServerName,
  338. BOOL fDisplayBadVolumes,
  339. DWORD cidVolumeTitle,
  340. DWORD cidVolumesLb )
  341. : DIALOG_WINDOW( idrsrcDialog, hwndOwner ),
  342. _sltVolumeTitle( this, cidVolumeTitle ),
  343. _lbVolumes( this, fDisplayBadVolumes, cidVolumesLb, hServer ),
  344. _pszServerName( pszServerName ),
  345. _hServer( hServer ),
  346. _cidVolumesLb( cidVolumesLb )
  347. {
  348. //
  349. // Make sure everything constructed OK
  350. //
  351. if ( QueryError() != NERR_Success )
  352. return;
  353. APIERR err;
  354. if ( ((err = _sltVolumeTitle.QueryError()) != NERR_Success ) ||
  355. ((err = _lbVolumes.QueryError()) != NERR_Success ))
  356. {
  357. ReportError( err );
  358. return;
  359. }
  360. err = BASE_ELLIPSIS::Init();
  361. if( err != NO_ERROR )
  362. {
  363. ReportError( err );
  364. return;
  365. }
  366. }
  367. /*******************************************************************
  368. NAME: VIEW_VOLUMES_DIALOG_BASE::~VIEW_VOLUMES_DIALOG_BASE
  369. SYNOPSIS: Destructor
  370. ENTRY:
  371. EXIT:
  372. RETURNS:
  373. NOTES:
  374. HISTORY:
  375. NarenG 11/11/92 Modified for AFPMGR
  376. ********************************************************************/
  377. VIEW_VOLUMES_DIALOG_BASE::~VIEW_VOLUMES_DIALOG_BASE()
  378. {
  379. BASE_ELLIPSIS::Term();
  380. }
  381. /*******************************************************************
  382. NAME: VIEW_VOLUMES_DIALOG_BASE::SelectVolumeItem
  383. SYNOPSIS: Selects the item which has the same path as the
  384. supplied path.
  385. ENTRY:
  386. EXIT:
  387. RETURNS:
  388. NOTES:
  389. HISTORY:
  390. NarenG 11/11/92 Modified for AFPMGR
  391. ********************************************************************/
  392. APIERR VIEW_VOLUMES_DIALOG_BASE::SelectVolumeItem( const TCHAR * pszPath )
  393. {
  394. NLS_STR nlsPath( pszPath );
  395. APIERR err = nlsPath.QueryError();
  396. if ( err != NERR_Success )
  397. {
  398. return err;
  399. }
  400. INT ilbCount = _lbVolumes.QueryCount();
  401. for ( INT i = 0; i < ilbCount; i++ )
  402. {
  403. VIEW_VOLUMES_LBI *pvvlbi = _lbVolumes.QueryItem(i);
  404. if ( nlsPath._stricmp( pvvlbi->QueryVolumePath() ) == 0 )
  405. {
  406. _lbVolumes.SelectItem(i);
  407. break;
  408. }
  409. }
  410. return NERR_Success;
  411. }
  412. /*******************************************************************
  413. NAME: VIEW_VOLUMES_DIALOG_BASE::Refresh
  414. SYNOPSIS: Refresh the volumes listbox
  415. ENTRY:
  416. EXIT:
  417. RETURNS:
  418. NOTES:
  419. HISTORY:
  420. NarenG 11/11/92 Modified for AFPMGR
  421. ********************************************************************/
  422. DWORD VIEW_VOLUMES_DIALOG_BASE::Refresh( VOID )
  423. {
  424. APIERR err = _lbVolumes.Refresh();
  425. _lbVolumes.Enable( _lbVolumes.QueryCount() > 0 );
  426. _sltVolumeTitle.Enable( _lbVolumes.QueryCount() > 0 );
  427. return err;
  428. }
  429. /*******************************************************************
  430. NAME: VIEW_VOLUMES_DIALOG_BASE::OnCommand
  431. SYNOPSIS: Check if the user double clicks on a volume
  432. ENTRY: event - the event that occurred
  433. EXIT:
  434. RETURNS:
  435. NOTES:
  436. HISTORY:
  437. NarenG 11/11/92 Modified for AFPMGR
  438. ********************************************************************/
  439. BOOL VIEW_VOLUMES_DIALOG_BASE::OnCommand( const CONTROL_EVENT &event )
  440. {
  441. APIERR err = NERR_Success;
  442. if ( event.QueryCid() == _cidVolumesLb )
  443. {
  444. if ((event.QueryCode() == LBN_DBLCLK) && (_lbVolumes.QuerySelCount()>0))
  445. {
  446. return OnVolumeLbDblClk();
  447. }
  448. }
  449. return DIALOG_WINDOW::OnCommand( event );
  450. }
  451. /*******************************************************************
  452. NAME: VIEW_VOLUMES_DIALOG_BASE::VolumeDelete
  453. SYNOPSIS: Helper method to Delete a volume and popup any
  454. warning if some users are connected to the volume
  455. ENTRY:
  456. EXIT:
  457. RETURNS:
  458. NOTES:
  459. HISTORY:
  460. NarenG 11/11/92 Modified for AFPMGR
  461. ********************************************************************/
  462. DWORD VIEW_VOLUMES_DIALOG_BASE::VolumeDelete( VIEW_VOLUMES_LBI * pvlbi,
  463. BOOL * pfCancel )
  464. {
  465. *pfCancel = FALSE;
  466. //
  467. // If this is a bad volume simply delete it
  468. //
  469. if ( !(pvlbi->IsVolumeValid()) )
  470. {
  471. DWORD err = ::AfpAdminInvalidVolumeDelete(
  472. _hServer,
  473. (LPWSTR)pvlbi->QueryVolumeName() );
  474. return err;
  475. }
  476. BOOL fOK = TRUE;
  477. //
  478. // Check if there are any users connected to the volume
  479. // by enumerating the connections to this volume.
  480. //
  481. PAFP_CONNECTION_INFO pAfpConnections;
  482. DWORD cEntriesRead;
  483. DWORD cTotalAvail;
  484. DWORD err = ::AfpAdminConnectionEnum( _hServer,
  485. (LPBYTE*)&pAfpConnections,
  486. AFP_FILTER_ON_VOLUME_ID,
  487. pvlbi->QueryVolumeId(),
  488. (DWORD)-1, // Get all conenctions
  489. &cEntriesRead,
  490. &cTotalAvail,
  491. NULL );
  492. //
  493. // See if the connections are available.
  494. //
  495. if( err != NO_ERROR )
  496. {
  497. return err;
  498. }
  499. if ( cEntriesRead > 0 )
  500. {
  501. //
  502. // There are users currently connected to the share to be deleted,
  503. // hence, popup a dialog displaying all uses to the volume.
  504. //
  505. CURRENT_USERS_WARNING_DIALOG *pdlg =
  506. new CURRENT_USERS_WARNING_DIALOG( QueryRobustHwnd(),
  507. _hServer,
  508. pAfpConnections,
  509. cEntriesRead,
  510. pvlbi->QueryVolumeName());
  511. if ( ( pdlg == NULL )
  512. || ((err = pdlg->QueryError()) != NERR_Success )
  513. || ((err = pdlg->Process( &fOK )) != NERR_Success )
  514. )
  515. {
  516. err = pdlg == NULL ? ERROR_NOT_ENOUGH_MEMORY : err;
  517. }
  518. //
  519. // User clicked CANCEL for the pdlg
  520. //
  521. if ( ( err != NO_ERROR ) || !fOK )
  522. {
  523. *pfCancel = TRUE;
  524. }
  525. delete pdlg;
  526. }
  527. ::AfpAdminBufferFree( pAfpConnections );
  528. //
  529. // If user gave the go ahead to close the volume then go ahead and
  530. // try to close it.
  531. //
  532. if ( err == NO_ERROR && fOK )
  533. {
  534. err = ::AfpAdminVolumeDelete( _hServer,
  535. (LPWSTR)pvlbi->QueryVolumeName() );
  536. }
  537. return err;
  538. }
  539. /*******************************************************************
  540. NAME: VIEW_VOLUMES_DIALOG_BASE::IsFocusOnGoodVolume
  541. SYNOPSIS: Will check to see if the current selection is a good or
  542. bad volume.
  543. ENTRY:
  544. EXIT:
  545. RETURNS: Returns TRUE if current selection is a valid volume.
  546. FALSE otherwise.
  547. NOTES:
  548. HISTORY:
  549. NarenG 11/11/92 Modified for AFPMGR
  550. ********************************************************************/
  551. BOOL VIEW_VOLUMES_DIALOG_BASE::IsFocusOnGoodVolume( VOID ) const
  552. {
  553. if( _lbVolumes.QuerySelCount() > 0 )
  554. {
  555. return( _lbVolumes.QueryItem()->IsVolumeValid() );
  556. }
  557. return FALSE;
  558. }