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.

1537 lines
38 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * sharestp.cxx
  7. * Contain the dialog for deleting shares.
  8. *
  9. * FILE HISTORY:
  10. * Yi-HsinS 8/25/91 Created
  11. * Yi-HsinS 12/15/91 Uses SHARE_NET_NAME
  12. * Yi-HsinS 12/31/91 Unicode work
  13. * Yi-HsinS 1/6/92 Renamed to sharestp.cxx and separated
  14. * the create share dialogs to sharecrt.cxx
  15. * Yi-HsinS 3/12/92 Added STOP_SHARING_GROUP
  16. * Yi-HsinS 4/2/92 Added MayRun
  17. * Yi-HsinS 8/6/92 Reorganize to match Winball
  18. * Yi-HsinS 11/20/92 Added support for sticky shares
  19. */
  20. #define INCL_WINDOWS_GDI
  21. #define INCL_WINDOWS
  22. #define INCL_DOSERRORS
  23. #define INCL_NETERRORS
  24. #define INCL_NETSHARE
  25. #define INCL_NETSERVER
  26. #define INCL_NETCONS
  27. #define INCL_NETLIB
  28. #include <lmui.hxx>
  29. extern "C"
  30. {
  31. #include <sharedlg.h>
  32. #include <helpnums.h>
  33. #include <winlocal.h>
  34. #include <mnet.h>
  35. }
  36. #define INCL_BLT_DIALOG
  37. #define INCL_BLT_CONTROL
  38. #define INCL_BLT_MSGPOPUP
  39. #define INCL_BLT_SPIN_GROUP
  40. #include <blt.hxx>
  41. #include <string.hxx>
  42. #include <uitrace.hxx>
  43. #include <strnumer.hxx>
  44. #include <lmoshare.hxx>
  45. #include <lmoesh.hxx>
  46. #include <lmoeconn.hxx>
  47. #include <lmosrv.hxx>
  48. #include <ctime.hxx>
  49. #include <intlprof.hxx>
  50. #include <strchlit.hxx> // for string and character constants
  51. #include "sharestp.hxx"
  52. /*******************************************************************
  53. NAME: SHARE_LBI::SHARE_LBI
  54. SYNOPSIS: Listbox items used in the SHARE_LISTBOX
  55. ENTRY: s2 - object returned by SHARE2_ENUM_ITER
  56. EXIT:
  57. RETURNS:
  58. NOTES:
  59. HISTORY:
  60. Yi-HsinS 1/8/92 Created
  61. ********************************************************************/
  62. SHARE_LBI::SHARE_LBI( const SHARE2_ENUM_OBJ &s2, UINT nType )
  63. : _nlsShareName( s2.QueryName()),
  64. _nlsSharePath( s2.QueryPath()),
  65. _nType ( nType )
  66. {
  67. if ( QueryError() != NERR_Success )
  68. return;
  69. APIERR err;
  70. if ( (( err = _nlsShareName.QueryError()) != NERR_Success )
  71. || (( err = _nlsSharePath.QueryError()) != NERR_Success )
  72. )
  73. {
  74. ReportError( err );
  75. return;
  76. }
  77. }
  78. /*******************************************************************
  79. NAME: SHARE_LBI::~SHARE_LBI
  80. SYNOPSIS: Destructor
  81. ENTRY:
  82. EXIT:
  83. RETURNS:
  84. NOTES:
  85. HISTORY:
  86. Yi-HsinS 1/6/92 Created
  87. ********************************************************************/
  88. SHARE_LBI::~SHARE_LBI()
  89. {
  90. }
  91. /*******************************************************************
  92. NAME: SHARE_LBI::QueryLeadingChar
  93. SYNOPSIS: Returns the leading character of the listbox item.
  94. The enables shortcut keys in the listbox
  95. ENTRY:
  96. EXIT:
  97. RETURNS: Returns the first char of the share name
  98. NOTES:
  99. HISTORY:
  100. Yi-HsinS 1/6/92 Created
  101. ********************************************************************/
  102. WCHAR SHARE_LBI::QueryLeadingChar( VOID ) const
  103. {
  104. ISTR istr( _nlsShareName );
  105. return _nlsShareName.QueryChar( istr );
  106. }
  107. /*******************************************************************
  108. NAME: SHARE_LBI::Paint
  109. SYNOPSIS: Redefine Paint() method of LBI class
  110. ENTRY:
  111. EXIT:
  112. RETURNS:
  113. NOTES:
  114. HISTORY:
  115. Yi-HsinS 1/8/92 Created
  116. beng 22-Apr-1992 Change to LBI::Paint
  117. ********************************************************************/
  118. VOID SHARE_LBI::Paint( LISTBOX *plb,
  119. HDC hdc,
  120. const RECT *prect,
  121. GUILTT_INFO *pGUILTT ) const
  122. {
  123. STR_DTE strdteShareName( _nlsShareName );
  124. STR_DTE strdteSharePath( _nlsSharePath );
  125. DISPLAY_TABLE dt(3, ((SHARE_LISTBOX *) plb)->QueryColumnWidths() );
  126. dt[0] = _nType == DISKSHARE_TYPE
  127. ? ((SHARE_LISTBOX *) plb)->QueryShareBitmap()
  128. : ( _nType == STICKYSHARE_TYPE
  129. ? ((SHARE_LISTBOX *) plb)->QueryStickyShareBitmap()
  130. : ((SHARE_LISTBOX *) plb)->QueryIPCShareBitmap());
  131. dt[1] = &strdteShareName;
  132. dt[2] = &strdteSharePath;
  133. dt.Paint( plb, hdc, prect, pGUILTT );
  134. }
  135. /*******************************************************************
  136. NAME: SHARE_LBI::Compare
  137. SYNOPSIS: Redefine Compare() method of LBI class
  138. We compare the share names of two LBIs.
  139. ENTRY: plbi - pointer to the LBI to compare with
  140. EXIT:
  141. RETURNS:
  142. NOTES:
  143. HISTORY:
  144. Yi-HsinS 1/8/92 Created
  145. ********************************************************************/
  146. INT SHARE_LBI::Compare( const LBI *plbi ) const
  147. {
  148. return( _nlsShareName._stricmp( ((const SHARE_LBI *) plbi)->_nlsShareName ));
  149. }
  150. /*******************************************************************
  151. NAME: SHARE_LISTBOX::SHARE_LISTBOX
  152. SYNOPSIS: Constructor
  153. ENTRY: powin - owner window
  154. cid - resource id of the share listbox
  155. nShareType - The type of shares to be displayed in the listbox
  156. EXIT:
  157. RETURNS:
  158. NOTES:
  159. HISTORY:
  160. Yi-HsinS 1/20/92 Created
  161. ********************************************************************/
  162. SHARE_LISTBOX::SHARE_LISTBOX( OWNER_WINDOW *powin, CID cid, UINT nShareType )
  163. : BLT_LISTBOX ( powin, cid ),
  164. _pdmdte ( NULL ),
  165. _pdmdteSticky( NULL ),
  166. _pdmdteIPC ( NULL ),
  167. _nShareType ( nShareType )
  168. {
  169. if ( QueryError() != NERR_Success )
  170. return;
  171. APIERR err = ERROR_NOT_ENOUGH_MEMORY;
  172. if ( ((_pdmdte = new DMID_DTE( BMID_SHARE )) == NULL )
  173. || ((_pdmdteSticky = new DMID_DTE( BMID_STICKYSHARE )) == NULL )
  174. || ((_pdmdteIPC = new DMID_DTE( BMID_IPCSHARE )) == NULL )
  175. || ((err = _pdmdte->QueryError()) != NERR_Success )
  176. || ((err = _pdmdteSticky->QueryError()) != NERR_Success )
  177. || ((err = DISPLAY_TABLE::CalcColumnWidths( _adx, 3, powin, cid, TRUE))
  178. != NERR_Success )
  179. )
  180. {
  181. ReportError( err );
  182. return;
  183. }
  184. }
  185. /*******************************************************************
  186. NAME: SHARE_LISTBOX::~SHARE_LISTBOX
  187. SYNOPSIS: Destructor
  188. ENTRY:
  189. EXIT:
  190. RETURNS:
  191. NOTES:
  192. HISTORY:
  193. Yi-HsinS 1/20/92 Created
  194. ********************************************************************/
  195. SHARE_LISTBOX::~SHARE_LISTBOX()
  196. {
  197. // Delete the share bitmap
  198. delete _pdmdte;
  199. _pdmdte = NULL;
  200. delete _pdmdteSticky;
  201. _pdmdteSticky = NULL;
  202. delete _pdmdteIPC;
  203. _pdmdteIPC = NULL;
  204. }
  205. /*******************************************************************
  206. NAME: SHARE_LISTBOX::Update
  207. SYNOPSIS: Update (refresh) the shares in the listbox
  208. ENTRY: pszComputer - The computer to set focus to, will be an
  209. empty string if the computer is local.
  210. EXIT:
  211. RETURNS:
  212. NOTES:
  213. HISTORY:
  214. Yi-HsinS 1/7/92 Created
  215. *******************************************************************/
  216. APIERR SHARE_LISTBOX::Update( SERVER_WITH_PASSWORD_PROMPT *psvr )
  217. {
  218. APIERR err = NERR_Success;
  219. ALIAS_STR nlsServer( psvr->QueryName() );
  220. DeleteAllItems();
  221. SetRedraw( FALSE );
  222. do // Not a loop, just a way to break out in case error occurred
  223. {
  224. SHARE2_ENUM sh2Enum( nlsServer );
  225. if ( ((err = sh2Enum.QueryError()) != NERR_Success )
  226. || ((err = sh2Enum.GetInfo()) != NERR_Success )
  227. )
  228. {
  229. break;
  230. }
  231. //
  232. // First, add the shares that are created
  233. //
  234. SHARE2_ENUM_ITER shi2( sh2Enum );
  235. const SHARE2_ENUM_OBJ *pshi2 = NULL;
  236. while ( (pshi2 = shi2() ) != NULL )
  237. {
  238. UINT nCurrentShareType = pshi2->QueryType() & ~STYPE_SPECIAL;
  239. //
  240. // Filter out unwanted shares
  241. //
  242. if ( _nShareType != STYPE_ALL_SHARE )
  243. {
  244. if (!( ( ( _nShareType & STYPE_DISK_SHARE )
  245. && ( nCurrentShareType == STYPE_DISKTREE ))
  246. || ( ( _nShareType & STYPE_PRINT_SHARE )
  247. && ( nCurrentShareType == STYPE_PRINTQ ))
  248. || ( ( _nShareType & STYPE_IPC_SHARE )
  249. && ( nCurrentShareType == STYPE_IPC ))))
  250. {
  251. continue;
  252. }
  253. }
  254. //
  255. // Add the share to the listbox
  256. //
  257. SHARE_LBI *psharelbi = new SHARE_LBI( *pshi2,
  258. nCurrentShareType == STYPE_IPC?
  259. IPCSHARE_TYPE : DISKSHARE_TYPE );
  260. if ( ( psharelbi == NULL )
  261. || ( ( err = psharelbi->QueryError() ) != NERR_Success )
  262. || ( AddItem( psharelbi ) < 0 )
  263. )
  264. {
  265. err = err? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  266. delete psharelbi;
  267. psharelbi = NULL;
  268. break;
  269. }
  270. }
  271. if ( !psvr->IsNT() )
  272. break;
  273. //
  274. // If we are focusing on NT, add the sticky shares.
  275. // AddItemIdemp will delete the item if it already exist in the listbox.
  276. //
  277. SHARE2_ENUM sh2EnumSticky( nlsServer, STICKYSHARE_TYPE );
  278. if ( ((err = sh2EnumSticky.QueryError()) != NERR_Success )
  279. || ((err = sh2EnumSticky.GetInfo()) != NERR_Success )
  280. )
  281. {
  282. break;
  283. }
  284. SHARE2_ENUM_ITER shi2Sticky( sh2EnumSticky );
  285. while ( (pshi2 = shi2Sticky()) != NULL )
  286. {
  287. //
  288. // Filter out unwanted shares
  289. //
  290. if ( _nShareType != STYPE_ALL_SHARE )
  291. {
  292. UINT nCurrentShareType = pshi2->QueryType() & ~STYPE_SPECIAL;
  293. if (!( ( ( _nShareType & STYPE_DISK_SHARE )
  294. && ( nCurrentShareType == STYPE_DISKTREE ))
  295. || ( ( _nShareType & STYPE_PRINT_SHARE )
  296. && ( nCurrentShareType == STYPE_PRINTQ ))
  297. || ( ( _nShareType & STYPE_IPC_SHARE )
  298. && ( nCurrentShareType == STYPE_IPC ))))
  299. {
  300. continue;
  301. }
  302. }
  303. //
  304. // Add the sticky share to the listbox
  305. //
  306. SHARE_LBI *psharelbi = new SHARE_LBI( *pshi2, TRUE );
  307. if ( ( psharelbi == NULL )
  308. || ( ( err = psharelbi->QueryError() ) != NERR_Success )
  309. || ( AddItemIdemp( psharelbi ) < 0 )
  310. )
  311. {
  312. err = err? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  313. delete psharelbi;
  314. psharelbi = NULL;
  315. break;
  316. }
  317. }
  318. }
  319. while ( FALSE );
  320. Invalidate( TRUE );
  321. SetRedraw( TRUE );
  322. return err;
  323. }
  324. /*******************************************************************
  325. NAME: VIEW_SHARE_DIALOG_BASE::VIEW_SHARE_DIALOG_BASE
  326. SYNOPSIS: Constructor
  327. ENTRY: pszDlgResource - name of the dialog
  328. hwndParent - handle of the parent
  329. nShareType - the type of share to display
  330. ulHelpContextBase - the base help context
  331. EXIT:
  332. RETURNS:
  333. NOTES:
  334. HISTORY:
  335. Yi-HsinS 8/25/91 Created
  336. ********************************************************************/
  337. VIEW_SHARE_DIALOG_BASE::VIEW_SHARE_DIALOG_BASE( const TCHAR *pszDlgResource,
  338. HWND hwndParent,
  339. ULONG ulHelpContextBase,
  340. UINT nShareType )
  341. : DIALOG_WINDOW ( pszDlgResource, hwndParent ),
  342. _sltShareTitle( this, SLT_SHARETITLE ),
  343. _lbShare ( this, LB_SHARE, nShareType ),
  344. _psvr ( NULL ),
  345. _ulHelpContextBase( ulHelpContextBase )
  346. {
  347. if ( QueryError() != NERR_Success )
  348. return;
  349. }
  350. /*******************************************************************
  351. NAME: VIEW_SHARE_DIALOG_BASE::~VIEW_SHARE_DIALOG_BASE
  352. SYNOPSIS: Destructor
  353. ENTRY:
  354. EXIT:
  355. RETURNS:
  356. NOTES:
  357. HISTORY:
  358. Yi-HsinS 8/8/92 Created
  359. ********************************************************************/
  360. VIEW_SHARE_DIALOG_BASE::~VIEW_SHARE_DIALOG_BASE()
  361. {
  362. delete _psvr;
  363. _psvr = NULL;
  364. }
  365. /*******************************************************************
  366. NAME: VIEW_SHARE_DIALOG_BASE::InitComputer
  367. SYNOPSIS: Initialize the dialog and internal variables
  368. to focus on the selected computer
  369. ENTRY: pszComputer - name of the computer to set focus on
  370. EXIT:
  371. RETURNS:
  372. NOTES:
  373. HISTORY:
  374. Yi-HsinS 8/8/92 Created
  375. ********************************************************************/
  376. APIERR VIEW_SHARE_DIALOG_BASE::InitComputer( const TCHAR *pszComputer )
  377. {
  378. APIERR err;
  379. do { // not a loop
  380. //
  381. // Display the title of the listbox
  382. //
  383. LOCATION loc( pszComputer, FALSE );
  384. NLS_STR nlsComputer;
  385. if ( ((err = nlsComputer.QueryError()) != NERR_Success )
  386. || ((err = loc.QueryDisplayName( &nlsComputer)) != NERR_Success )
  387. )
  388. {
  389. break;
  390. }
  391. const NLS_STR *apnlsParams[2];
  392. apnlsParams[0] = (NLS_STR *) &nlsComputer;
  393. apnlsParams[1] = NULL;
  394. RESOURCE_STR nlsTitle( IDS_SHARE_LB_TITLE_TEXT );
  395. if ( ((err = nlsTitle.QueryError()) != NERR_Success )
  396. || ((err = nlsTitle.InsertParams( apnlsParams )) != NERR_Success )
  397. )
  398. {
  399. break;
  400. }
  401. _sltShareTitle.SetText( nlsTitle );
  402. //
  403. // Initialize the SERVER_WITH_PASSWORD_PROMPT object
  404. //
  405. LOCATION locLocal; // local computer
  406. NLS_STR nlsLocalComputer;
  407. if ( (err = locLocal.QueryDisplayName( &nlsLocalComputer))
  408. != NERR_Success )
  409. break;
  410. if( !::I_MNetComputerNameCompare( nlsLocalComputer, nlsComputer ) )
  411. nlsComputer = EMPTY_STRING;
  412. _psvr = new SERVER_WITH_PASSWORD_PROMPT( nlsComputer,
  413. QueryRobustHwnd(),
  414. QueryHelpContextBase());
  415. if ( ( _psvr == NULL )
  416. || ((err = _psvr->QueryError() ) != NERR_Success )
  417. || ((err = _psvr->GetInfo() ) != NERR_Success )
  418. )
  419. {
  420. err = err? err: (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  421. delete _psvr;
  422. _psvr = NULL;
  423. break;
  424. }
  425. //
  426. // Update the listbox and disable it if the number of items is zero
  427. //
  428. err = err? err : _lbShare.Update( _psvr );
  429. _lbShare.Enable( _lbShare.QueryCount() > 0 );
  430. _sltShareTitle.Enable( _lbShare.QueryCount() > 0 );
  431. if ( _lbShare.QueryCount() > 0 )
  432. _lbShare.ClaimFocus();
  433. } while ( FALSE );
  434. return err;
  435. }
  436. /*******************************************************************
  437. NAME: VIEW_SHARE_DIALOG_BASE::Refresh
  438. SYNOPSIS: Refresh the share listbox
  439. ENTRY:
  440. EXIT:
  441. RETURNS:
  442. NOTES:
  443. HISTORY:
  444. Yi-HsinS 8/8/92 Created
  445. ********************************************************************/
  446. APIERR VIEW_SHARE_DIALOG_BASE::Refresh( VOID )
  447. {
  448. AUTO_CURSOR autocur;
  449. UIASSERT( _psvr != NULL );
  450. APIERR err = _lbShare.Update( _psvr );
  451. _lbShare.Enable( _lbShare.QueryCount() > 0 );
  452. _sltShareTitle.Enable( _lbShare.QueryCount() > 0 );
  453. return err;
  454. }
  455. /*******************************************************************
  456. NAME: VIEW_SHARE_DIALOG_BASE::OnCommand
  457. SYNOPSIS: Check if the user double clicks on a share
  458. ENTRY: event - the event that occurred
  459. EXIT:
  460. RETURNS:
  461. NOTES:
  462. HISTORY:
  463. Yi-HsinS 1/8/92 Created
  464. ********************************************************************/
  465. BOOL VIEW_SHARE_DIALOG_BASE::OnCommand( const CONTROL_EVENT &event )
  466. {
  467. APIERR err = NERR_Success;
  468. switch ( event.QueryCid() )
  469. {
  470. case LB_SHARE:
  471. if ( ( event.QueryCode() == LBN_DBLCLK )
  472. && ( _lbShare.QuerySelCount() > 0 )
  473. )
  474. {
  475. return OnShareLbDblClk();
  476. }
  477. break;
  478. default:
  479. return DIALOG_WINDOW::OnCommand( event );
  480. }
  481. return TRUE;
  482. }
  483. /*******************************************************************
  484. NAME: VIEW_SHARE_DIALOG_BASE::StopShare
  485. SYNOPSIS: Helper method to delete a share and popup any
  486. warning if some users are connected to the share
  487. ENTRY: pszShare - the share to be deleted
  488. EXIT: pfCancel - pointer to a BOOLEAN indicating whether
  489. the user decided to cancel deleting the share
  490. RETURNS:
  491. NOTES:
  492. HISTORY:
  493. Yi-HsinS 8/8/92 Created
  494. ********************************************************************/
  495. APIERR VIEW_SHARE_DIALOG_BASE::StopShare( const TCHAR *pszShare, BOOL *pfCancel)
  496. {
  497. UIASSERT( pfCancel != NULL );
  498. *pfCancel = FALSE;
  499. ALIAS_STR nlsShare( pszShare );
  500. ALIAS_STR nlsComputer( _psvr->QueryName() );
  501. APIERR err = NERR_Success;
  502. SHARE_2 sh2( nlsShare, nlsComputer, FALSE );
  503. //
  504. // Check if there are any users connected to the share
  505. //
  506. if ( (( err = sh2.QueryError()) == NERR_Success )
  507. && (( err = sh2.GetInfo()) == NERR_Success )
  508. && ( sh2.QueryCurrentUses() > 0 )
  509. )
  510. {
  511. //
  512. // There are users currently connected to the share to be deleted,
  513. // hence, popup a dialog displaying all uses to the share.
  514. //
  515. BOOL fOK = TRUE;
  516. CURRENT_USERS_WARNING_DIALOG *pdlg =
  517. new CURRENT_USERS_WARNING_DIALOG( QueryRobustHwnd(),
  518. nlsComputer,
  519. nlsShare,
  520. QueryHelpContextBase() );
  521. if ( ( pdlg == NULL )
  522. || ((err = pdlg->QueryError()) != NERR_Success )
  523. || ((err = pdlg->Process( &fOK )) != NERR_Success )
  524. )
  525. {
  526. err = err? err : (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  527. }
  528. // User clicked CANCEL for the pdlg
  529. if ( !err && !fOK )
  530. {
  531. *pfCancel = TRUE;
  532. }
  533. delete pdlg;
  534. }
  535. if ( !err && !*pfCancel )
  536. err = sh2.Delete();
  537. return err;
  538. }
  539. /*******************************************************************
  540. NAME: STOP_SHARING_DIALOG::STOP_SHARING_DIALOG
  541. SYNOPSIS: Constructor
  542. ENTRY: hwndParent - handle of parent window
  543. pszSelectedDir - the directory selected in the
  544. file manager. This will be used
  545. to determine which computer the
  546. user is currently focusing on.
  547. ulHelpContextBase - the base help context
  548. EXIT:
  549. RETURNS:
  550. NOTES:
  551. HISTORY:
  552. Yi-HsinS 8/25/91 Created
  553. ********************************************************************/
  554. STOP_SHARING_DIALOG::STOP_SHARING_DIALOG( HWND hwndParent,
  555. const TCHAR *pszSelectedDir,
  556. ULONG ulHelpContextBase )
  557. : VIEW_SHARE_DIALOG_BASE( MAKEINTRESOURCE(IDD_SHARESTOPDLG),
  558. hwndParent,
  559. ulHelpContextBase,
  560. STYPE_DISK_SHARE ),
  561. _buttonOK ( this, IDOK ),
  562. _buttonCancel( this, IDCANCEL ),
  563. _stpShareGrp ( QueryLBShare(), &_buttonOK, &_buttonCancel )
  564. {
  565. if ( QueryError() != NERR_Success )
  566. return;
  567. APIERR err;
  568. if ( ((err = _stpShareGrp.QueryError() ) != NERR_Success )
  569. || ((err = Init( pszSelectedDir ) ) != NERR_Success )
  570. )
  571. {
  572. if ( err == ERROR_INVALID_LEVEL ) // winball machine
  573. err = ERROR_NOT_SUPPORTED;
  574. ReportError( err );
  575. return;
  576. }
  577. }
  578. /*******************************************************************
  579. NAME: STOP_SHARING_DIALOG::Init
  580. SYNOPSIS: 2nd stage constructor
  581. ENTRY: pszSelectedDir - the directory selected in the
  582. file manager. This will be used
  583. to determine which computer the
  584. user is currently focusing on.
  585. EXIT:
  586. RETURNS:
  587. NOTES: If no directory is selected, then the focus is
  588. set to the local computer.
  589. HISTORY:
  590. Yi-HsinS 4/2/92 Created
  591. ********************************************************************/
  592. APIERR STOP_SHARING_DIALOG::Init( const TCHAR *pszSelectedDir )
  593. {
  594. AUTO_CURSOR autocur;
  595. APIERR err;
  596. do { // Not a loop
  597. ALIAS_STR nlsSelectedDir( pszSelectedDir );
  598. NLS_STR nlsServerString;
  599. if ((err = nlsServerString.QueryError()) != NERR_Success )
  600. break;
  601. //
  602. // If no file is selected, set the focus to the local computer.
  603. //
  604. if ( nlsSelectedDir.QueryTextLength() == 0 )
  605. {
  606. err = InitComputer( nlsServerString );
  607. break;
  608. }
  609. //
  610. // Get the computer the selected file/dir is on
  611. //
  612. SHARE_NET_NAME netName( pszSelectedDir, TYPE_PATH_ABS );
  613. if ( ((err = netName.QueryError()) != NERR_Success )
  614. || ((err = netName.QueryComputerName( &nlsServerString ))
  615. != NERR_Success )
  616. || ((err = InitComputer( nlsServerString )) != NERR_Success )
  617. )
  618. {
  619. break;
  620. }
  621. //
  622. // Search for share names that have paths that are the same
  623. // as the selected directory and then select them in the share listbox.
  624. //
  625. NLS_STR nlsPath;
  626. if ( (( err = nlsPath.QueryError()) != NERR_Success )
  627. || (( err = netName.QueryLocalPath( &nlsPath )) != NERR_Success )
  628. )
  629. {
  630. break;
  631. }
  632. SHARE_LISTBOX *plbShare = QueryLBShare();
  633. INT ilbCount = plbShare->QueryCount();
  634. INT iFirstSelected = -1;
  635. for ( INT i = 0; i < ilbCount; i++ )
  636. {
  637. SHARE_LBI *pshlbi = plbShare->QueryItem(i);
  638. if ( nlsPath._stricmp( *(pshlbi->QuerySharePath())) == 0 )
  639. {
  640. if ( iFirstSelected < 0 )
  641. iFirstSelected = i;
  642. plbShare->SelectItem(i);
  643. }
  644. }
  645. if ( iFirstSelected >= 0 )
  646. plbShare->SetTopIndex( iFirstSelected );
  647. // Falls through if error occurs
  648. } while ( FALSE );
  649. if ( err == NERR_Success )
  650. {
  651. //
  652. // Make OK the default button if shares are selected in the listbox
  653. // and Cancel the default button otherwise.
  654. //
  655. SHARE_LISTBOX *plbShare = QueryLBShare();
  656. if ( plbShare->QuerySelCount() > 0 )
  657. _buttonOK.MakeDefault();
  658. else
  659. _buttonCancel.MakeDefault();
  660. if ( plbShare->QueryCount() == 0 )
  661. {
  662. err = IERR_NO_SHARES_ON_SERVER;
  663. }
  664. }
  665. return err;
  666. }
  667. /*******************************************************************
  668. NAME: STOP_SHARING_DIALOG::OnShareLbDblClk
  669. SYNOPSIS: When the user double clicks on the share,
  670. it's as if the user is clicking the OK button.
  671. ENTRY:
  672. EXIT:
  673. RETURNS:
  674. NOTES:
  675. HISTORY:
  676. Yi-HsinS 8/25/91 Created
  677. ********************************************************************/
  678. BOOL STOP_SHARING_DIALOG::OnShareLbDblClk( VOID )
  679. {
  680. return OnOK();
  681. }
  682. /*******************************************************************
  683. NAME: STOP_SHARING_DIALOG::OnOK
  684. SYNOPSIS: Gather information and delete the shares selected
  685. in the listbox.
  686. ENTRY:
  687. EXIT:
  688. RETURNS:
  689. NOTES:
  690. HISTORY:
  691. Yi-HsinS 8/25/91 Created
  692. ********************************************************************/
  693. BOOL STOP_SHARING_DIALOG::OnOK( VOID )
  694. {
  695. AUTO_CURSOR autocur;
  696. APIERR err = NERR_Success;
  697. SHARE_LISTBOX *plbShare = QueryLBShare();
  698. INT ciMax = plbShare->QuerySelCount();
  699. //
  700. // If there are no items selected in the listbox,
  701. // just dismiss the dialog.
  702. //
  703. if ( ciMax == 0 )
  704. {
  705. Dismiss( FALSE );
  706. return TRUE;
  707. }
  708. //
  709. // Get all the items selected in the listbox
  710. //
  711. INT *paSelItems = (INT *) new BYTE[ sizeof(INT) * ciMax ];
  712. if ( paSelItems == NULL )
  713. {
  714. ::MsgPopup( this, ERROR_NOT_ENOUGH_MEMORY);
  715. return TRUE;
  716. }
  717. // JonN 01/27/00: PREFIX bug 444909
  718. ::ZeroMemory( paSelItems, sizeof(INT)*ciMax );
  719. err = plbShare->QuerySelItems( paSelItems, ciMax );
  720. UIASSERT( err == NERR_Success );
  721. //
  722. // Loop through each share that the user selects in the listbox
  723. // and stop sharing the share. We will break out of the loop
  724. // if any error occurred in stopping a share or if the user
  725. // decides not stop sharing any share that some user is connected to.
  726. //
  727. BOOL fCancel = FALSE;
  728. BOOL fDeleted = FALSE;
  729. SHARE_LBI *pshlbi = NULL;
  730. for ( INT i = 0; i < ciMax; i++ )
  731. {
  732. pshlbi = plbShare->QueryItem( paSelItems[i] );
  733. if (NULL == pshlbi) continue; // JonN 01/27/00: PREFIX bug 444910
  734. if ( pshlbi->IsSticky() )
  735. {
  736. err = ::MNetShareDelSticky( QueryComputerName(),
  737. pshlbi->QueryShareName()->QueryPch(),
  738. 0 ); // Reserved
  739. }
  740. else
  741. {
  742. err = StopShare( pshlbi->QueryShareName()->QueryPch(), &fCancel );
  743. }
  744. if (( err != NERR_Success ) || fCancel )
  745. break;
  746. fDeleted = TRUE;
  747. }
  748. delete paSelItems;
  749. paSelItems = NULL;
  750. //
  751. // Dismiss the dialog only if everything went on smoothly or if
  752. // we get an NERR_BadTransactConfig error.
  753. //
  754. if ( err != NERR_Success )
  755. {
  756. if ( err == NERR_NetNameNotFound )
  757. {
  758. ::MsgPopup( this, IERR_SHARE_NOT_FOUND, MPSEV_ERROR, MP_OK,
  759. pshlbi->QueryShareName()->QueryPch());
  760. }
  761. else if ( err == NERR_BadTransactConfig )
  762. {
  763. DismissMsg( err );
  764. }
  765. else
  766. {
  767. ::MsgPopup( this, err );
  768. }
  769. }
  770. else if ( !fCancel )
  771. {
  772. Dismiss( TRUE );
  773. }
  774. //
  775. // Refresh the listbox if some shares have already been deleted or if
  776. // the error NERR_NetNameNotFound occurred.
  777. //
  778. if (( fDeleted) || ( err == NERR_NetNameNotFound) )
  779. {
  780. err = Refresh();
  781. if ( err != NERR_Success )
  782. {
  783. ::MsgPopup( this, err );
  784. }
  785. else
  786. {
  787. _buttonOK.Enable( plbShare->QueryCount() > 0 );
  788. if ( plbShare->QueryCount() > 0 )
  789. plbShare->ClaimFocus();
  790. else
  791. _buttonCancel.ClaimFocus();
  792. }
  793. }
  794. return TRUE;
  795. }
  796. /*******************************************************************
  797. NAME: STOP_SHARING_DIALOG::QueryHelpContext
  798. SYNOPSIS: Get the help context of the dialog
  799. ENTRY:
  800. EXIT:
  801. RETURNS: Returns the help context
  802. NOTES:
  803. HISTORY:
  804. Yi-HsinS 8/25/91 Created
  805. ********************************************************************/
  806. ULONG STOP_SHARING_DIALOG::QueryHelpContext( VOID )
  807. {
  808. return QueryHelpContextBase() + HC_FILEMGRSTOPSHARE;
  809. }
  810. /*******************************************************************
  811. NAME: STOP_SHARING_GROUP::STOP_SHARING_GROUP
  812. SYNOPSIS: Constructor
  813. ENTRY: plbShareName - pointer to share name combo box
  814. pbuttonOK - pointer to the OK push button
  815. pbuttonCancel- pointer to the CANCEL push button
  816. EXIT:
  817. RETURNS:
  818. NOTES:
  819. HISTORY:
  820. Yi-HsinS 3/12/92 Created
  821. ********************************************************************/
  822. STOP_SHARING_GROUP::STOP_SHARING_GROUP( SHARE_LISTBOX *plbShare,
  823. PUSH_BUTTON *pbuttonOK,
  824. PUSH_BUTTON *pbuttonCancel )
  825. : _plbShare ( plbShare ),
  826. _pbuttonOK ( pbuttonOK ),
  827. _pbuttonCancel( pbuttonCancel )
  828. {
  829. UIASSERT( _plbShare );
  830. UIASSERT( _pbuttonOK );
  831. UIASSERT( _pbuttonCancel );
  832. _plbShare->SetGroup( this );
  833. }
  834. /*******************************************************************
  835. NAME: STOP_SHARING_GROUP::~STOP_SHARING_GROUP
  836. SYNOPSIS: Destructor
  837. ENTRY:
  838. EXIT:
  839. RETURNS:
  840. NOTES:
  841. HISTORY:
  842. Yi-HsinS 3/12/92 Created
  843. ********************************************************************/
  844. STOP_SHARING_GROUP::~STOP_SHARING_GROUP()
  845. {
  846. _plbShare = NULL;
  847. _pbuttonOK = NULL;
  848. _pbuttonCancel = NULL;
  849. }
  850. /*******************************************************************
  851. NAME: STOP_SHARING_GROUP::OnUserAction
  852. SYNOPSIS: If share name listbox box is empty, set the default button
  853. to CANCEL, else set the default button to OK.
  854. ENTRY:
  855. EXIT:
  856. RETURNS:
  857. NOTES:
  858. HISTORY:
  859. Yi-HsinS 3/12/92 Created
  860. ********************************************************************/
  861. APIERR STOP_SHARING_GROUP::OnUserAction( CONTROL_WINDOW *pcw,
  862. const CONTROL_EVENT &e )
  863. {
  864. if ( pcw == QueryLBShare() )
  865. {
  866. if ( e.QueryCode() == LBN_SELCHANGE )
  867. {
  868. if ( QueryLBShare()->QuerySelCount() > 0 )
  869. _pbuttonOK->MakeDefault();
  870. else
  871. _pbuttonCancel->MakeDefault();
  872. }
  873. }
  874. return GROUP_NO_CHANGE;
  875. }
  876. /*******************************************************************
  877. NAME: CURRENT_USERS_WARNING_DIALOG::CURRENT_USERS_WARNING_DIALOG
  878. SYNOPSIS: Constructor
  879. ENTRY: hwndParent - hwnd of Parent Window
  880. pszServer - Server Name
  881. pszShare - Share Name
  882. ulHelpContextBase - the base help context
  883. EXIT:
  884. RETURNS:
  885. NOTES:
  886. HISTORY:
  887. Yi-HsinS 8/25/91 Created
  888. ********************************************************************/
  889. CURRENT_USERS_WARNING_DIALOG::CURRENT_USERS_WARNING_DIALOG( HWND hwndParent,
  890. const TCHAR *pszServer,
  891. const TCHAR *pszShare,
  892. ULONG ulHelpContextBase )
  893. : DIALOG_WINDOW( IDD_SHAREUSERSWARNINGDLG, hwndParent ),
  894. _sltShareText( this, SLT_SHARE_TEXT ),
  895. _lbUsers( this, LB_USERS ),
  896. _ulHelpContextBase( ulHelpContextBase )
  897. {
  898. if ( QueryError() != NERR_Success )
  899. return;
  900. UIASSERT( pszShare );
  901. APIERR err;
  902. ALIAS_STR nlsShare( pszShare );
  903. RESOURCE_STR nlsShareText( IDS_SHARE_CURRENT_USERS_TEXT );
  904. if (( err = nlsShareText.InsertParams( nlsShare )) != NERR_Success )
  905. {
  906. ReportError( err );
  907. return;
  908. }
  909. _sltShareText.SetText( nlsShareText );
  910. //
  911. // Gather all connections to the share that the user wants to delete.
  912. //
  913. CONN1_ENUM c1( (TCHAR *) pszServer, (TCHAR *) pszShare );
  914. if ( ((err = c1.QueryError()) != NERR_Success )
  915. || ((err = c1.GetInfo()) != NERR_Success )
  916. )
  917. {
  918. ReportError( err );
  919. return;
  920. }
  921. CONN1_ENUM_ITER ci1( c1 );
  922. const CONN1_ENUM_OBJ *pci1;
  923. _lbUsers.SetRedraw( FALSE );
  924. while ( ( pci1 = ci1() ) != NULL)
  925. {
  926. USERS_LBI *puserslbi = new USERS_LBI( *pci1 );
  927. if ( ( puserslbi == NULL )
  928. || ( (err = puserslbi->QueryError()) != NERR_Success )
  929. || ( _lbUsers.AddItem( puserslbi ) < 0 )
  930. )
  931. {
  932. //
  933. // If err is still NERR_Success, set it to ERROR_NOT_ENOUGH_MEMORY
  934. // ( either allocation failed or failed to add it in list box )
  935. //
  936. err = err? err: (APIERR) ERROR_NOT_ENOUGH_MEMORY;
  937. delete puserslbi;
  938. puserslbi = NULL;
  939. ReportError( err );
  940. return;
  941. }
  942. }
  943. _lbUsers.Invalidate( TRUE );
  944. _lbUsers.SetRedraw( TRUE );
  945. }
  946. /*******************************************************************
  947. NAME: CURRENT_USERS_WARNING_DIALOG::QueryHelpContext
  948. SYNOPSIS: Get the help context of the dialog
  949. ENTRY:
  950. EXIT:
  951. RETURNS: Returns the help context
  952. NOTES:
  953. HISTORY:
  954. Yi-HsinS 8/25/91 Created
  955. ********************************************************************/
  956. ULONG CURRENT_USERS_WARNING_DIALOG::QueryHelpContext( VOID )
  957. {
  958. return _ulHelpContextBase + HC_CURRENTUSERSWARNING;
  959. }
  960. /*******************************************************************
  961. NAME: USERS_LISTBOX::USERS_LISTBOX
  962. SYNOPSIS: Constructor - list box used in CURRENT_USERS_WARNING_DIALOG
  963. ENTRY: powin - owner window
  964. cid - resource id of the listbox
  965. EXIT:
  966. RETURNS:
  967. NOTES: This is a read-only listbox.
  968. HISTORY:
  969. Yi-HsinS 1/21/92 Created
  970. ********************************************************************/
  971. USERS_LISTBOX::USERS_LISTBOX( OWNER_WINDOW *powin, CID cid )
  972. : BLT_LISTBOX( powin, cid, TRUE ) // ReadOnly Listbox
  973. {
  974. if ( QueryError() != NERR_Success )
  975. return;
  976. APIERR err;
  977. if ( (err = DISPLAY_TABLE::CalcColumnWidths( _adx, 3, powin, cid, FALSE))
  978. != NERR_Success )
  979. {
  980. ReportError( err );
  981. return;
  982. }
  983. }
  984. /*******************************************************************
  985. NAME: USERS_LBI::USERS_LBI
  986. SYNOPSIS: List box items used in CURRENT_USERS_WARNING_DIALOG
  987. ENTRY: c1 - connection_info_1 returned by NetConnectionEnum
  988. EXIT:
  989. RETURNS:
  990. NOTES:
  991. HISTORY:
  992. Yi-HsinS 8/25/91 Created
  993. ********************************************************************/
  994. USERS_LBI::USERS_LBI( const CONN1_ENUM_OBJ &c1 )
  995. : _nlsUserName( c1.QueryUserName() ),
  996. _usNumOpens( c1.QueryNumOpens() ),
  997. _ulTime( c1.QueryTime() )
  998. {
  999. if ( QueryError() != NERR_Success )
  1000. return;
  1001. APIERR err;
  1002. if ( ( err = _nlsUserName.QueryError()) != NERR_Success )
  1003. {
  1004. ReportError( err );
  1005. return;
  1006. }
  1007. }
  1008. /*******************************************************************
  1009. NAME: USERS_LBI::~USERS_LBI
  1010. SYNOPSIS: Destructor
  1011. ENTRY:
  1012. EXIT:
  1013. RETURNS:
  1014. NOTES:
  1015. HISTORY:
  1016. Yi-HsinS 8/25/91 Created
  1017. ********************************************************************/
  1018. USERS_LBI::~USERS_LBI()
  1019. {
  1020. }
  1021. /*******************************************************************
  1022. NAME: USERS_LBI::Paint
  1023. SYNOPSIS: Redefine Paint() method of LBI class
  1024. ENTRY:
  1025. EXIT:
  1026. RETURNS:
  1027. NOTES:
  1028. HISTORY:
  1029. Yi-HsinS 8/25/91 Created
  1030. beng 6-Apr-1992 Removed wsprintf
  1031. beng 22-Apr-1992 Change to LBI::Paint
  1032. ********************************************************************/
  1033. VOID USERS_LBI::Paint( LISTBOX *plb,
  1034. HDC hdc,
  1035. const RECT *prect,
  1036. GUILTT_INFO *pGUILTT ) const
  1037. {
  1038. APIERR err;
  1039. DEC_STR nlsNumOpens( _usNumOpens );
  1040. NLS_STR nlsTime;
  1041. if ( ((err = nlsNumOpens.QueryError()) != NERR_Success )
  1042. || ((err = nlsTime.QueryError()) != NERR_Success )
  1043. || ((err = ConvertTime( _ulTime, &nlsTime )) != NERR_Success )
  1044. )
  1045. {
  1046. ::MsgPopup( plb->QueryOwnerHwnd(), err);
  1047. return;
  1048. }
  1049. STR_DTE strdteUserName( _nlsUserName );
  1050. STR_DTE strdteNumOpens( nlsNumOpens );
  1051. STR_DTE strdteTime( nlsTime );
  1052. DISPLAY_TABLE dt(3, ((USERS_LISTBOX *) plb)->QueryColumnWidths() );
  1053. dt[0] = &strdteUserName;
  1054. dt[1] = &strdteNumOpens;
  1055. dt[2] = &strdteTime;
  1056. dt.Paint( plb, hdc, prect, pGUILTT );
  1057. }
  1058. /*******************************************************************
  1059. NAME: USERS_LBI::ConvertTime
  1060. SYNOPSIS: Convert the time given from ULONG (seconds) to a string
  1061. to be shown. It complies with the internationalization
  1062. of time using INTL_PROFILE.
  1063. ENTRY:
  1064. EXIT:
  1065. RETURNS:
  1066. NOTES:
  1067. HISTORY:
  1068. Yi-HsinS 8/25/91 Created
  1069. ********************************************************************/
  1070. #define SECONDS_PER_DAY 86400
  1071. #define SECONDS_PER_HOUR 3600
  1072. #define SECONDS_PER_MINUTE 60
  1073. APIERR USERS_LBI::ConvertTime( ULONG ulTime, NLS_STR *pnlsTime) const
  1074. {
  1075. INTL_PROFILE intlProf;
  1076. INT nDay = (INT) ulTime / SECONDS_PER_DAY;
  1077. ulTime %= SECONDS_PER_DAY;
  1078. INT nHour = (INT) ulTime / SECONDS_PER_HOUR;
  1079. ulTime %= SECONDS_PER_HOUR;
  1080. INT nMinute = (INT) ulTime / SECONDS_PER_MINUTE;
  1081. INT nSecond = (INT) ulTime % SECONDS_PER_MINUTE;
  1082. return intlProf.QueryDurationStr( nDay, nHour, nMinute,
  1083. nSecond, pnlsTime);
  1084. }
  1085. /*******************************************************************
  1086. NAME: USERS_LBI::Compare
  1087. SYNOPSIS: Redefine Compare() method of LBI class
  1088. ENTRY:
  1089. EXIT:
  1090. RETURNS:
  1091. NOTES:
  1092. HISTORY:
  1093. Yi-HsinS 8/25/91 Created
  1094. ********************************************************************/
  1095. INT USERS_LBI::Compare( const LBI *plbi ) const
  1096. {
  1097. return( _nlsUserName._stricmp( ((const USERS_LBI *) plbi)->_nlsUserName ));
  1098. }