Leaked source code of windows server 2003
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.

651 lines
17 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : CoverPage.cpp //
  3. // //
  4. // DESCRIPTION : Implementation of the cover page result node. //
  5. // //
  6. // AUTHOR : yossg //
  7. // //
  8. // HISTORY : //
  9. // Feb 9 2000 yossg Create //
  10. // Oct 17 2000 yossg //
  11. // //
  12. // Copyright (C) 2000 Microsoft Corporation All Rights Reserved //
  13. /////////////////////////////////////////////////////////////////////////////
  14. #include "StdAfx.h"
  15. #include "snapin.h"
  16. #include "CoverPage.h"
  17. #include "CoverPages.h"
  18. #include "FaxServer.h"
  19. #include "FaxServerNode.h"
  20. #include "FaxMMCPropertyChange.h"
  21. #include "oaidl.h"
  22. #include "urlmon.h"
  23. #include "mshtmhst.h"
  24. #include "exdisp.h"
  25. #include <windows.h>
  26. #include <shlwapi.h>
  27. #include <faxreg.h>
  28. /////////////////////////////////////////////////////////////////////////////
  29. // {D0F52487-3C98-4d1a-AF15-4033900DCCDC}
  30. static const GUID CFaxCoverPageNodeGUID_NODETYPE =
  31. { 0xd0f52487, 0x3c98, 0x4d1a, { 0xaf, 0x15, 0x40, 0x33, 0x90, 0xd, 0xcc, 0xdc } };
  32. const GUID* CFaxCoverPageNode::m_NODETYPE = &CFaxCoverPageNodeGUID_NODETYPE;
  33. const OLECHAR* CFaxCoverPageNode::m_SZNODETYPE = OLESTR("D0F52487-3C98-4d1a-AF15-4033900DCCDC");
  34. //const OLECHAR* CnotImplemented::m_SZDISPLAY_NAME = OLESTR("Cover Pages");
  35. const CLSID* CFaxCoverPageNode::m_SNAPIN_CLASSID = &CLSID_Snapin;
  36. /*
  37. - CFaxCoverPageNode::Init
  38. -
  39. * Purpose:
  40. * Init all members icon etc.
  41. *
  42. * Arguments:
  43. * [in] pRuleConfig - PFAX_OUTBOUND_ROUTING_RULE
  44. *
  45. * Return:
  46. * OLE error code
  47. */
  48. HRESULT CFaxCoverPageNode::Init(WIN32_FIND_DATA * pCoverPageData)
  49. {
  50. DEBUG_FUNCTION_NAME( _T("CFaxCoverPageNode::Init"));
  51. DWORD ec = ERROR_SUCCESS;
  52. _FILETIME FileTime;
  53. SYSTEMTIME SystemTime;
  54. TCHAR szLastModifiedTimeStr[MAX_PATH+1];
  55. TCHAR szDateBuf[MAX_PATH+1];
  56. ULARGE_INTEGER uliFileSize;
  57. CHAR szFileSize[MAX_PATH+1];
  58. CComBSTR bstrDate;
  59. CComBSTR bstrTime;
  60. ATLASSERT(pCoverPageData);
  61. m_bstrDisplayName = pCoverPageData->cFileName;
  62. if (!m_bstrDisplayName)
  63. {
  64. ec = ERROR_NOT_ENOUGH_MEMORY;
  65. DebugPrintEx( DEBUG_ERR,
  66. _T("Null m_bstrDisplayName - out of memory."));
  67. goto Error;
  68. }
  69. //
  70. // Last Modified
  71. //
  72. if (!FileTimeToLocalFileTime(
  73. &pCoverPageData->ftLastWriteTime,
  74. &FileTime
  75. )
  76. )
  77. {
  78. ec = GetLastError();
  79. DebugPrintEx(
  80. DEBUG_ERR,
  81. _T("Fail to convert LocalTimeToFileTime. (ec: %ld)"),
  82. ec);
  83. goto Error;
  84. }
  85. if (!FileTimeToSystemTime(
  86. &FileTime,
  87. &SystemTime)
  88. )
  89. {
  90. ec = GetLastError();
  91. DebugPrintEx(
  92. DEBUG_ERR,
  93. _T("Fail to convert FileTimeToSystemTime. (ec: %ld)"),
  94. ec);
  95. goto Error;
  96. }
  97. //
  98. // a. Create a string specifying the date
  99. //
  100. if (!GetY2KCompliantDate (LOCALE_USER_DEFAULT, // Get user's locale
  101. DATE_SHORTDATE, // Short date format
  102. &SystemTime, // Source date/time
  103. szDateBuf, // Output buffer
  104. sizeof(szDateBuf)/ sizeof(szDateBuf[0]) // MAX_PATH Output buffer size
  105. ))
  106. {
  107. ec = GetLastError();
  108. DebugPrintEx(
  109. DEBUG_ERR,
  110. _T("Fail to GetY2KCompliantDate. (ec: %ld)"),
  111. ec);
  112. goto Error;
  113. }
  114. else
  115. {
  116. bstrDate = szDateBuf;
  117. if (!bstrDate)
  118. {
  119. ec = ERROR_NOT_ENOUGH_MEMORY;
  120. DebugPrintEx( DEBUG_ERR,
  121. _T("empty m_bstrTimeFormated - out of memory."));
  122. goto Error;
  123. }
  124. }
  125. //
  126. // b. Create a string specifying the time
  127. //
  128. if (!FaxTimeFormat(
  129. LOCALE_USER_DEFAULT, //Locale
  130. TIME_NOSECONDS, //dwFlags options
  131. &SystemTime, //CONST SYSTEMTIME time
  132. NULL, //LPCTSTR lpFormat time format string
  133. szLastModifiedTimeStr, //formatted string buffer
  134. sizeof(szLastModifiedTimeStr)/ sizeof(szLastModifiedTimeStr[0])// MAX_PATH// size of string buffer
  135. )
  136. )
  137. {
  138. ec = GetLastError();
  139. DebugPrintEx(
  140. DEBUG_ERR,
  141. _T("Fail to FaxTimeFormat. (ec: %ld)"),
  142. ec);
  143. goto Error;
  144. }
  145. else
  146. {
  147. bstrTime = szLastModifiedTimeStr;
  148. if (!bstrTime)
  149. {
  150. ec = ERROR_NOT_ENOUGH_MEMORY;
  151. DebugPrintEx( DEBUG_ERR,
  152. _T("empty m_bstrTimeFormated - out of memory."));
  153. goto Error;
  154. }
  155. }
  156. m_bstrTimeFormatted = bstrDate;
  157. m_bstrTimeFormatted += L" ";
  158. m_bstrTimeFormatted += bstrTime;
  159. //
  160. // Size
  161. //
  162. uliFileSize.LowPart = pCoverPageData->nFileSizeLow;
  163. uliFileSize.HighPart = pCoverPageData->nFileSizeHigh;
  164. if (!StrFormatByteSize64A(
  165. (LONGLONG) uliFileSize.QuadPart,
  166. szFileSize,
  167. sizeof(szFileSize)/ sizeof(szFileSize[0])
  168. )
  169. )
  170. {
  171. ec = GetLastError();
  172. DebugPrintEx(
  173. DEBUG_ERR,
  174. _T("Fail to convert FileTimeToSystemTime. (ec: %ld)"),
  175. ec);
  176. goto Error;
  177. }
  178. else
  179. {
  180. m_bstrFileSize = szFileSize;
  181. }
  182. //
  183. // Icon
  184. //
  185. m_resultDataItem.nImage = IMAGE_SRV_COVERPAGE;
  186. ATLASSERT(ERROR_SUCCESS == ec);
  187. goto Exit;
  188. Error:
  189. ATLASSERT(ERROR_SUCCESS != ec);
  190. DebugPrintEx(
  191. DEBUG_ERR,
  192. _T("Failed to init members"));
  193. ATLASSERT(NULL != m_pParentNode);
  194. if (NULL != m_pParentNode)
  195. {
  196. m_pParentNode->NodeMsgBox(IDS_FAIL2INIT_COVERPAGE_DATA);
  197. }
  198. return HRESULT_FROM_WIN32(ec);
  199. Exit:
  200. return S_OK;
  201. }
  202. /*
  203. - CFaxCoverPageNode::GetResultPaneColInfo
  204. -
  205. * Purpose:
  206. * Return the text for specific column
  207. * Called for each column in the result pane
  208. *
  209. * Arguments:
  210. * [in] nCol - column number
  211. *
  212. * Return:
  213. * String to be displayed in the specific column
  214. */
  215. LPOLESTR CFaxCoverPageNode::GetResultPaneColInfo(int nCol)
  216. {
  217. DEBUG_FUNCTION_NAME( _T("CFaxCoverPageNode::GetResultPaneColInfo"));
  218. HRESULT hRc = S_OK;
  219. switch (nCol)
  220. {
  221. case 0:
  222. //
  223. // Cover page file Name
  224. //
  225. if (!m_bstrDisplayName)
  226. {
  227. DebugPrintEx(
  228. DEBUG_ERR,
  229. TEXT("Null memeber BSTR - m_bstrDisplayName."));
  230. goto Error;
  231. }
  232. else
  233. {
  234. return (m_bstrDisplayName);
  235. }
  236. case 1:
  237. //
  238. // Cover page Last Modified
  239. //
  240. if (!m_bstrTimeFormatted)
  241. {
  242. DebugPrintEx(
  243. DEBUG_ERR,
  244. TEXT("Null memeber BSTR - m_bstrTimeFormatted."));
  245. goto Error;
  246. }
  247. else
  248. {
  249. return (m_bstrTimeFormatted);
  250. }
  251. case 2:
  252. //
  253. // Cover page file size
  254. //
  255. if (!m_bstrFileSize)
  256. {
  257. DebugPrintEx(
  258. DEBUG_ERR,
  259. _T("Null memeber BSTR - m_bstrFileSize."));
  260. goto Error;
  261. }
  262. else
  263. {
  264. return (m_bstrFileSize);
  265. }
  266. default:
  267. ATLASSERT(0); // "this number of column is not supported "
  268. return(L"");
  269. } // endswitch (nCol)
  270. Error:
  271. return(L"???");
  272. }
  273. /*
  274. - CFaxCoverPageNode::SetVerbs
  275. -
  276. * Purpose:
  277. * What verbs to enable/disable when this object is selected
  278. *
  279. * Arguments:
  280. * [in] pConsoleVerb - MMC ConsoleVerb interface
  281. *
  282. * Return:
  283. * OLE Error code
  284. */
  285. HRESULT CFaxCoverPageNode::SetVerbs(IConsoleVerb *pConsoleVerb)
  286. {
  287. HRESULT hRc = S_OK;
  288. //
  289. // Display verbs that we support:
  290. // 1. Delete
  291. //
  292. hRc = pConsoleVerb->SetVerbState(MMC_VERB_DELETE, ENABLED, TRUE);
  293. //
  294. // No default verb
  295. //
  296. hRc = pConsoleVerb->SetDefaultVerb(MMC_VERB_NONE);
  297. return hRc;
  298. }
  299. HRESULT CFaxCoverPageNode::OnDoubleClick(
  300. LPARAM arg
  301. , LPARAM param
  302. , IComponentData * pComponentData
  303. , IComponent * pComponent
  304. , DATA_OBJECT_TYPES type
  305. )
  306. {
  307. UNREFERENCED_PARAMETER (arg);
  308. UNREFERENCED_PARAMETER (param);
  309. UNREFERENCED_PARAMETER (pComponentData);
  310. UNREFERENCED_PARAMETER (pComponent);
  311. UNREFERENCED_PARAMETER (type);
  312. DEBUG_FUNCTION_NAME(
  313. _T("CFaxCoverPageNode::::OnDoubleClick -->> Edit CoverPage "));
  314. HRESULT hRc = S_OK;
  315. bool bTemp = true; //UNREFERENCED_PARAMETER
  316. CSnapInObjectRootBase * pRootTemp = NULL; //UNREFERENCED_PARAMETER
  317. hRc = OnEditCoverPage(bTemp, pRootTemp);
  318. if ( S_OK != hRc )
  319. {
  320. DebugPrintEx(
  321. DEBUG_ERR,
  322. _T("Fail to call OnEditCoverPage(). (hRc : %08X)"),
  323. hRc);
  324. //msgbox by called func.
  325. }
  326. // Maguire wrote in his code:
  327. // "Through speaking with Eugene Baucom, I discovered that if you return S_FALSE
  328. // here, the default verb action will occur when the user double clicks on a node.
  329. // For the most part we have Properties as default verb, so a double click
  330. // will cause property sheet on a node to pop up."
  331. //
  332. // Hence we return S_OK in any case for now
  333. return S_OK;
  334. }
  335. /*
  336. - CFaxCoverPageNode::OnDelete
  337. -
  338. * Purpose:
  339. * Called when deleting this node
  340. *
  341. * Arguments:
  342. *
  343. * Return:
  344. * OLE error code
  345. */
  346. HRESULT CFaxCoverPageNode::OnDelete(
  347. LPARAM arg,
  348. LPARAM param,
  349. IComponentData *pComponentData,
  350. IComponent *pComponent,
  351. DATA_OBJECT_TYPES type,
  352. BOOL fSilent/* = FALSE*/
  353. )
  354. {
  355. DEBUG_FUNCTION_NAME( _T("CFaxCoverPageNode::OnDelete"));
  356. UNREFERENCED_PARAMETER (arg);
  357. UNREFERENCED_PARAMETER (param);
  358. UNREFERENCED_PARAMETER (pComponentData);
  359. UNREFERENCED_PARAMETER (pComponent);
  360. UNREFERENCED_PARAMETER (type);
  361. HRESULT hRc = S_OK;
  362. DWORD ec = ERROR_SUCCESS;
  363. WCHAR pszCovDir[MAX_PATH+1];
  364. CComBSTR bstrFullPath;
  365. CComBSTR bstrServerName;
  366. //
  367. // Are you sure?
  368. //
  369. if (! fSilent)
  370. {
  371. //
  372. // 1. Use pConsole as owner of the message box
  373. //
  374. int res;
  375. NodeMsgBox(IDS_CONFIRM, MB_YESNO | MB_ICONWARNING, &res);
  376. if (IDNO == res)
  377. {
  378. goto Exit;
  379. }
  380. }
  381. //
  382. // Prepere the file name to delete
  383. //
  384. bstrServerName = ((CFaxServerNode *)GetRootNode())->GetServerName();
  385. if (!bstrServerName)
  386. {
  387. DebugPrintEx(DEBUG_ERR, TEXT("Out of memory. Failed to get server name."));
  388. hRc = E_OUTOFMEMORY;
  389. goto Error;
  390. }
  391. if(!GetServerCpDir(bstrServerName,
  392. pszCovDir,
  393. sizeof(pszCovDir)/sizeof(pszCovDir[0])))
  394. {
  395. ec = GetLastError();
  396. DebugPrintEx(
  397. DEBUG_ERR,
  398. _T("Failed to get Server Cover-Page Dir. (ec : %ld)"), ec);
  399. hRc = HRESULT_FROM_WIN32(ec);
  400. goto Error;
  401. }
  402. bstrFullPath = pszCovDir;
  403. if (!bstrFullPath)
  404. {
  405. hRc = E_OUTOFMEMORY;
  406. DebugPrintEx(
  407. DEBUG_ERR,
  408. _T("Failed to allocate string - out of memory"));
  409. goto Error;
  410. }
  411. bstrFullPath += FAX_PATH_SEPARATOR_STR;
  412. bstrFullPath += m_bstrDisplayName;
  413. //
  414. // Delete - done by parent node
  415. //
  416. hRc = m_pParentNode->DeleteCoverPage(bstrFullPath, this);
  417. if ( FAILED(hRc) )
  418. {
  419. DebugPrintEx(
  420. DEBUG_ERR,
  421. _T("Failed to delete cover page"));
  422. goto Error;
  423. }
  424. ATLASSERT(S_OK == hRc);
  425. goto Exit;
  426. Error:
  427. ATLASSERT(S_OK != hRc);
  428. NodeMsgBox(IDS_FAIL2DELETE_COV);
  429. Exit:
  430. return hRc;
  431. }
  432. /*
  433. - CFaxCoverPageNode::OnEditCoverPage
  434. -
  435. * Purpose:
  436. *
  437. *
  438. * Arguments:
  439. * [out] bHandled - Do we handle it?
  440. * [in] pRoot - The root node
  441. *
  442. * Return:
  443. * OLE Error code
  444. */
  445. HRESULT
  446. CFaxCoverPageNode::OnEditCoverPage(bool &bHandled, CSnapInObjectRootBase *pRoot)
  447. {
  448. DEBUG_FUNCTION_NAME( _T("CFaxCoverPageNode::OnEditCoverPage"));
  449. UNREFERENCED_PARAMETER (pRoot);
  450. UNREFERENCED_PARAMETER (bHandled);
  451. DWORD ec = ERROR_SUCCESS;
  452. TCHAR tszServerCPDir[MAX_PATH * 4];
  453. TCHAR tszQuotedFullCPFilePath[MAX_PATH * 4];
  454. if(!IsFaxComponentInstalled(FAX_COMPONENT_CPE))
  455. {
  456. return S_OK;
  457. }
  458. ATLASSERT(m_pParentNode);
  459. //
  460. // Prepare the filename of the cover page
  461. // Step1: Get full path
  462. //
  463. CComBSTR bstrServerName = ((CFaxServerNode *)GetRootNode())->GetServerName();
  464. if (!bstrServerName)
  465. {
  466. DebugPrintEx(DEBUG_ERR, TEXT("Out of memory. Failed to get server name."));
  467. NodeMsgBox(IDS_MEMORY);
  468. return E_OUTOFMEMORY;
  469. }
  470. if (!GetServerCpDir (bstrServerName, tszServerCPDir, ARR_SIZE (tszServerCPDir)))
  471. {
  472. ec = GetLastError ();
  473. DebugPrintEx(DEBUG_ERR, _T("Error %ld when calling GetServerCpDir"), ec);
  474. NodeMsgBox(IDS_MEMORY);
  475. return HRESULT_FROM_WIN32(ec);
  476. }
  477. //
  478. // To avoid problems with space included file names like: "My Cover Page.cov"
  479. //
  480. if (0 >= wnsprintf (tszQuotedFullCPFilePath,
  481. ARR_SIZE (tszQuotedFullCPFilePath),
  482. TEXT("\"%s\\%s\""),
  483. tszServerCPDir,
  484. m_bstrDisplayName))
  485. {
  486. ec = ERROR_BUFFER_OVERFLOW;
  487. DebugPrintEx(DEBUG_ERR, _T("Error %ld when calling wnsprintf"), ec);
  488. NodeMsgBox(IDS_MEMORY);
  489. return HRESULT_FROM_WIN32(ec);
  490. }
  491. //
  492. // Open cover page editor
  493. //
  494. ec = m_pParentNode->OpenCoverPageEditor(CComBSTR(tszQuotedFullCPFilePath));
  495. if (ERROR_SUCCESS != ec)
  496. {
  497. DebugPrintEx(
  498. DEBUG_ERR,
  499. _T("Fail to OpenCoverPageEditor. (ec : %ld)"), ec);
  500. return HRESULT_FROM_WIN32( ec );
  501. }
  502. return S_OK;
  503. }
  504. /*
  505. +
  506. + CFaxCoverPageNode::OnShowContextHelp
  507. *
  508. * Purpose:
  509. * Overrides CSnapinNode::OnShowContextHelp.
  510. *
  511. * Arguments:
  512. *
  513. * Return:
  514. - OLE error code
  515. -
  516. */
  517. HRESULT CFaxCoverPageNode::OnShowContextHelp(
  518. IDisplayHelp* pDisplayHelp, LPOLESTR helpFile)
  519. {
  520. return DisplayContextHelp(pDisplayHelp, helpFile, HLP_COVER_PAGES);
  521. }
  522. /*
  523. - CFaxCoverPageNode::UpdateMenuState
  524. -
  525. * Purpose:
  526. * Overrides the ATL CSnapInItemImpl::UpdateMenuState
  527. * which only have one line inside it "return;"
  528. * This function implements the grayed\ungrayed view for the
  529. * the Enable and the Disable menus.
  530. *
  531. * Arguments:
  532. * [in] id - unsigned int with the menu IDM value
  533. * [out] pBuf - string
  534. * [out] flags - pointer to flags state combination unsigned int
  535. *
  536. * Return:
  537. * no return value - void function
  538. */
  539. void CFaxCoverPageNode::UpdateMenuState(UINT id, LPTSTR pBuf, UINT *flags)
  540. {
  541. DEBUG_FUNCTION_NAME( _T("CFaxCoverPageNode::UpdateMenuState"));
  542. UNREFERENCED_PARAMETER (pBuf);
  543. switch (id)
  544. {
  545. case IDM_EDIT_COVERPAGE:
  546. *flags = IsFaxComponentInstalled(FAX_COMPONENT_CPE) ? MF_ENABLED : MF_GRAYED;
  547. break;
  548. default:
  549. break;
  550. }
  551. return;
  552. }