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.

660 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /**********************************************************************/
  5. /*
  6. fmx.cxx
  7. This file contains the FMExtensionProc. All code that interfaces with
  8. the file manager lives in this module
  9. FILE HISTORY:
  10. NarenG 11/23/92 Created.
  11. */
  12. #define INCL_WINDOWS
  13. #define INCL_WINDOWS_GDI
  14. #define INCL_DOSERRORS
  15. #define INCL_NETERRORS
  16. #define INCL_NETSERVICE
  17. #define INCL_NETLIB
  18. #define INCL_NETACCESS
  19. #define INCL_NETUSE
  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. #define INCL_BLT_SPIN_GROUP
  28. #define INCL_BLT_GROUP
  29. #include <blt.hxx>
  30. #include <uiassert.hxx>
  31. #include <dbgstr.hxx>
  32. #include <lmoloc.hxx>
  33. #include <netname.hxx>
  34. extern "C"
  35. {
  36. #include <wfext.h>
  37. #include <macfile.h>
  38. #include <afpmgr.h>
  39. }
  40. #include <lmsvc.hxx>
  41. #include <fmx.hxx>
  42. #include <startafp.hxx>
  43. #include <newvol.hxx>
  44. #include <voledit.hxx>
  45. #include <voldel.hxx>
  46. #include <assoc.hxx>
  47. #include <perms.hxx>
  48. extern "C"
  49. {
  50. //
  51. // Globals.
  52. //
  53. extern HINSTANCE _hInstance;// Exported by the afpmgr.cxx module.
  54. static HWND _hWnd; // Handle to the owner window.
  55. static DWORD _dwDelta; // Used to manipulate menu items.
  56. static HMENU _hMenu; // Created at load time.
  57. EXT_BUTTON aExtButton[] = { IDM_VOLUME_CREATE, 0, 0,
  58. IDM_VOLUME_DELETE, 0, 0,
  59. IDM_DIRECTORY_PERMISSIONS, 0, 0
  60. };
  61. } // extern "C"
  62. /*******************************************************************
  63. NAME: GetCurrentFocus
  64. SYNOPSIS: Will retrieve the current selection.
  65. ENTRY:
  66. EXIT: pnlsServerName - Will point to a server name if it is not
  67. local.
  68. pnlsPath - Will point to the path as returned by
  69. filemgr.
  70. pnlsLocalPath - Will point to the local path if pnlsPath
  71. was a remote drive, otherwise it will
  72. be the same as pnlsPath.
  73. pfIsFile - Indicates if the current selection is
  74. a file or not.
  75. RETURNS:
  76. NOTES:
  77. HISTORY:
  78. NarenG 11/23/92 Created.
  79. ********************************************************************/
  80. APIERR GetCurrentFocus( NLS_STR * pnlsServerName,
  81. NLS_STR * pnlsPath,
  82. NLS_STR * pnlsLocalPath,
  83. BOOL * pfIsFile )
  84. {
  85. APIERR err;
  86. //
  87. // Get the current selection
  88. //
  89. if ( err = ::GetSelItem( _hWnd, pnlsPath, FALSE, pfIsFile ))
  90. {
  91. return err;
  92. }
  93. NET_NAME NetName( pnlsPath->QueryPch() );
  94. if ( ( err = NetName.QueryError() ) != NERR_Success )
  95. {
  96. return err;
  97. }
  98. BOOL fIsLocal = NetName.IsLocal( &err );
  99. if ( err != NERR_Success )
  100. {
  101. return err;
  102. }
  103. if ( fIsLocal )
  104. {
  105. pnlsLocalPath->CopyFrom( *pnlsPath );
  106. }
  107. else
  108. {
  109. if ( ( err = NetName.QueryLocalPath( pnlsLocalPath ) ) != NERR_Success )
  110. {
  111. return err;
  112. }
  113. }
  114. //
  115. // Get the server name to connect to.
  116. //
  117. if (( err = NetName.QueryComputerName(pnlsServerName)) != NERR_Success)
  118. {
  119. return err;
  120. }
  121. return NERR_Success;
  122. }
  123. /*******************************************************************
  124. NAME: FMExtensionProcW
  125. SYNOPSIS: File Manager Extension Procedure
  126. ENTRY: hwnd See FMX spec for details
  127. wEvent
  128. lParam
  129. EXIT: See FMX spec for details
  130. RETURNS: See FMX spec for details
  131. NOTES:
  132. HISTORY:
  133. NarenG 11/23/92 Created.
  134. ********************************************************************/
  135. LONG /* FAR PASCAL */ FMExtensionProcW( HWND hWnd, WORD wEvent, LONG lParam )
  136. {
  137. NLS_STR nlsServerName;
  138. NLS_STR nlsPath;
  139. NLS_STR nlsLocalPath;
  140. DWORD err = NO_ERROR;
  141. BOOL fIsFile;
  142. AFP_SERVER_HANDLE hServer = NULL;
  143. UNREFERENCED( _dwDelta );
  144. FMX Fmx( hWnd );
  145. //
  146. // If this is a user event then we need to connect to the server
  147. //
  148. if ( ( wEvent == IDM_FILE_ASSOCIATE ) ||
  149. ( wEvent == IDM_VOLUME_CREATE ) ||
  150. ( wEvent == IDM_VOLUME_EDIT ) ||
  151. ( wEvent == IDM_VOLUME_DELETE ) ||
  152. ( wEvent == IDM_DIRECTORY_PERMISSIONS ) )
  153. {
  154. AUTO_CURSOR Cursor;
  155. //
  156. // Get the current focus
  157. //
  158. if ((( err = nlsServerName.QueryError() ) != NERR_Success ) ||
  159. (( err = nlsLocalPath.QueryError() ) != NERR_Success ) ||
  160. (( err = nlsPath.QueryError() ) != NERR_Success ))
  161. {
  162. ::MsgPopup( _hWnd, err );
  163. return err;
  164. }
  165. if ( Fmx.QuerySelCount() > 1 )
  166. {
  167. ::MsgPopup( _hWnd, IDS_MULTISEL_NOT_ALLOWED );
  168. return( ERROR_TOO_MANY_OPEN_FILES );
  169. }
  170. if ( (err = GetCurrentFocus( &nlsServerName,
  171. &nlsPath,
  172. &nlsLocalPath,
  173. &fIsFile ) ) != NERR_Success )
  174. {
  175. ::MsgPopup( _hWnd, err );
  176. return err;
  177. }
  178. //
  179. // Check if the server focus of the current selection is running AFP
  180. //
  181. BOOL fIsAfpRunning;
  182. if ( ( err = IsAfpServiceRunning( nlsServerName.QueryPch(),
  183. &fIsAfpRunning ) ) != NERR_Success )
  184. {
  185. if ( err == IDS_MACFILE_NOT_INSTALLED )
  186. {
  187. ::MsgPopup( _hWnd,
  188. err,
  189. MPSEV_ERROR,
  190. MP_OKCANCEL,
  191. nlsServerName.QueryPch(),
  192. MP_OK );
  193. }
  194. else
  195. {
  196. ::MsgPopup( _hWnd, err );
  197. }
  198. return err;
  199. }
  200. if ( !fIsAfpRunning )
  201. {
  202. //
  203. // Ask the user if he/she wants to start it.
  204. //
  205. if ( ::MsgPopup( hWnd,
  206. IDS_START_AFPSERVER_NOW,
  207. MPSEV_WARNING,
  208. MP_YESNO,
  209. MP_YES ) == IDYES )
  210. {
  211. //
  212. // Start the AFP Service
  213. //
  214. err = StartAfpService( hWnd, nlsServerName.QueryPch());
  215. if ( err != NERR_Success )
  216. {
  217. ::MsgPopup( _hWnd, err );
  218. return err;
  219. }
  220. }
  221. else
  222. {
  223. //
  224. // User does not want to start the AFP Service now so
  225. // simply return
  226. //
  227. return NERR_Success;
  228. }
  229. }
  230. //
  231. // Set up an RPC conenction with the server
  232. //
  233. if ( ( err = ::AfpAdminConnect( (LPWSTR)(nlsServerName.QueryPch()),
  234. &hServer ) ) != NO_ERROR )
  235. {
  236. ::MsgPopup( _hWnd, AFPERR_TO_STRINGID( err ) );
  237. return err;
  238. }
  239. }
  240. //
  241. // What does the user want to do with the server ?
  242. //
  243. switch( wEvent )
  244. {
  245. case IDM_FILE_ASSOCIATE:
  246. {
  247. FILE_ASSOCIATION_DIALOG * pfadlg = new FILE_ASSOCIATION_DIALOG(
  248. _hWnd,
  249. hServer,
  250. nlsPath.QueryPch(),
  251. fIsFile );
  252. err = ( pfadlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  253. : pfadlg->Process();
  254. delete pfadlg;
  255. break;
  256. }
  257. case IDM_VOLUME_CREATE:
  258. {
  259. NEW_VOLUME_FILEMGR_DIALOG * pnvdlg = new NEW_VOLUME_FILEMGR_DIALOG(
  260. _hWnd,
  261. nlsPath.QueryPch(),
  262. fIsFile );
  263. err = ( pnvdlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  264. : pnvdlg->Process();
  265. delete pnvdlg;
  266. break;
  267. }
  268. case IDM_VOLUME_EDIT:
  269. {
  270. VOLUME_EDIT_DIALOG * pvedlg = new VOLUME_EDIT_DIALOG(
  271. _hWnd,
  272. hServer,
  273. nlsServerName.QueryPch(),
  274. nlsLocalPath.QueryPch(),
  275. fIsFile );
  276. err = ( pvedlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  277. : pvedlg->Process();
  278. delete pvedlg;
  279. break;
  280. }
  281. case IDM_VOLUME_DELETE:
  282. {
  283. VOLUME_DELETE_DIALOG * pvddlg = new VOLUME_DELETE_DIALOG(
  284. _hWnd,
  285. hServer,
  286. nlsServerName.QueryPch(),
  287. nlsLocalPath.QueryPch(),
  288. fIsFile );
  289. err = ( pvddlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  290. : pvddlg->Process();
  291. delete pvddlg;
  292. break;
  293. }
  294. case IDM_DIRECTORY_PERMISSIONS:
  295. {
  296. if ( fIsFile )
  297. {
  298. ::MsgPopup( _hWnd, IDS_MUST_BE_VALID_DIR );
  299. return NO_ERROR;
  300. }
  301. DIRECTORY_PERMISSIONS_DLG * pdpdlg = new DIRECTORY_PERMISSIONS_DLG(
  302. _hWnd,
  303. hServer,
  304. nlsServerName.QueryPch(),
  305. FALSE,
  306. nlsLocalPath.QueryPch(),
  307. nlsPath.QueryPch() );
  308. err = ( pdpdlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  309. : pdpdlg->Process();
  310. delete pdpdlg;
  311. break;
  312. }
  313. case IDM_AFPMGR_HELP:
  314. {
  315. RESOURCE_STR nlsHelpFile( IDS_AFPMGR_HELPFILENAME );
  316. if ( err = nlsHelpFile.QueryError() )
  317. {
  318. break;
  319. }
  320. ::WinHelp( _hWnd, nlsHelpFile, HELP_FINDER, HC_FILE_MANAGER_CONTENTS );
  321. break;
  322. }
  323. case FMEVENT_LOAD:
  324. {
  325. //
  326. // The file manager is ANSI only, so we need to MAP appropriately
  327. //
  328. FMS_LOAD * pfmsload = (FMS_LOAD *)lParam;
  329. //
  330. // Save the handle to the owner window
  331. //
  332. _hWnd = hWnd;
  333. _dwDelta = pfmsload->wMenuDelta;
  334. pfmsload->dwSize = sizeof( FMS_LOAD );
  335. RESOURCE_STR nlsMenuName( IDS_AFPMGR_MENU_NAME );
  336. if ( nlsMenuName.QueryError() != NERR_Success )
  337. {
  338. return FALSE; // failed to install FMX
  339. }
  340. //
  341. // MENU_TEXT_LEN is defined in wfext.h, in BYTES
  342. //
  343. if ( nlsMenuName.QueryTextSize() > sizeof(pfmsload->szMenuName) )
  344. {
  345. return FALSE; // failed to install FMX
  346. }
  347. if ( nlsMenuName.MapCopyTo(pfmsload->szMenuName,
  348. sizeof(pfmsload->szMenuName))!=NERR_Success)
  349. {
  350. return FALSE ;
  351. }
  352. //
  353. // Compute hMenu
  354. //
  355. _hMenu = ::LoadMenu(::_hInstance,MAKEINTRESOURCE(ID_FILEMGR_MENU));
  356. if ( _hMenu == NULL )
  357. {
  358. return FALSE; // failed to install FMX
  359. }
  360. pfmsload->hMenu = _hMenu;
  361. return TRUE;
  362. }
  363. case FMEVENT_INITMENU:
  364. {
  365. return 0;
  366. }
  367. case FMEVENT_UNLOAD:
  368. {
  369. _hWnd = NULL;
  370. _dwDelta = 0;
  371. return 0;
  372. }
  373. case FMEVENT_TOOLBARLOAD:
  374. {
  375. FMS_TOOLBARLOAD * pfmstoolbarload = (FMS_TOOLBARLOAD *)lParam;
  376. pfmstoolbarload->dwSize = sizeof(FMS_TOOLBARLOAD) ;
  377. pfmstoolbarload->lpButtons = aExtButton ;
  378. pfmstoolbarload->cButtons = 3;
  379. pfmstoolbarload->cBitmaps = 3;
  380. pfmstoolbarload->idBitmap = IDBM_AFP_TOOLBAR;
  381. pfmstoolbarload->hBitmap = NULL ;
  382. return TRUE;
  383. }
  384. case FMEVENT_HELPSTRING:
  385. {
  386. FMS_HELPSTRING * pfmshelp = (FMS_HELPSTRING *) lParam ;
  387. MSGID msgHelp ;
  388. switch ( pfmshelp->idCommand )
  389. {
  390. case IDM_FILE_ASSOCIATE:
  391. {
  392. msgHelp = IDS_FM_HELP_ASSOCIATE;
  393. break;
  394. }
  395. case IDM_VOLUME_CREATE:
  396. {
  397. msgHelp = IDS_FM_HELP_CREATE_VOLUME;
  398. break;
  399. }
  400. case IDM_VOLUME_EDIT:
  401. {
  402. msgHelp = IDS_FM_HELP_EDIT_VOLUMES;
  403. break;
  404. }
  405. case IDM_VOLUME_DELETE:
  406. {
  407. msgHelp = IDS_FM_HELP_DELETE_VOLUMES;
  408. break;
  409. }
  410. case IDM_DIRECTORY_PERMISSIONS:
  411. {
  412. msgHelp = IDS_FM_HELP_PERMISSIONS;
  413. break;
  414. }
  415. case IDM_AFPMGR_HELP:
  416. {
  417. msgHelp = IDS_FM_HELP_HELP;
  418. break;
  419. }
  420. default:
  421. {
  422. msgHelp = IDS_FM_SFM;
  423. break;
  424. }
  425. }
  426. RESOURCE_STR nlsHelp( msgHelp );
  427. if ( !nlsHelp.QueryError() )
  428. {
  429. (void) nlsHelp.MapCopyTo( pfmshelp->szHelp,
  430. sizeof( pfmshelp->szHelp )) ;
  431. }
  432. break;
  433. }
  434. //
  435. // Somebody's pressed F1 on the security menu item selection
  436. //
  437. case FMEVENT_HELPMENUITEM:
  438. {
  439. err = NERR_Success;
  440. RESOURCE_STR nlsHelpFile( IDS_AFPMGR_HELPFILENAME );
  441. if ( err = nlsHelpFile.QueryError() )
  442. {
  443. break;
  444. }
  445. ULONG hc;
  446. switch ( lParam )
  447. {
  448. case IDM_FILE_ASSOCIATE:
  449. {
  450. hc = HC_SFMSERVER_ASSOCIATE;
  451. break;
  452. }
  453. case IDM_VOLUME_CREATE:
  454. {
  455. hc = HC_SFMSERVER_CREATE_VOLUME;
  456. break;
  457. }
  458. case IDM_VOLUME_EDIT:
  459. {
  460. hc = HC_SFMSERVER_EDIT_VOLUMES;
  461. break;
  462. }
  463. case IDM_VOLUME_DELETE:
  464. {
  465. hc = HC_SFMSERVER_REMOVE_VOLUME;
  466. break;
  467. }
  468. case IDM_DIRECTORY_PERMISSIONS:
  469. {
  470. hc = HC_SFMSERVER_PERMISSIONS;
  471. break;
  472. }
  473. default:
  474. {
  475. hc = HC_FILE_MANAGER_CONTENTS;
  476. break;
  477. }
  478. }
  479. ::WinHelp( _hWnd, nlsHelpFile, HELP_CONTEXT, hc );
  480. break;
  481. }
  482. default:
  483. {
  484. return 0;
  485. }
  486. }
  487. if ( ( err != NO_ERROR ) && ( err != ERROR_ALREADY_REPORTED ) )
  488. {
  489. ::MsgPopup( _hWnd, AFPERR_TO_STRINGID( err ) );
  490. }
  491. if ( hServer != NULL )
  492. {
  493. ::AfpAdminDisconnect( hServer );
  494. }
  495. return err;
  496. } // FMExtensionProcW
  497.