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.

803 lines
27 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: COMFIN.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: Transfer page. Gets the destination path and filename.
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "comfin.h"
  19. #include "simcrack.h"
  20. #include "resource.h"
  21. #include "svselfil.h"
  22. #include "simrect.h"
  23. #include "movewnd.h"
  24. #include "runnpwiz.h"
  25. #include "mboxex.h"
  26. #include <wininet.h>
  27. #define STR_LOCAL_LINK_ID TEXT("LocalLinkId")
  28. #define STR_REMOTE_LINK_ID TEXT("RemoteLinkId")
  29. #define STR_DETAILED_DOWNLOAD_ERROR_ID TEXT("DetailedDownloadErrorId")
  30. #define STR_DETAILED_UPLOAD_ERROR_ID TEXT("DetailedUploadErrorId")
  31. #define ID_FINISHBUTTON 0x3025
  32. //
  33. // Sole constructor
  34. //
  35. CCommonFinishPage::CCommonFinishPage( HWND hWnd )
  36. : m_hWnd(hWnd),
  37. m_nWiaEventMessage(RegisterWindowMessage(STR_WIAEVENT_NOTIFICATION_MESSAGE)),
  38. m_pControllerWindow(NULL),
  39. m_hBigTitleFont(NULL)
  40. {
  41. }
  42. //
  43. // Destructor
  44. //
  45. CCommonFinishPage::~CCommonFinishPage(void)
  46. {
  47. m_hWnd = NULL;
  48. m_pControllerWindow = NULL;
  49. }
  50. HRESULT CCommonFinishPage::GetManifestInfo( IXMLDOMDocument *pXMLDOMDocumentManifest, CSimpleString &strSiteName, CSimpleString &strSiteURL )
  51. {
  52. WCHAR wszSiteName[MAX_PATH] = {0};
  53. WCHAR wszSiteURL[INTERNET_MAX_URL_LENGTH] = {0};
  54. HRESULT hr;
  55. if (pXMLDOMDocumentManifest)
  56. {
  57. //
  58. // lets crack the manifest and work out whats what with the publish that
  59. // we just performed.
  60. //
  61. CComPtr<IXMLDOMNode> pXMLDOMNodeUploadInfo;
  62. hr = pXMLDOMDocumentManifest->selectSingleNode( CSimpleBStr(L"transfermanifest/uploadinfo"), &pXMLDOMNodeUploadInfo );
  63. if (S_OK == hr)
  64. {
  65. //
  66. // lets pick up the site name from the manifest, this will be an attribute on the
  67. // upload info element.
  68. //
  69. CComPtr<IXMLDOMElement> pXMLDOMElement;
  70. hr = pXMLDOMNodeUploadInfo->QueryInterface( IID_IXMLDOMElement, (void**)&pXMLDOMElement );
  71. if (SUCCEEDED(hr))
  72. {
  73. VARIANT var = {0};
  74. hr = pXMLDOMElement->getAttribute( CSimpleBStr(L"friendlyname"), &var );
  75. if (S_OK == hr)
  76. {
  77. StrCpyNW( wszSiteName, var.bstrVal, ARRAYSIZE(wszSiteName) );
  78. VariantClear(&var);
  79. }
  80. else
  81. {
  82. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMElement->getAttribute( \"friendlyname\" ) failed")));
  83. }
  84. }
  85. else
  86. {
  87. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMNodeUploadInfo->QueryInterface( IID_IXMLDOMElement ) failed on line %d"), __LINE__ ));
  88. }
  89. //
  90. // lets now try and pick up the site URL node, this is going to either
  91. // be the file target, or HTML UI element.
  92. //
  93. CComPtr<IXMLDOMNode> pXMLDOMNodeURL;
  94. hr = pXMLDOMNodeUploadInfo->selectSingleNode( CSimpleBStr(L"htmlui"), &pXMLDOMNodeURL);
  95. if (S_FALSE == hr)
  96. {
  97. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMDocumentManifest->selectSingleNode \"htmlui\" failed")));
  98. hr = pXMLDOMNodeUploadInfo->selectSingleNode( CSimpleBStr(L"netplace"), &pXMLDOMNodeURL);
  99. }
  100. if (S_FALSE == hr)
  101. {
  102. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMDocumentManifest->selectSingleNode \"target\" failed")));
  103. hr = pXMLDOMNodeUploadInfo->selectSingleNode( CSimpleBStr(L"target"), &pXMLDOMNodeURL);
  104. }
  105. if (S_OK == hr)
  106. {
  107. CComPtr<IXMLDOMElement> pXMLDOMElement;
  108. hr = pXMLDOMNodeURL->QueryInterface( IID_IXMLDOMElement, (void**)&pXMLDOMElement );
  109. if (SUCCEEDED(hr))
  110. {
  111. //
  112. // attempt to read the HREF attribute, if that is defined
  113. // the we use it, otherwise (for compatibility with B2, we need
  114. // to get the node text and use that instead).
  115. //
  116. VARIANT var = {0};
  117. hr = pXMLDOMElement->getAttribute( CSimpleBStr(L"href"), &var );
  118. if (hr != S_OK)
  119. {
  120. hr = pXMLDOMElement->get_nodeTypedValue( &var );
  121. }
  122. if (S_OK == hr)
  123. {
  124. StrCpyNW(wszSiteURL, var.bstrVal, ARRAYSIZE(wszSiteURL) );
  125. VariantClear(&var);
  126. }
  127. else
  128. {
  129. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMElement->getAttribute or pXMLDOMElement->get_nodeTypedValue failed")));
  130. }
  131. }
  132. else
  133. {
  134. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMNodeUploadInfo->QueryInterface( IID_IXMLDOMElement ) failed on line %d"), __LINE__ ));
  135. }
  136. }
  137. else
  138. {
  139. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMDocumentManifest->selectSingleNode \"target\" failed")));
  140. }
  141. }
  142. else
  143. {
  144. WIA_PRINTHRESULT((hr,TEXT("pXMLDOMDocumentManifest->selectSingleNode \"transfermanifest\\uploadinfo\" failed")));
  145. }
  146. }
  147. else
  148. {
  149. WIA_ERROR((TEXT("pXMLDOMDocumentManifest is NULL")));
  150. hr = E_INVALIDARG;
  151. }
  152. strSiteName = CSimpleStringConvert::NaturalString( CSimpleStringWide( wszSiteName ) );
  153. strSiteURL = CSimpleStringConvert::NaturalString( CSimpleStringWide( wszSiteURL ) );
  154. return hr;
  155. }
  156. LRESULT CCommonFinishPage::OnInitDialog( WPARAM, LPARAM lParam )
  157. {
  158. //
  159. // Make sure this starts out NULL
  160. //
  161. m_pControllerWindow = NULL;
  162. //
  163. // Get the PROPSHEETPAGE.lParam
  164. //
  165. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  166. if (pPropSheetPage)
  167. {
  168. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  169. if (m_pControllerWindow)
  170. {
  171. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  172. }
  173. }
  174. //
  175. // Bail out
  176. //
  177. if (!m_pControllerWindow)
  178. {
  179. EndDialog(m_hWnd,IDCANCEL);
  180. return -1;
  181. }
  182. //
  183. // Set the font size for the title
  184. //
  185. m_hBigTitleFont = WiaUiUtil::CreateFontWithPointSizeFromWindow( GetDlgItem(m_hWnd,IDC_FINISH_TITLE), 14, false, false );
  186. if (m_hBigTitleFont)
  187. {
  188. SendDlgItemMessage( m_hWnd, IDC_FINISH_TITLE, WM_SETFONT, reinterpret_cast<WPARAM>(m_hBigTitleFont), MAKELPARAM(TRUE,0));
  189. }
  190. return 0;
  191. }
  192. LRESULT CCommonFinishPage::OnWizFinish( WPARAM, LPARAM )
  193. {
  194. LRESULT nResult = FALSE;
  195. //
  196. // Open the shell folder containing the images
  197. //
  198. OpenLocalStorage();
  199. return nResult;
  200. }
  201. /*
  202. From finish page:
  203. if (error_occurred)
  204. {
  205. if (no_images)
  206. {
  207. goto SelectionPage
  208. }
  209. else
  210. {
  211. goto DestinationPage
  212. }
  213. }
  214. else
  215. {
  216. goto UploadQueryPage
  217. }
  218. */
  219. //
  220. // handler for PSN_WIZBACK
  221. //
  222. LRESULT CCommonFinishPage::OnWizBack( WPARAM, LPARAM )
  223. {
  224. //
  225. // If no errors occurred, go to the upload query page
  226. //
  227. HPROPSHEETPAGE hNextPage = NULL;
  228. if (S_OK==m_pControllerWindow->m_hrDownloadResult && !m_pControllerWindow->m_bDownloadCancelled)
  229. {
  230. hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nUploadQueryPageIndex );
  231. }
  232. else
  233. {
  234. if (m_pControllerWindow->GetSelectedImageCount())
  235. {
  236. hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nDestinationPageIndex );
  237. }
  238. else
  239. {
  240. hNextPage = PropSheet_IndexToPage( GetParent(m_hWnd), m_pControllerWindow->m_nSelectionPageIndex );
  241. }
  242. }
  243. PropSheet_SetCurSel( GetParent(m_hWnd), hNextPage, -1 );
  244. return -1;
  245. }
  246. //
  247. // handler for PSN_SETACTIVE
  248. //
  249. LRESULT CCommonFinishPage::OnSetActive( WPARAM, LPARAM )
  250. {
  251. WIA_PUSHFUNCTION(TEXT("CCommonFinishPage::OnSetActive"));
  252. //
  253. // Make sure we have a valid controller window
  254. //
  255. if (!m_pControllerWindow)
  256. {
  257. return -1;
  258. }
  259. //
  260. // Assume we are displaying a success message
  261. //
  262. int nPageTitle = IDS_FINISH_SUCCESS_TITLE;
  263. //
  264. // Assume we failed for this message
  265. //
  266. int nFinishPrompt = IDS_FINISH_PROMPT_FAILURE;
  267. //
  268. // Only disable the back button if (a) we are disconnected and (b) we hit an error or were cancelled
  269. //
  270. if (m_pControllerWindow->m_bDisconnected && (S_OK != m_pControllerWindow->m_hrDownloadResult || m_pControllerWindow->m_bDownloadCancelled))
  271. {
  272. //
  273. // Basically, this disables the Cancel button.
  274. //
  275. PropSheet_CancelToClose( GetParent(m_hWnd) );
  276. //
  277. // Change the finish button to a close button
  278. //
  279. PropSheet_SetFinishText( GetParent(m_hWnd), CSimpleString( IDS_FINISH_TO_CLOSE_TITLE, g_hInstance ).String() );
  280. //
  281. // Disable back
  282. //
  283. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_FINISH );
  284. //
  285. // Tell the user to use Close to close the wizard.
  286. //
  287. nFinishPrompt = IDS_FINISH_PROMPT_FAILURE_DISCONNECT;
  288. }
  289. else
  290. {
  291. //
  292. // Allow finish and back
  293. //
  294. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_FINISH|PSWIZB_BACK );
  295. }
  296. #if defined(DBG)
  297. //
  298. // Display statistics for debugging
  299. //
  300. WIA_TRACE((TEXT("m_pControllerWindow->m_DownloadedFileList.Size(): %d"), m_pControllerWindow->m_DownloadedFileInformationList.Size()));
  301. for (int i=0;i<m_pControllerWindow->m_DownloadedFileInformationList.Size();i++)
  302. {
  303. WIA_TRACE((TEXT(" m_pControllerWindow->m_DownloadedFileList[%d]==%s"), i, m_pControllerWindow->m_DownloadedFileInformationList[i].Filename().String()));
  304. }
  305. WIA_TRACE((TEXT("m_pControllerWindow->m_nFailedImagesCount: %d"), m_pControllerWindow->m_nFailedImagesCount ));
  306. WIA_TRACE((TEXT("m_pControllerWindow->m_strErrorMessage: %s"), m_pControllerWindow->m_strErrorMessage.String()));
  307. WIA_PRINTHRESULT((m_pControllerWindow->m_hrDownloadResult,TEXT("m_pControllerWindow->m_hrDownloadResult")));
  308. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("m_pControllerWindow->m_hrUploadResult")));
  309. WIA_PRINTHRESULT((m_pControllerWindow->m_hrDeleteResult,TEXT("m_pControllerWindow->m_hrDeleteResult")));
  310. #endif
  311. CSimpleString strStatusMessage;
  312. //
  313. // If the transfer succeeded, and the user didn't cancel
  314. //
  315. if (S_OK==m_pControllerWindow->m_hrDownloadResult && !m_pControllerWindow->m_bDownloadCancelled)
  316. {
  317. CSimpleString strSuccessfullyDownloaded;
  318. CSimpleString strSuccessfullyUploaded;
  319. CSimpleString strSuccessfullyDeleted;
  320. CSimpleString strHyperlinks;
  321. CSimpleString strLocalHyperlink;
  322. CSimpleString strRemoteHyperlink;
  323. int nSuccessCount = 0;
  324. //
  325. // If we have successfully transferred images, display the count and show the associated controls
  326. //
  327. if (m_pControllerWindow->m_DownloadedFileInformationList.Size())
  328. {
  329. //
  330. // Count up all of the "countable" files (we don't include attachments in the count)
  331. //
  332. for (int i=0;i<m_pControllerWindow->m_DownloadedFileInformationList.Size();i++)
  333. {
  334. if (m_pControllerWindow->m_DownloadedFileInformationList[i].IncludeInFileCount())
  335. {
  336. nSuccessCount++;
  337. }
  338. }
  339. //
  340. // If we had any errors while deleting images, let the user know
  341. //
  342. if (m_pControllerWindow->m_bDeletePicturesIfSuccessful && FAILED(m_pControllerWindow->m_hrDeleteResult))
  343. {
  344. strSuccessfullyDeleted.LoadString( IDS_DELETION_FAILED, g_hInstance );
  345. }
  346. //
  347. // If we uploaded to the web, set the destination text
  348. //
  349. if (m_pControllerWindow->m_bUploadToWeb)
  350. {
  351. //
  352. // If we have a valid publishing wizard, get the manifest and hresult
  353. //
  354. if (m_pControllerWindow->m_pPublishingWizard)
  355. {
  356. //
  357. // Get the transfer manifest
  358. //
  359. CComPtr<IXMLDOMDocument> pXMLDOMDocumentManifest;
  360. if (SUCCEEDED(m_pControllerWindow->m_pPublishingWizard->GetTransferManifest( &m_pControllerWindow->m_hrUploadResult, &pXMLDOMDocumentManifest )))
  361. {
  362. WIA_PRINTHRESULT((m_pControllerWindow->m_hrUploadResult,TEXT("m_pControllerWindow->m_hrUploadResult")));
  363. //
  364. // Get the destination URL and friendly name out of the manifest
  365. //
  366. CSimpleString strUploadDestination;
  367. if (S_OK==m_pControllerWindow->m_hrUploadResult && SUCCEEDED(CCommonFinishPage::GetManifestInfo( pXMLDOMDocumentManifest, strUploadDestination, m_strSiteUrl )))
  368. {
  369. //
  370. // If we have a friendly name, use it. Otherwise, use the URL
  371. //
  372. strRemoteHyperlink = strUploadDestination;
  373. if (!strRemoteHyperlink.Length())
  374. {
  375. strRemoteHyperlink = m_strSiteUrl;
  376. }
  377. }
  378. }
  379. }
  380. if (HRESULT_FROM_WIN32(ERROR_CANCELLED) == m_pControllerWindow->m_hrUploadResult)
  381. {
  382. strSuccessfullyUploaded.LoadString( IDS_FINISH_UPLOAD_CANCELLED, g_hInstance );
  383. }
  384. else if (FAILED(m_pControllerWindow->m_hrUploadResult))
  385. {
  386. strSuccessfullyUploaded.LoadString( IDS_FINISH_UPLOAD_FAILED, g_hInstance );
  387. }
  388. }
  389. if (nSuccessCount)
  390. {
  391. strLocalHyperlink = m_pControllerWindow->m_CurrentDownloadDestination.DisplayName(m_pControllerWindow->m_DestinationNameData).String();
  392. nFinishPrompt = IDS_FINISH_PROMPT_SUCCESS;
  393. }
  394. }
  395. int nCountOfSuccessfulDestinations = 0;
  396. if (strLocalHyperlink.Length() || strRemoteHyperlink.Length())
  397. {
  398. strHyperlinks += TEXT("\n");
  399. }
  400. //
  401. // Get the client rect for calculating the allowable size of the hyperlink string
  402. //
  403. RECT rcControl;
  404. GetClientRect( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ), &rcControl );
  405. if (strLocalHyperlink.Length())
  406. {
  407. nCountOfSuccessfulDestinations++;
  408. strHyperlinks += CSimpleString( IDS_FINISH_LOCAL_LINK_PROMPT, g_hInstance );
  409. strHyperlinks += TEXT("\n");
  410. strHyperlinks += TEXT("<a id=\"") STR_LOCAL_LINK_ID TEXT("\">");
  411. strHyperlinks += WiaUiUtil::TruncateTextToFitInRect( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ), strLocalHyperlink, rcControl, DT_END_ELLIPSIS|DT_NOPREFIX );
  412. strHyperlinks += TEXT("</a>");
  413. }
  414. if (strRemoteHyperlink.Length())
  415. {
  416. nCountOfSuccessfulDestinations++;
  417. strHyperlinks += TEXT("\n\n");
  418. strHyperlinks += CSimpleString( IDS_FINISH_REMOTE_LINK_PROMPT, g_hInstance );
  419. strHyperlinks += TEXT("\n");
  420. strHyperlinks += TEXT("<a id=\"") STR_REMOTE_LINK_ID TEXT("\">");
  421. strHyperlinks += WiaUiUtil::TruncateTextToFitInRect( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ), strRemoteHyperlink, rcControl, DT_END_ELLIPSIS|DT_NOPREFIX );
  422. strHyperlinks += TEXT("</a>");
  423. }
  424. if (strHyperlinks.Length())
  425. {
  426. strHyperlinks += TEXT("\n");
  427. }
  428. //
  429. // Format the success string
  430. //
  431. if (nCountOfSuccessfulDestinations)
  432. {
  433. strSuccessfullyDownloaded.Format( IDS_SUCCESSFUL_DOWNLOAD, g_hInstance, nSuccessCount );
  434. }
  435. //
  436. // Append the individual status messages to the main status message
  437. //
  438. if (strSuccessfullyDownloaded.Length())
  439. {
  440. if (strStatusMessage.Length())
  441. {
  442. strStatusMessage += TEXT("\n");
  443. }
  444. strStatusMessage += strSuccessfullyDownloaded;
  445. }
  446. if (strHyperlinks.Length())
  447. {
  448. if (strStatusMessage.Length())
  449. {
  450. strStatusMessage += TEXT("\n");
  451. }
  452. strStatusMessage += strHyperlinks;
  453. }
  454. if (strSuccessfullyUploaded.Length())
  455. {
  456. if (strStatusMessage.Length())
  457. {
  458. strStatusMessage += TEXT("\n");
  459. }
  460. strStatusMessage += strSuccessfullyUploaded;
  461. }
  462. if (strSuccessfullyDeleted.Length())
  463. {
  464. if (strStatusMessage.Length())
  465. {
  466. strStatusMessage += TEXT("\n");
  467. }
  468. strStatusMessage += strSuccessfullyDeleted;
  469. }
  470. strStatusMessage.SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ) );
  471. }
  472. //
  473. // Else if there was an offline error
  474. //
  475. else if (WIA_ERROR_OFFLINE == m_pControllerWindow->m_hrDownloadResult || m_pControllerWindow->m_bDisconnected)
  476. {
  477. nPageTitle = IDS_FINISH_FAILURE_TITLE;
  478. (CSimpleString( IDS_DEVICE_DISCONNECTED, g_hInstance )).SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ) );
  479. }
  480. //
  481. // Else, if the user cancelled
  482. //
  483. else if (m_pControllerWindow->m_bDownloadCancelled)
  484. {
  485. nPageTitle = IDS_FINISH_FAILURE_TITLE;
  486. CSimpleString( IDS_USER_CANCELLED, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ) );
  487. }
  488. //
  489. // Otherwise there was an error
  490. //
  491. else
  492. {
  493. nPageTitle = IDS_FINISH_FAILURE_TITLE;
  494. CSimpleString( IDS_FINISH_ERROR_MESSAGE, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_STATUS ) );
  495. }
  496. //
  497. // Display the finish title message
  498. //
  499. CSimpleString( nPageTitle, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_TITLE ) );
  500. //
  501. // Display the finish prompt.
  502. //
  503. CSimpleString( nFinishPrompt, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_FINISH_PROMPT ) );
  504. //
  505. // Don't do anything on disconnect messages
  506. //
  507. m_pControllerWindow->m_OnDisconnect = 0;
  508. //
  509. // Get the focus off the stinkin' hyperlink control
  510. //
  511. PostMessage( m_hWnd, WM_NEXTDLGCTL, reinterpret_cast<WPARAM>(GetDlgItem(GetParent(m_hWnd),ID_FINISHBUTTON)), MAKELPARAM(TRUE,0));
  512. return 0;
  513. }
  514. LRESULT CCommonFinishPage::OnDestroy( WPARAM, LPARAM )
  515. {
  516. if (m_hBigTitleFont)
  517. {
  518. DeleteObject(m_hBigTitleFont);
  519. m_hBigTitleFont = NULL;
  520. }
  521. return 0;
  522. }
  523. void CCommonFinishPage::OpenLocalStorage()
  524. {
  525. CWaitCursor wc;
  526. //
  527. // Assume we do need to open the shell folder
  528. //
  529. bool bNeedToOpenShellFolder = true;
  530. //
  531. // Special case for CD burning--attempt to open the CD burner folder
  532. //
  533. if (CDestinationData( CSIDL_CDBURN_AREA ) == m_pControllerWindow->m_CurrentDownloadDestination)
  534. {
  535. //
  536. // Create the CD burner interface, so we can get the drive letter
  537. //
  538. CComPtr<ICDBurn> pCDBurn;
  539. HRESULT hr = CoCreateInstance( CLSID_CDBurn, NULL, CLSCTX_SERVER, IID_ICDBurn, (void**)&pCDBurn );
  540. if (SUCCEEDED(hr))
  541. {
  542. //
  543. // Get the drive letter of the available CD burner
  544. //
  545. WCHAR szDriveLetter[MAX_PATH];
  546. hr = pCDBurn->GetRecorderDriveLetter( szDriveLetter, ARRAYSIZE(szDriveLetter) );
  547. //
  548. // Make sure the function returned success and that we have a string
  549. //
  550. if (S_OK == hr && szDriveLetter[0] != L'\0')
  551. {
  552. //
  553. // Convert the drive to a TCHAR string
  554. //
  555. CSimpleString strShellLocation = CSimpleStringConvert::NaturalString(CSimpleStringWide(szDriveLetter));
  556. if (strShellLocation.Length())
  557. {
  558. //
  559. // Attempt to open the CD drive. If we can't, we will fail gracefully and open the staging area
  560. //
  561. SHELLEXECUTEINFO ShellExecuteInfo = {0};
  562. ShellExecuteInfo.cbSize = sizeof(ShellExecuteInfo);
  563. ShellExecuteInfo.hwnd = m_hWnd;
  564. ShellExecuteInfo.nShow = SW_SHOW;
  565. ShellExecuteInfo.lpVerb = TEXT("open");
  566. ShellExecuteInfo.lpFile = const_cast<LPTSTR>(strShellLocation.String());
  567. if (ShellExecuteEx( &ShellExecuteInfo ))
  568. {
  569. bNeedToOpenShellFolder = false;
  570. }
  571. else
  572. {
  573. WIA_PRINTHRESULT((HRESULT_FROM_WIN32(GetLastError()),TEXT("ShellExecuteEx failed")));
  574. }
  575. }
  576. }
  577. }
  578. }
  579. //
  580. // If we still need to open the shell folder, do so.
  581. //
  582. if (bNeedToOpenShellFolder)
  583. {
  584. CSimpleDynamicArray<CSimpleString> DownloadedFiles;
  585. if (SUCCEEDED(m_pControllerWindow->m_DownloadedFileInformationList.GetUniqueFiles(DownloadedFiles)))
  586. {
  587. OpenShellFolder::OpenShellFolderAndSelectFile( GetParent(m_hWnd), DownloadedFiles );
  588. }
  589. }
  590. }
  591. void CCommonFinishPage::OpenRemoteStorage()
  592. {
  593. CWaitCursor wc;
  594. if (m_strSiteUrl.Length())
  595. {
  596. SHELLEXECUTEINFO ShellExecuteInfo = {0};
  597. ShellExecuteInfo.cbSize = sizeof(ShellExecuteInfo);
  598. ShellExecuteInfo.fMask = SEE_MASK_FLAG_NO_UI;
  599. ShellExecuteInfo.nShow = SW_SHOWNORMAL;
  600. ShellExecuteInfo.lpFile = const_cast<LPTSTR>(m_strSiteUrl.String());
  601. ShellExecuteInfo.lpVerb = TEXT("open");
  602. ShellExecuteEx(&ShellExecuteInfo);
  603. }
  604. }
  605. LRESULT CCommonFinishPage::OnEventNotification( WPARAM, LPARAM lParam )
  606. {
  607. WIA_PUSH_FUNCTION((TEXT("CCommonFinishPage::OnEventNotification") ));
  608. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  609. if (pEventMessage)
  610. {
  611. if (pEventMessage->EventId() == WIA_EVENT_DEVICE_DISCONNECTED)
  612. {
  613. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) == m_hWnd)
  614. {
  615. //
  616. // If there were any errors, disable back, since we can't upload
  617. //
  618. if (S_OK != m_pControllerWindow->m_hrDownloadResult || m_pControllerWindow->m_bDownloadCancelled)
  619. {
  620. //
  621. // Disable "back"
  622. //
  623. PropSheet_SetWizButtons( GetParent(m_hWnd), PSWIZB_FINISH );
  624. }
  625. }
  626. }
  627. //
  628. // Don't delete the message, it is deleted in the controller window
  629. //
  630. }
  631. return 0;
  632. }
  633. LRESULT CCommonFinishPage::OnCommand( WPARAM wParam, LPARAM lParam )
  634. {
  635. SC_BEGIN_COMMAND_HANDLERS()
  636. {
  637. }
  638. SC_END_COMMAND_HANDLERS();
  639. }
  640. LRESULT CCommonFinishPage::OnHyperlinkClick( WPARAM, LPARAM lParam )
  641. {
  642. LRESULT lResult = FALSE;
  643. NMLINK *pNmLink = reinterpret_cast<NMLINK*>(lParam);
  644. if (pNmLink)
  645. {
  646. WIA_TRACE((TEXT("ID: %s"),pNmLink->item.szID));
  647. switch (pNmLink->hdr.idFrom)
  648. {
  649. case IDC_FINISH_STATUS:
  650. {
  651. if (!lstrcmp(pNmLink->item.szID,STR_DETAILED_DOWNLOAD_ERROR_ID))
  652. {
  653. CSimpleString strMessage( IDS_TRANSFER_ERROR, g_hInstance );
  654. strMessage += m_pControllerWindow->m_strErrorMessage;
  655. CMessageBoxEx::MessageBox( m_hWnd, strMessage, CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_OK|CMessageBoxEx::MBEX_ICONWARNING );
  656. lResult = TRUE;
  657. }
  658. else if (!lstrcmp(pNmLink->item.szID,STR_DETAILED_UPLOAD_ERROR_ID))
  659. {
  660. CSimpleString strMessage( IDS_UPLOAD_ERROR, g_hInstance );
  661. CSimpleString strError = WiaUiUtil::GetErrorTextFromHResult(m_pControllerWindow->m_hrUploadResult);
  662. if (!strError.Length())
  663. {
  664. strError.Format( CSimpleString( IDS_TRANSFER_ERROR_OCCURRED, g_hInstance ), m_pControllerWindow->m_hrUploadResult );
  665. }
  666. strMessage += strError;
  667. CMessageBoxEx::MessageBox( m_hWnd, strMessage, CSimpleString( IDS_ERROR_TITLE, g_hInstance ), CMessageBoxEx::MBEX_OK|CMessageBoxEx::MBEX_ICONWARNING );
  668. lResult = TRUE;
  669. }
  670. else if (!lstrcmp(pNmLink->item.szID,STR_LOCAL_LINK_ID))
  671. {
  672. OpenLocalStorage();
  673. lResult = TRUE;
  674. }
  675. else if (!lstrcmp(pNmLink->item.szID,STR_REMOTE_LINK_ID))
  676. {
  677. OpenRemoteStorage();
  678. lResult = TRUE;
  679. }
  680. }
  681. break;
  682. }
  683. }
  684. return lResult;
  685. }
  686. LRESULT CCommonFinishPage::OnNotify( WPARAM wParam, LPARAM lParam )
  687. {
  688. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  689. {
  690. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_RETURN,IDC_FINISH_STATUS,OnHyperlinkClick);
  691. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_CLICK,IDC_FINISH_STATUS,OnHyperlinkClick);
  692. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZBACK,OnWizBack);
  693. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZFINISH,OnWizFinish);
  694. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  695. }
  696. SC_END_NOTIFY_MESSAGE_HANDLERS();
  697. }
  698. INT_PTR CALLBACK CCommonFinishPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  699. {
  700. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CCommonFinishPage)
  701. {
  702. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  703. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  704. SC_HANDLE_DIALOG_MESSAGE( WM_DESTROY, OnDestroy );
  705. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  706. }
  707. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nWiaEventMessage, OnEventNotification );
  708. SC_END_DIALOG_MESSAGE_HANDLERS();
  709. }