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.

1680 lines
43 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. Ca.cpp
  5. Abstract:
  6. Cartridge Node Implementation.
  7. Author:
  8. Rohde Wakefield [rohde] 07-Aug-97
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "Ca.h"
  13. #include "PrCar.h"
  14. int CUiCar::m_nResultIcon = AddResultImage( IDI_NODETAPE );
  15. int CUiCar::m_nResultIconX = AddResultImage( IDI_NODETAPEX );
  16. int CUiCar::m_nResultIconD = AddResultImage( IDI_NODETAPED );
  17. // Not used
  18. int CUiCar::m_nScopeCloseIcon = AddScopeImage( IDI_NODETAPE );
  19. int CUiCar::m_nScopeCloseIconX = AddScopeImage( IDI_NODETAPE );
  20. int CUiCar::m_nScopeOpenIcon = CUiCar::m_nScopeCloseIcon;
  21. int CUiCar::m_nScopeOpenIconX = CUiCar::m_nScopeCloseIconX;
  22. /////////////////////////////////////////////////////////////////////////////
  23. //
  24. // CoComObjectRoot
  25. //
  26. /////////////////////////////////////////////////////////////////////////////
  27. //---------------------------------------------------------------------------
  28. //
  29. // FinalConstruct
  30. //
  31. // Initialize this level of the object hierarchy
  32. //
  33. HRESULT CUiCar::FinalConstruct( )
  34. {
  35. WsbTraceIn( L"CUiCar::FinalConstruct", L"" );
  36. m_rTypeGuid = &cGuidCar;
  37. m_bIsContainer = FALSE;
  38. HRESULT hr = CSakNode::FinalConstruct( );
  39. m_bSupportsPropertiesSingle = TRUE;
  40. m_bSupportsPropertiesMulti = TRUE;
  41. m_bSupportsDeleteSingle = FALSE;
  42. m_bSupportsDeleteMulti = FALSE;
  43. m_bSupportsRefreshSingle = TRUE;
  44. m_bSupportsRefreshMulti = FALSE;
  45. // Toolbar values
  46. INT i = 0;
  47. #if 0 // MS does not want this button to show
  48. m_ToolbarButtons[i].nBitmap = 0;
  49. m_ToolbarButtons[i].idCommand = TB_CMD_CAR_COPIES;
  50. m_ToolbarButtons[i].idButtonText = IDS_TB_TEXT_CAR_COPIES;
  51. m_ToolbarButtons[i].idTooltipText = IDS_TB_TIP_CAR_COPIES;
  52. i++;
  53. #endif
  54. m_ToolbarBitmap = IDB_TOOLBAR_CAR;
  55. m_cToolbarButtons = i;
  56. WsbTraceOut( L"CUiCar::FinalConstruct", L"hr = <%ls>", WsbHrAsString( hr ) );
  57. return( hr );
  58. }
  59. //---------------------------------------------------------------------------
  60. //
  61. // FinalRelease
  62. //
  63. // Clean up this level of the object hierarchy
  64. //
  65. void CUiCar::FinalRelease( )
  66. {
  67. WsbTraceIn( L"CUiCar::FinalRelease", L"" );
  68. CSakNode::FinalRelease( );
  69. WsbTraceOut( L"CUiCar::FinalRelease", L"" );
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. //
  73. // ISakNode
  74. //
  75. /////////////////////////////////////////////////////////////////////////////
  76. //---------------------------------------------------------------------------
  77. //
  78. // GetContextMenu
  79. //
  80. // Return an HMENU to be used for context menus on this node.
  81. //
  82. STDMETHODIMP
  83. CUiCar::GetContextMenu( BOOL /*bMultiSelect*/, HMENU* phMenu )
  84. {
  85. return( LoadContextMenu( IDR_CAR, phMenu ) );
  86. }
  87. //---------------------------------------------------------------------------
  88. //
  89. // InvokeCommand
  90. //
  91. // User has selected a command from the menu. Process it here.
  92. //
  93. STDMETHODIMP
  94. CUiCar::InvokeCommand( SHORT sCmd, IDataObject* pDataObject )
  95. {
  96. WsbTraceIn( L"CUiCar::InvokeCommand", L"sCmd = <%d>", sCmd );
  97. CString theString;
  98. HRESULT hr = S_OK;
  99. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  100. switch (sCmd) {
  101. case ID_CAR_COPIES:
  102. ShowCarProperties( pDataObject, 1 );
  103. break;
  104. }
  105. #if 0
  106. switch (sCmd) {
  107. case ID_CAR_ROOT_DELCARTRIDGE:
  108. theString.Format (L"Del Cartridge menu command for Car: %d", sCmd);
  109. AfxMessageBox(theString);
  110. break;
  111. default:
  112. theString.Format (L"Unknown menu command for Car: %d", sCmd);
  113. AfxMessageBox(theString);
  114. break;
  115. }
  116. #endif
  117. WsbTraceOut( L"CUiCar::InvokeCommand", L"hr = <%ls>", WsbHrAsString( hr ) );
  118. return( hr );
  119. }
  120. HRESULT CUiCar::OnToolbarButtonClick( IDataObject *pDataObject, long cmdId )
  121. {
  122. WsbTraceIn( L"CUiCar::OnToolbarButtonClick", L"cmdId = <%d>", cmdId );
  123. HRESULT hr = S_OK;
  124. try {
  125. switch ( cmdId ) {
  126. case TB_CMD_CAR_COPIES:
  127. ShowCarProperties( pDataObject, 1 );
  128. break;
  129. }
  130. } WsbCatch( hr );
  131. WsbTraceOut( L"CUiCar::OnToolbarButtonClick", L"hr = <%ls>", WsbHrAsString( hr ) );
  132. return hr;
  133. }
  134. HRESULT CUiCar::ShowCarProperties (IDataObject *pDataObject, int initialPage)
  135. {
  136. WsbTraceIn( L"CUiCar::ShowCarProperties", L"initialPage = <%d>", initialPage );
  137. HRESULT hr = S_OK;
  138. try {
  139. CComPtr<ISakNode> pSakNode;
  140. WsbAffirmHr( _InternalQueryInterface( IID_ISakNode, (void **) &pSakNode ) );
  141. WsbAffirmHr( m_pSakSnapAsk->ShowPropertySheet( pSakNode, pDataObject, initialPage ) );
  142. } WsbCatch (hr);
  143. WsbTraceOut( L"CUiCar::ShowCarProperties", L"hr = <%ls>", WsbHrAsString( hr ) );
  144. return hr;
  145. }
  146. //---------------------------------------------------------------------------
  147. //
  148. // InitNode
  149. //
  150. // Initialize single COM object.
  151. //
  152. STDMETHODIMP
  153. CUiCar::InitNode(
  154. ISakSnapAsk* pSakSnapAsk,
  155. IUnknown* pHsmObj,
  156. ISakNode* pParent
  157. )
  158. {
  159. WsbTraceIn( L"CUiCar::InitNode", L"pSakSnapAsk = <0x%p>, pHsmObj = <0x%p>, pParent = <0x%p>", pSakSnapAsk, pHsmObj, pParent );
  160. HRESULT hr = S_OK;
  161. try {
  162. // Note that this node must have it's objectId set before initnode is called.
  163. //
  164. // Init the lower layers.
  165. //
  166. WsbAffirmHr( CSakNode::InitNode( pSakSnapAsk, 0, pParent ) );
  167. //
  168. // Set Display Type
  169. //
  170. CString tempString;
  171. tempString.LoadString( IDS_CAR_TYPE );
  172. WsbAffirmHr( put_Type( (OLECHAR *)(LPCWSTR)tempString ) );
  173. WsbAffirmHr( RefreshObject() );
  174. } WsbCatch( hr );
  175. WsbTraceOut( L"CUiCar::InitNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  176. return( hr );
  177. }
  178. STDMETHODIMP CUiCar::RefreshObject()
  179. {
  180. WsbTraceIn( L"CUiCar::RefreshObject", L"" );
  181. HRESULT hr = S_OK;
  182. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  183. CMediaInfoObject mio;
  184. try {
  185. CComPtr<IHsmServer> pHsmServer;
  186. WsbAffirmHrOk( m_pSakSnapAsk->GetHsmServer( &pHsmServer ) );
  187. CComPtr<IRmsServer> pRmsServer;
  188. WsbAffirmHrOk( m_pSakSnapAsk->GetRmsServer( &pRmsServer ) );
  189. //
  190. // Create a GUI media object and initialize it with the info
  191. //
  192. WsbAffirmHr( mio.Initialize( m_ObjectId, pHsmServer, pRmsServer ) );
  193. //
  194. // Copy information from the media info object to the node object
  195. //
  196. m_RmsIdMaster = mio.m_RmsIdMaster;
  197. m_Type = mio.m_Type;
  198. m_FreeSpace = mio.m_FreeSpace,
  199. m_Capacity = mio.m_Capacity;
  200. m_LastHr = mio.m_LastHr;
  201. m_ReadOnly = mio.m_ReadOnly;
  202. m_Recreating = mio.m_Recreating;
  203. m_MasterName = mio.m_MasterName;
  204. m_Modify = mio.m_Modify;
  205. m_NextDataSet = mio.m_NextDataSet;
  206. m_LastGoodNextDataSet = mio.m_LastGoodNextDataSet;
  207. m_Disabled = mio.m_Disabled;
  208. WsbAffirmHr( put_Description( (LPWSTR)(LPCWSTR)mio.m_MasterDescription ) );
  209. WsbAffirmHr( put_DisplayName( (LPWSTR)(LPCWSTR)mio.m_Description ) );
  210. //
  211. // Update the media copy info
  212. //
  213. for( int i = 0; i < HSMADMIN_MAX_COPY_SETS; i++ ) {
  214. m_CopyInfo[i] = mio.m_CopyInfo[i];
  215. }
  216. } WsbCatch( hr );
  217. WsbTraceOut( L"CUiCar::RefreshObject", L"hr = <%ls>", WsbHrAsString( hr ) );
  218. return( hr );
  219. }
  220. HRESULT
  221. CUiCar::GetCopySetP(
  222. IN int CopySet,
  223. OUT BSTR * pszValue
  224. )
  225. /*++
  226. Routine Description:
  227. Returns a string (BSTR) that describes the state of the
  228. given copy set.
  229. Arguments:
  230. CopySet - copy set of interest.
  231. pszValue - return string representing the state.
  232. Return Value:
  233. S_OK - Handled.
  234. E_UNEXPECTED - Some error occurred.
  235. --*/
  236. {
  237. WsbTraceIn( L"CUiCar::GetCopySetP", L"CopySet = <%d>, pszValue = <0x%p>", CopySet, pszValue );
  238. //
  239. // Three states - Up-to-date, Out-of-date, Error
  240. //
  241. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  242. HRESULT hr = S_OK;
  243. try {
  244. USHORT status;
  245. CString statusString;
  246. status = RsGetCopyStatus( m_CopyInfo[ CopySet - 1 ].m_RmsId, m_CopyInfo[ CopySet - 1 ].m_Hr, m_CopyInfo[ CopySet - 1 ].m_NextDataSet, m_LastGoodNextDataSet );
  247. WsbAffirmHr( RsGetCopyStatusString( status, statusString ) );
  248. *pszValue = SysAllocString( statusString );
  249. WsbAffirmPointer( *pszValue );
  250. } WsbCatch( hr );
  251. WsbTraceOut( L"CUiCar::GetCopySetP", L"hr = <%ls>, pszValue = <%ls>", WsbHrAsString( hr ), WsbPtrToStringAsString( pszValue ) );
  252. return( hr );
  253. }
  254. STDMETHODIMP
  255. CUiCar::get_CopySet1P_SortKey(
  256. OUT BSTR * pszValue
  257. )
  258. {
  259. return( get_CopySet1P( pszValue ) );
  260. }
  261. STDMETHODIMP
  262. CUiCar::get_CopySet2P_SortKey(
  263. OUT BSTR * pszValue
  264. )
  265. {
  266. return( get_CopySet2P( pszValue ) );
  267. }
  268. STDMETHODIMP
  269. CUiCar::get_CopySet3P_SortKey(
  270. OUT BSTR * pszValue
  271. )
  272. {
  273. return( get_CopySet3P( pszValue ) );
  274. }
  275. STDMETHODIMP
  276. CUiCar::get_CopySet1P(
  277. OUT BSTR * pszValue
  278. )
  279. /*++
  280. Routine Description:
  281. Returns a string (BSTR) that describes the state of the
  282. first copy set.
  283. Arguments:
  284. pszValue - return string representing the state.
  285. Return Value:
  286. S_OK - Handled.
  287. E_UNEXPECTED - Some error occurred.
  288. --*/
  289. {
  290. return( GetCopySetP( 1, pszValue ) );
  291. }
  292. STDMETHODIMP
  293. CUiCar::get_CopySet2P(
  294. OUT BSTR * pszValue
  295. )
  296. /*++
  297. Routine Description:
  298. Returns a string (BSTR) that describes the state of the
  299. second copy set.
  300. Arguments:
  301. pszValue - return string representing the state.
  302. Return Value:
  303. S_OK - Handled.
  304. E_UNEXPECTED - Some error occurred.
  305. --*/
  306. {
  307. return( GetCopySetP( 2, pszValue ) );
  308. }
  309. STDMETHODIMP
  310. CUiCar::get_CopySet3P(
  311. OUT BSTR * pszValue
  312. )
  313. /*++
  314. Routine Description:
  315. Returns a string (BSTR) that describes the state of the
  316. third copy set.
  317. Arguments:
  318. pszValue - return string representing the state.
  319. Return Value:
  320. S_OK - Handled.
  321. E_UNEXPECTED - Some error occurred.
  322. --*/
  323. {
  324. return( GetCopySetP( 3, pszValue ) );
  325. }
  326. STDMETHODIMP
  327. CUiCar::get_MediaTypeP(
  328. OUT BSTR * pszValue
  329. )
  330. /*++
  331. Routine Description:
  332. Returns a string (BSTR) that describes the type of media.
  333. Arguments:
  334. pszValue - return string representing the state.
  335. Return Value:
  336. S_OK - Handled.
  337. E_UNEXPECTED - Some error occurred.
  338. --*/
  339. {
  340. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  341. HRESULT hr = S_OK;
  342. try {
  343. CString retval;
  344. int resourceId = IDS_MEDTYPE_UNKNOWN;
  345. switch( m_Type ) {
  346. case HSM_JOB_MEDIA_TYPE_FIXED_MAG:
  347. resourceId = IDS_MEDTYPE_FIXED;
  348. break;
  349. case HSM_JOB_MEDIA_TYPE_REMOVABLE_MAG:
  350. resourceId = IDS_MEDTYPE_REMOVABLE;
  351. break;
  352. case HSM_JOB_MEDIA_TYPE_OPTICAL:
  353. resourceId = IDS_MEDTYPE_OPTICAL;
  354. break;
  355. case HSM_JOB_MEDIA_TYPE_TAPE:
  356. resourceId = IDS_MEDTYPE_TAPE;
  357. break;
  358. }
  359. retval.LoadString( resourceId );
  360. *pszValue = SysAllocString( retval );
  361. WsbAffirmPointer( *pszValue );
  362. } WsbCatch( hr );
  363. return( hr );
  364. }
  365. STDMETHODIMP
  366. CUiCar::get_CapacityP(
  367. OUT BSTR * pszValue
  368. )
  369. /*++
  370. Routine Description:
  371. Returns a string (BSTR) that describes the capacity of
  372. the cartridge.
  373. Arguments:
  374. pszValue - return string representing the state.
  375. Return Value:
  376. S_OK - Handled.
  377. E_UNEXPECTED - Some error occurred.
  378. --*/
  379. {
  380. HRESULT hr = S_OK;
  381. try {
  382. CString retval;
  383. WsbAffirmHr( RsGuiFormatLongLong4Char( m_Capacity, retval ) );
  384. *pszValue = SysAllocString( retval );
  385. WsbAffirmPointer( *pszValue );
  386. } WsbCatch( hr );
  387. return( hr );
  388. }
  389. STDMETHODIMP
  390. CUiCar::get_CapacityP_SortKey(
  391. OUT BSTR * pszValue
  392. )
  393. /*++
  394. Routine Description:
  395. Returns a string (BSTR) that describes the capacity of
  396. the cartridge.
  397. Arguments:
  398. pszValue - return string representing the state.
  399. Return Value:
  400. S_OK - Handled.
  401. E_UNEXPECTED - Some error occurred.
  402. --*/
  403. {
  404. HRESULT hr = S_OK;
  405. try {
  406. *pszValue = SysAlloc64BitSortKey( m_Capacity );
  407. WsbAffirmPointer( *pszValue );
  408. } WsbCatch( hr );
  409. return( hr );
  410. }
  411. STDMETHODIMP
  412. CUiCar::get_FreeSpaceP(
  413. OUT BSTR * pszValue
  414. )
  415. /*++
  416. Routine Description:
  417. Returns a string (BSTR) that describes the free space on
  418. the cartridge.
  419. Arguments:
  420. pszValue - return string representing the state.
  421. Return Value:
  422. S_OK - Handled.
  423. E_UNEXPECTED - Some error occurred.
  424. --*/
  425. {
  426. HRESULT hr = S_OK;
  427. try {
  428. CString retval;
  429. WsbAffirmHr( RsGuiFormatLongLong4Char( m_FreeSpace, retval ) );
  430. *pszValue = SysAllocString( retval );
  431. WsbAffirmPointer( *pszValue );
  432. } WsbCatch( hr );
  433. return( hr );
  434. }
  435. STDMETHODIMP
  436. CUiCar::get_FreeSpaceP_SortKey(
  437. OUT BSTR * pszValue
  438. )
  439. /*++
  440. Routine Description:
  441. Returns a string (BSTR) that describes the free space on
  442. the cartridge.
  443. Arguments:
  444. pszValue - return string representing the state.
  445. Return Value:
  446. S_OK - Handled.
  447. E_UNEXPECTED - Some error occurred.
  448. --*/
  449. {
  450. HRESULT hr = S_OK;
  451. try {
  452. *pszValue = SysAlloc64BitSortKey( m_FreeSpace );
  453. WsbAffirmPointer( *pszValue );
  454. } WsbCatch( hr );
  455. return( hr );
  456. }
  457. STDMETHODIMP
  458. CUiCar::get_StatusP(
  459. OUT BSTR * pszValue
  460. )
  461. /*++
  462. Routine Description:
  463. Returns a string (BSTR) that describes the state of the media.
  464. Arguments:
  465. pszValue - return string representing the state.
  466. Return Value:
  467. S_OK - Handled.
  468. E_UNEXPECTED - Some error occurred.
  469. --*/
  470. {
  471. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  472. HRESULT hr = S_OK;
  473. try {
  474. USHORT status;
  475. CString statusString;
  476. status = RsGetCartStatus( m_LastHr, m_ReadOnly, m_Recreating, m_NextDataSet, m_LastGoodNextDataSet );
  477. WsbAffirmHr( RsGetCartStatusString( status, statusString ) );
  478. *pszValue = SysAllocString( statusString );
  479. WsbAffirmPointer( *pszValue );
  480. } WsbCatch( hr );
  481. return( hr );
  482. }
  483. STDMETHODIMP
  484. CUiCar::get_StatusP_SortKey(
  485. OUT BSTR * pszValue
  486. )
  487. {
  488. return( get_StatusP( pszValue ) );
  489. }
  490. //----------------------------------------------------------------------------
  491. //
  492. // AddPropertyPages
  493. //
  494. STDMETHODIMP
  495. CUiCar::AddPropertyPages(
  496. IN RS_NOTIFY_HANDLE handle,
  497. IN IUnknown* pUnkPropSheetCallback,
  498. IN IEnumGUID* pEnumObjectId,
  499. IN IEnumUnknown* pEnumUnkNode
  500. )
  501. {
  502. WsbTraceIn( L"CUiCar::AddPropertyPages", L"" );
  503. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  504. HRESULT hr = S_OK;
  505. try {
  506. //
  507. // Make sure we can still contact the engine before doing this
  508. // If not running, we shouldn't even exist so update parent
  509. //
  510. CComPtr<IHsmServer> pHsmServer;
  511. HRESULT hrRunning = m_pSakSnapAsk->GetHsmServer( &pHsmServer );
  512. if( S_FALSE == hrRunning ) {
  513. m_pSakSnapAsk->UpdateAllViews( m_pParent );
  514. }
  515. WsbAffirmHrOk( hrRunning );
  516. // Create an object to hold the pages
  517. CUiCarSheet *pCarPropertySheet = new CUiCarSheet;
  518. WsbAffirmAlloc( pCarPropertySheet );
  519. WsbAffirmHr( pCarPropertySheet->InitSheet(
  520. handle,
  521. pUnkPropSheetCallback,
  522. (CSakNode *) this,
  523. m_pSakSnapAsk,
  524. pEnumObjectId,
  525. pEnumUnkNode
  526. ) );
  527. // Tell the object to add it's pages
  528. WsbAffirmHr( pCarPropertySheet->AddPropertyPages( ) );
  529. } WsbCatch ( hr );
  530. WsbTraceOut( L"CUiCar::AddPropertyPages", L"hr = <%ls>", WsbHrAsString( hr ) );
  531. return ( hr );
  532. }
  533. STDMETHODIMP
  534. CUiCar::GetResultIcon(
  535. IN BOOL bOK,
  536. OUT int* pIconIndex
  537. )
  538. {
  539. WsbTraceIn( L"CUiCar::GetResultIcon", L"" );
  540. HRESULT hr = S_OK;
  541. try {
  542. if( m_Disabled ) {
  543. *pIconIndex = m_nResultIconD;
  544. } else {
  545. //
  546. // Check to make sure it's not deleted (or being deleted)
  547. // If so, put on the X
  548. //
  549. USHORT status;
  550. status = RsGetCartStatus( m_LastHr, m_ReadOnly, m_Recreating, m_NextDataSet, m_LastGoodNextDataSet );
  551. switch( status ) {
  552. case RS_MEDIA_STATUS_ERROR_MISSING:
  553. bOK = FALSE;
  554. break;
  555. }
  556. WsbAffirmHr( CSakNodeImpl<CUiCar>::GetResultIcon( bOK, pIconIndex ) );
  557. }
  558. } WsbCatch( hr );
  559. WsbTraceOut( L"CUiCar::GetResultIcon", L"hr = <%ls>", WsbHrAsString( hr ) );
  560. return( hr );
  561. }
  562. ///////////////////////////////////////////////////////////////////////////////////////////
  563. //
  564. //
  565. // Class CUiCarSheet
  566. //
  567. HRESULT
  568. CUiCarSheet::InitSheet(
  569. RS_NOTIFY_HANDLE handle,
  570. IUnknown* pUnkPropSheetCallback,
  571. CSakNode* pSakNode,
  572. ISakSnapAsk* pSakSnapAsk,
  573. IEnumGUID* pEnumObjectId,
  574. IEnumUnknown* pEnumUnkNode
  575. )
  576. {
  577. WsbTraceIn( L"CUiCarSheet::InitSheet",
  578. L"handle <0x%p>, pUnkPropSheetCallback <0x%p>, pSakNode <0x%p>, pSakSnapAsk <0x%p>, pEnumObjectId <0x%p>, pEnumUnkNode <0x%p>",
  579. handle, pUnkPropSheetCallback, pSakNode, pSakSnapAsk, pEnumObjectId, pEnumUnkNode);
  580. HRESULT hr = S_OK;
  581. try {
  582. WsbAffirmHr( CSakPropertySheet::InitSheet( handle, pUnkPropSheetCallback, pSakNode, pSakSnapAsk, pEnumObjectId, pEnumUnkNode ) );
  583. m_pPropPageStatus = NULL;
  584. m_pPropPageCopies = NULL;
  585. m_pPropPageRecover = NULL;
  586. //
  587. // Save the object id (used in single select)
  588. //
  589. WsbAffirmHr( pSakNode->GetObjectId ( & m_mediaId ) );
  590. //
  591. // Get the Hsm Server
  592. //
  593. CComPtr <IHsmServer> pHsmServer;
  594. WsbAffirmHrOk( pSakSnapAsk->GetHsmServer( &pHsmServer ) );
  595. //
  596. // Get Number of Media Copies from engine and save
  597. //
  598. CComPtr<IHsmStoragePool> pPool;
  599. WsbAffirmHr( RsGetStoragePool( pHsmServer, &pPool ) );
  600. WsbAffirmHr( pPool->GetNumMediaCopies( &m_pNumMediaCopies ) );
  601. } WsbCatch( hr );
  602. WsbTraceOut( L"CUiCarSheet::InitSheet", L"hr = <%ls>", WsbHrAsString( hr ) );
  603. return( hr );
  604. }
  605. HRESULT CUiCarSheet::GetNumMediaCopies (USHORT *pNumMediaCopies)
  606. {
  607. WsbTraceIn( L"CUiCarSheet::GetNumMediaCopies", L"pNumMediaCopies = <0x%p>", pNumMediaCopies);
  608. *pNumMediaCopies = m_pNumMediaCopies;
  609. WsbTraceOut( L"CUiCarSheet::GetNumMediaCopies", L"*pNumMediaCopies = <%hu>", *pNumMediaCopies );
  610. return( S_OK );
  611. }
  612. HRESULT CUiCarSheet::AddPropertyPages()
  613. {
  614. WsbTraceIn( L"CUiCarSheet::AddPropertyPages", L"");
  615. HRESULT hr = S_OK;
  616. try {
  617. // set the dll context so that MMC can find the resource.
  618. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  619. // --------------------- Status Page ----------------------------------
  620. long resourceId = ( IsMultiSelect() != S_OK ) ? IDD_PROP_CAR_STATUS : IDD_PROP_CAR_STATUS_MULTI;
  621. m_pPropPageStatus = new CPropCartStatus( resourceId );
  622. WsbAffirmAlloc( m_pPropPageStatus );
  623. WsbAffirmHr( AddPage( m_pPropPageStatus ) );
  624. // --------------------- Copies Page ----------------------------------
  625. resourceId = ( IsMultiSelect() != S_OK ) ? IDD_PROP_CAR_COPIES : IDD_PROP_CAR_COPIES_MULTI;
  626. m_pPropPageCopies = new CPropCartCopies( resourceId );
  627. WsbAffirmAlloc( m_pPropPageCopies );
  628. WsbAffirmHr( AddPage( m_pPropPageCopies ) );
  629. // --------------------- Recovery Page ----------------------------------
  630. // Only show this page for single select
  631. if( IsMultiSelect() != S_OK ) {
  632. m_pPropPageRecover = new CPropCartRecover();
  633. WsbAffirmAlloc( m_pPropPageRecover );
  634. WsbAffirmHr( AddPage( m_pPropPageRecover ) );
  635. }
  636. } WsbCatch( hr );
  637. WsbTraceOut( L"CUiCarSheet::AddPropertyPages", L"hr = <%ls>", WsbHrAsString( hr ) );
  638. return( hr );
  639. }
  640. HRESULT CUiCarSheet::GetMediaId (GUID *pMediaId)
  641. {
  642. WsbTraceIn( L"CUiCarSheet::GetMediaId", L"");
  643. *pMediaId = m_mediaId;
  644. WsbTraceOut( L"CUiCarSheet::GetMediaId", L"*pMediaId <%ls>", WsbGuidAsString( *pMediaId ));
  645. return S_OK;
  646. }
  647. HRESULT CUiCarSheet::OnPropertyChange( RS_NOTIFY_HANDLE hNotifyHandle )
  648. {
  649. HRESULT hr = S_OK;
  650. try {
  651. //
  652. // Call the base class to notify MMC and refresh the result pane
  653. //
  654. CSakPropertySheet::OnPropertyChange( hNotifyHandle );
  655. // Refresh all our pages
  656. if( m_pPropPageStatus ) m_pPropPageStatus->Refresh();
  657. if( m_pPropPageCopies ) m_pPropPageCopies->Refresh();
  658. if( m_pPropPageRecover ) m_pPropPageRecover->Refresh();
  659. } WsbCatch( hr );
  660. return( hr );
  661. }
  662. /////////////////////////////////////////////////////////////////////////////
  663. // CMediaInfoObject
  664. CMediaInfoObject::CMediaInfoObject( )
  665. {
  666. WsbTraceIn( L"CMediaInfoObject::CMediaInfoObject", L"");
  667. m_MediaId = GUID_NULL;
  668. m_RmsIdMaster = GUID_NULL;
  669. m_NumMediaCopies = 0;
  670. for( int index = 0; index < HSMADMIN_MAX_COPY_SETS; index++ ) {
  671. m_CopyInfo[ index ].m_ModifyTime = WsbLLtoFT( 0 );
  672. m_CopyInfo[ index ].m_Hr = S_OK;
  673. m_CopyInfo[ index ].m_RmsId = GUID_NULL;
  674. }
  675. WsbTraceOut( L"CMediaInfoObject::CMediaInfoObject", L"");
  676. }
  677. CMediaInfoObject::~CMediaInfoObject( )
  678. {
  679. WsbTraceIn( L"CMediaInfoObject::~CMediaInfoObject", L"");
  680. // Release the entity first
  681. if( m_pMediaInfo ) {
  682. m_pMediaInfo = 0;
  683. }
  684. // Close the DB
  685. if( m_pDb ) {
  686. m_pDb->Close( m_pDbSession );
  687. }
  688. WsbTraceOut( L"CMediaInfoObject::~CMediaInfoObject", L"");
  689. }
  690. HRESULT CMediaInfoObject::First( )
  691. {
  692. HRESULT hr = S_OK;
  693. try {
  694. WsbAffirmPointer( m_pMediaInfo );
  695. WsbAffirmHr( m_pMediaInfo->First( ) );
  696. //
  697. // Get information
  698. //
  699. WsbAffirmHr( InternalGetInfo( ) );
  700. } WsbCatch ( hr );
  701. return( hr );
  702. }
  703. HRESULT CMediaInfoObject::Next( )
  704. {
  705. HRESULT hr = S_OK;
  706. try {
  707. WsbAffirmPointer( m_pMediaInfo );
  708. WsbAffirmHr( m_pMediaInfo->Next() );
  709. // Get information
  710. WsbAffirmHr( InternalGetInfo() );
  711. } WsbCatch ( hr );
  712. return hr;
  713. }
  714. HRESULT CMediaInfoObject::DeleteCopy( int Copy )
  715. {
  716. HRESULT hr = S_OK;
  717. try {
  718. GUID mediaSubsystemId;
  719. WsbAffirmHr( m_pMediaInfo->GetCopyMediaSubsystemId( (USHORT)Copy, &mediaSubsystemId ));
  720. // If the cartridge cannot be found we assume it
  721. // was already deallocated through the media manager UI.
  722. HRESULT hrRecycle = m_pRmsServer->RecycleCartridge( mediaSubsystemId, 0 );
  723. WsbAffirm( S_OK == hrRecycle || RMS_E_CARTRIDGE_NOT_FOUND == hrRecycle, hrRecycle );
  724. WsbAffirmHr( m_pMediaInfo->DeleteCopy( (USHORT)Copy ) );
  725. WsbAffirmHr( m_pMediaInfo->Write( ) );
  726. } WsbCatch (hr);
  727. return hr;
  728. }
  729. HRESULT CMediaInfoObject::RecreateMaster( )
  730. {
  731. HRESULT hr = S_OK;
  732. try {
  733. SHORT copyToUse = 0;
  734. //
  735. // Before we do recreate master, let's make sure there
  736. // is an up-to-date copy available
  737. //
  738. BOOL goodCopyAvailable = FALSE;
  739. USHORT status;
  740. CComPtr<IRmsCartridge> pRmsCart;
  741. LONG type;
  742. for( int index = 0; index < m_NumMediaCopies && !goodCopyAvailable; index++ ) {
  743. status = RsGetCopyStatus( m_CopyInfo[ index ].m_RmsId, m_CopyInfo[ index ].m_Hr, m_CopyInfo[ index ].m_NextDataSet, m_LastGoodNextDataSet );
  744. if( RS_MEDIA_COPY_STATUS_INSYNC == status ) {
  745. //
  746. // Enabled?
  747. //
  748. if( ! m_CopyInfo[ index ].m_Disabled ) {
  749. pRmsCart.Release( );
  750. HRESULT hrFind = m_pRmsServer->FindCartridgeById( m_CopyInfo[ index ].m_RmsId, &pRmsCart );
  751. if( SUCCEEDED( hrFind ) ) {
  752. //
  753. // Available without user intervention?
  754. //
  755. WsbAffirmHr( pRmsCart->GetLocation( &type, 0, 0, 0, 0, 0, 0, 0 ) );
  756. switch( (RmsElement) type ) {
  757. case RmsElementShelf:
  758. case RmsElementOffSite:
  759. case RmsElementUnknown:
  760. break;
  761. default:
  762. goodCopyAvailable = TRUE;
  763. }
  764. }
  765. }
  766. }
  767. }
  768. if( !goodCopyAvailable ) {
  769. CRecreateChooseCopy dlg( this );
  770. if( IDOK == dlg.DoModal( ) ) {
  771. copyToUse = dlg.CopyToUse( );
  772. } else {
  773. //
  774. // Otherwise, cancel
  775. //
  776. WsbThrow( E_FAIL );
  777. }
  778. }
  779. WsbAffirmHr( RsCreateAndRunMediaRecreateJob( m_pHsmServer, m_pMediaInfo, m_MediaId, m_Description, copyToUse ) );
  780. } WsbCatch ( hr );
  781. return hr;
  782. }
  783. HRESULT CMediaInfoObject::Initialize( GUID mediaId, IHsmServer *pHsmServer, IRmsServer *pRmsServer )
  784. {
  785. // Initialize can be called any number of times
  786. // Note: Initialize with GUID_NULL to start with the first record
  787. WsbTraceIn( L"CMediaInfoObject::Initialize", L"mediaId = <%ls>, pHsmServer = <0x%p>, pRmsServer = <%0x%0.8x>",
  788. WsbGuidAsString( mediaId ), pHsmServer, pRmsServer );
  789. HRESULT hr = S_OK;
  790. HRESULT hrInternal = S_OK;
  791. try {
  792. m_pHsmServer = pHsmServer;
  793. m_pRmsServer = pRmsServer;
  794. // If already initialized, don't re-open
  795. if( !m_pDb ) {
  796. WsbAffirmHr( pHsmServer->GetSegmentDb( &m_pDb ) );
  797. WsbAffirmHr( m_pDb->Open( &m_pDbSession ) );
  798. WsbAffirmHr( m_pDb->GetEntity( m_pDbSession, HSM_MEDIA_INFO_REC_TYPE, IID_IMediaInfo, (void**)&m_pMediaInfo ) );
  799. }
  800. // Get the number of media sets
  801. CComPtr<IHsmStoragePool> pPool;
  802. WsbAffirmHr( RsGetStoragePool( m_pHsmServer, &pPool ) );
  803. WsbAffirmHr( pPool->GetNumMediaCopies( &m_NumMediaCopies ) );
  804. // If the caller supplied a GUID, find the corresponding record. If not, start at
  805. // the beginning.
  806. if( IsEqualGUID( mediaId, GUID_NULL ) ) {
  807. // Don't throw an error on First, it's OK to not have any media
  808. try {
  809. if( SUCCEEDED( m_pMediaInfo->First() ) ) {
  810. WsbAffirmHr( InternalGetInfo () );
  811. }
  812. } WsbCatch( hrInternal );
  813. } else {
  814. WsbAffirmHr( m_pMediaInfo->SetId( mediaId ) );
  815. WsbAffirmHr( m_pMediaInfo->FindEQ( ) );
  816. WsbAffirmHr( InternalGetInfo () );
  817. }
  818. } WsbCatch( hr );
  819. WsbTraceOut( L"CMediaInfoObject::Initialize", L"hr = <%ls>", WsbHrAsString( hr ) );
  820. return( hr );
  821. }
  822. HRESULT CMediaInfoObject::InternalGetInfo( )
  823. {
  824. HRESULT hr = S_OK;
  825. CWsbStringPtr name;
  826. CWsbStringPtr description;
  827. LONGLONG logicalValidBytes;
  828. GUID storagePool;
  829. try {
  830. //
  831. // Get information about the last known good master so that we
  832. // have a true reference whether a copy is up-to-date or not,
  833. // and whether a recreated master is complete or not.
  834. //
  835. GUID unusedGuid1;
  836. GUID unusedGuid2; // NOTE: Use multiples so the trace in GetLastKnownGoodMasterInfo works
  837. GUID unusedGuid3; // NOTE: Use multiples so the trace in GetLastKnownGoodMasterInfo works
  838. LONGLONG unusedLL1;
  839. LONGLONG unusedLL2; // NOTE: Use multiples so the trace in GetLastKnownGoodMasterInfo works
  840. BOOL unusedBool;
  841. HRESULT unusedHr;
  842. FILETIME unusedFt;
  843. HSM_JOB_MEDIA_TYPE unusedJMT;
  844. m_Disabled = FALSE;
  845. WsbAffirmHr( m_pMediaInfo->GetLastKnownGoodMasterInfo(
  846. &unusedGuid1, &unusedGuid2, &unusedGuid3, &unusedLL1, &unusedLL2,
  847. &unusedHr, &description, 0, &unusedJMT, &name, 0, &unusedBool, &unusedFt,
  848. &m_LastGoodNextDataSet ) );
  849. name.Free( );
  850. description.Free( );
  851. //
  852. // Get the standard media info
  853. //
  854. WsbAffirmHr( m_pMediaInfo->GetMediaInfo(
  855. &m_MediaId, &m_RmsIdMaster, &storagePool,
  856. &m_FreeSpace, &m_Capacity, &m_LastHr,
  857. &m_NextDataSet, &description, 0, &m_Type,
  858. &name, 0, &m_ReadOnly, &m_Modify,
  859. &logicalValidBytes, &m_Recreating ) );
  860. m_Name = name;
  861. m_Description = description;
  862. //
  863. // Get info about the copy sets. Note that we grab all
  864. // info, not just up to the number of copys set by user
  865. //
  866. USHORT index;
  867. USHORT status;
  868. for( index = 0; index < HSMADMIN_MAX_COPY_SETS; index++ ) {
  869. description.Free( );
  870. name.Free( );
  871. m_CopyInfo[index].m_Disabled = FALSE;
  872. //
  873. // copy sets are 1 based.
  874. //
  875. WsbAffirmHr( m_pMediaInfo->GetCopyInfo( (USHORT)( index + 1 ),
  876. &(m_CopyInfo[index].m_RmsId), &description, 0, &name, 0,
  877. &(m_CopyInfo[index].m_ModifyTime),
  878. &(m_CopyInfo[index].m_Hr),
  879. &(m_CopyInfo[index].m_NextDataSet) ) );
  880. status = RsGetCopyStatus( m_CopyInfo[ index ].m_RmsId, m_CopyInfo[ index ].m_Hr, m_CopyInfo[ index ].m_NextDataSet, m_LastGoodNextDataSet );
  881. if ( status != RS_MEDIA_COPY_STATUS_NONE ) {
  882. if( m_pRmsServer ) {
  883. //
  884. // Make sure the cartridge is still available.
  885. //
  886. CComPtr<IRmsCartridge> pRmsCart;
  887. HRESULT hrFind = m_pRmsServer->FindCartridgeById( m_CopyInfo[index].m_RmsId, &pRmsCart );
  888. if( FAILED( hrFind ) ) {
  889. //
  890. // Didn't find cartridge, may have been deallocated
  891. // Show that there is a problem and use what info we have
  892. //
  893. m_CopyInfo[index].m_Hr = hrFind;
  894. } else {
  895. //
  896. // Is Cartridge disabled?
  897. //
  898. CComPtr<IRmsComObject> pCartCom;
  899. WsbAffirmHr( pRmsCart.QueryInterface( &pCartCom ) );
  900. if( pCartCom->IsEnabled( ) == S_FALSE ) {
  901. m_CopyInfo[index].m_Disabled = TRUE;
  902. }
  903. }
  904. }
  905. }
  906. }
  907. if( m_pRmsServer ) {
  908. //
  909. // Get the corresponding RmsCartridge object
  910. //
  911. CComPtr<IRmsCartridge> pRmsCart;
  912. HRESULT hrFind = m_pRmsServer->FindCartridgeById( m_RmsIdMaster, &pRmsCart );
  913. if( SUCCEEDED( hrFind ) ) {
  914. //
  915. // Is Cartridge disabled?
  916. //
  917. CComPtr<IRmsComObject> pCartCom;
  918. WsbAffirmHr( pRmsCart.QueryInterface( &pCartCom ) );
  919. if( pCartCom->IsEnabled( ) == S_FALSE ) {
  920. m_Disabled = TRUE;
  921. }
  922. //
  923. // Fill out internal info
  924. //
  925. CWsbBstrPtr bstr;
  926. WsbAffirmHr( pRmsCart->GetName( &bstr ) );
  927. if( wcscmp( bstr, L"" ) == 0 ) {
  928. m_MasterName.Format( IDS_CAR_NAME_UNKNOWN );
  929. } else {
  930. m_MasterName = bstr;
  931. }
  932. bstr.Free( );
  933. WsbAffirmHr( pRmsCart->GetDescription( &bstr ) );
  934. m_MasterDescription = bstr;
  935. } else {
  936. //
  937. // Didn't find cartridge, may have been deallocated
  938. // Show that there is a problem and use what info we have
  939. //
  940. m_LastHr = hrFind;
  941. }
  942. }
  943. } WsbCatch( hr );
  944. return( hr );
  945. }
  946. /////////////////////////////////////////////////////////////////////////////
  947. // CRecreateChooseCopy dialog
  948. CRecreateChooseCopy::CRecreateChooseCopy(CMediaInfoObject * pMio, CWnd* pParent /*=NULL*/)
  949. : CDialog(CRecreateChooseCopy::IDD, pParent), m_pMio( pMio ), m_CopyToUse( 0 )
  950. {
  951. //{{AFX_DATA_INIT(CRecreateChooseCopy)
  952. // NOTE: the ClassWizard will add member initialization here
  953. //}}AFX_DATA_INIT
  954. }
  955. void CRecreateChooseCopy::DoDataExchange(CDataExchange* pDX)
  956. {
  957. CDialog::DoDataExchange(pDX);
  958. //{{AFX_DATA_MAP(CRecreateChooseCopy)
  959. DDX_Control(pDX, IDC_RECREATE_COPY_LIST, m_List);
  960. //}}AFX_DATA_MAP
  961. }
  962. BEGIN_MESSAGE_MAP(CRecreateChooseCopy, CDialog)
  963. //{{AFX_MSG_MAP(CRecreateChooseCopy)
  964. ON_NOTIFY(NM_CLICK, IDC_RECREATE_COPY_LIST, OnClickList)
  965. //}}AFX_MSG_MAP
  966. END_MESSAGE_MAP()
  967. /////////////////////////////////////////////////////////////////////////////
  968. // CRecreateChooseCopy message handlers
  969. SHORT CRecreateChooseCopy::CopyToUse( void )
  970. {
  971. WsbTraceIn( L"CRecreateChooseCopy::CopyToUse", L"" );
  972. SHORT copyToUse = m_CopyToUse;
  973. WsbTraceOut( L"CRecreateChooseCopy::CopyToUse", L"copyToUse = <%hd>", copyToUse );
  974. return( copyToUse );
  975. }
  976. void CRecreateChooseCopy::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
  977. {
  978. WsbTraceIn( L"CRecreateChooseCopy::OnClickList", L"" );
  979. NMLISTVIEW *pNMLV = (NMLISTVIEW*)pNMHDR;
  980. int index = pNMLV->iItem;
  981. BOOL enableOk = FALSE;
  982. if( ( index >= 0 ) && ( index < m_pMio->m_NumMediaCopies ) ) {
  983. if( ! m_pMio->m_CopyInfo[ index ].m_Disabled ) {
  984. USHORT status;
  985. status = RsGetCopyStatus( m_pMio->m_CopyInfo[ index ].m_RmsId, m_pMio->m_CopyInfo[ index ].m_Hr, m_pMio->m_CopyInfo[ index ].m_NextDataSet, m_pMio->m_LastGoodNextDataSet );
  986. switch( status ) {
  987. case RS_MEDIA_COPY_STATUS_NONE:
  988. case RS_MEDIA_COPY_STATUS_MISSING:
  989. //
  990. // Do not allow
  991. //
  992. break;
  993. case RS_MEDIA_COPY_STATUS_OUTSYNC:
  994. case RS_MEDIA_COPY_STATUS_INSYNC:
  995. case RS_MEDIA_COPY_STATUS_ERROR:
  996. enableOk = TRUE;
  997. m_CopyToUse = (USHORT)( index + 1 );
  998. break;
  999. }
  1000. }
  1001. }
  1002. GetDlgItem( IDOK )->EnableWindow( enableOk );
  1003. *pResult = 0;
  1004. WsbTraceOut( L"CRecreateChooseCopy::OnClickList", L"" );
  1005. }
  1006. BOOL CRecreateChooseCopy::OnInitDialog()
  1007. {
  1008. WsbTraceIn( L"CRecreateChooseCopy::OnInitDialog", L"" );
  1009. HRESULT hr = S_OK;
  1010. try {
  1011. CDialog::OnInitDialog();
  1012. //
  1013. // Disable the OK button until something appropriate is selected
  1014. //
  1015. GetDlgItem( IDOK )->EnableWindow( FALSE );
  1016. //
  1017. // Set the style appropriately
  1018. //
  1019. ListView_SetExtendedListViewStyle( m_List.GetSafeHwnd( ), LVS_EX_FULLROWSELECT );
  1020. //
  1021. // Also need to calculate some buffer space
  1022. // Use 8 dialog units (for numeral)
  1023. //
  1024. CRect padRect( 0, 0, 8, 8 );
  1025. MapDialogRect( padRect );
  1026. //
  1027. // Set up columns
  1028. //
  1029. CString title;
  1030. int column = 0;
  1031. int width, widthDateTitle, widthSum = 0;
  1032. m_ColCopy = column++;
  1033. title.LoadString( IDS_RECREATE_COL_COPY_WIDTH );
  1034. width = m_List.GetStringWidth( title ) + padRect.Width( );
  1035. widthSum += width;
  1036. title.LoadString( IDS_RECREATE_COL_COPY_TITLE );
  1037. m_List.InsertColumn( m_ColCopy, title, LVCFMT_LEFT, width );
  1038. m_ColName = column++;
  1039. title.LoadString( IDS_RECREATE_COL_NAME_WIDTH );
  1040. width = m_List.GetStringWidth( title ) + padRect.Width( );
  1041. widthSum += width;
  1042. title.LoadString( IDS_RECREATE_COL_NAME_TITLE );
  1043. m_List.InsertColumn( m_ColName, title, LVCFMT_LEFT, width );
  1044. m_ColStatus = column++;
  1045. title.LoadString( IDS_RECREATE_COL_STATUS_WIDTH );
  1046. width = m_List.GetStringWidth( title ) + padRect.Width( );
  1047. widthSum += width;
  1048. title.LoadString( IDS_RECREATE_COL_STATUS_TITLE );
  1049. m_List.InsertColumn( m_ColStatus, title, LVCFMT_LEFT, width );
  1050. m_ColDate = column++;
  1051. title.LoadString( IDS_RECREATE_COL_DATE_TITLE );
  1052. m_List.InsertColumn( m_ColDate, title );
  1053. widthDateTitle = m_List.GetStringWidth( title );
  1054. //
  1055. // Date gets what is left in width
  1056. //
  1057. CRect viewRect;
  1058. m_List.GetClientRect( &viewRect );
  1059. m_List.SetColumnWidth( m_ColDate, max( widthDateTitle, viewRect.Width( ) - widthSum ) );
  1060. //
  1061. // Fill in list view
  1062. //
  1063. CComPtr<IRmsCartridge> pRmsCart;
  1064. CWsbBstrPtr name;
  1065. USHORT status;
  1066. CString statusString1, statusString2;
  1067. LONG type;
  1068. for( int index = 0; index < m_pMio->m_NumMediaCopies; index++ ) {
  1069. title.Format( IDS_RECREATE_COPY_FORMAT, index + 1 );
  1070. m_List.InsertItem( index, title );
  1071. status = RsGetCopyStatus(
  1072. m_pMio->m_CopyInfo[ index ].m_RmsId,
  1073. m_pMio->m_CopyInfo[ index ].m_Hr,
  1074. m_pMio->m_CopyInfo[ index ].m_NextDataSet,
  1075. m_pMio->m_LastGoodNextDataSet );
  1076. WsbAffirmHr( RsGetCopyStatusString( status, statusString1 ) );
  1077. if( RS_MEDIA_COPY_STATUS_NONE == status ) {
  1078. title = statusString1;
  1079. } else {
  1080. type = RmsElementUnknown;
  1081. pRmsCart.Release( );
  1082. HRESULT hrFind = m_pMio->m_pRmsServer->FindCartridgeById( m_pMio->m_CopyInfo[ index ].m_RmsId, &pRmsCart );
  1083. if( SUCCEEDED( hrFind ) ) {
  1084. name.Free( );
  1085. WsbAffirmHr( pRmsCart->GetName( &name ) );
  1086. m_List.SetItemText( index, m_ColName, name );
  1087. WsbAffirmHr( pRmsCart->GetLocation( &type, 0, 0, 0, 0, 0, 0, 0 ) );
  1088. }
  1089. if( m_pMio->m_CopyInfo[ index ].m_Disabled ) {
  1090. statusString2.LoadString( IDS_RECREATE_LOCATION_DISABLED );
  1091. } else {
  1092. switch( (RmsElement) type ) {
  1093. case RmsElementShelf:
  1094. case RmsElementOffSite:
  1095. statusString2.LoadString( IDS_RECREATE_LOCATION_OFFLINE );
  1096. break;
  1097. case RmsElementUnknown:
  1098. statusString2.LoadString( IDS_RECREATE_LOCATION_UNKNOWN );
  1099. break;
  1100. default:
  1101. statusString2.LoadString( IDS_RECREATE_LOCATION_ONLINE );
  1102. }
  1103. }
  1104. AfxFormatString2( title, IDS_RECREATE_STATUS_FORMAT, statusString1, statusString2 );
  1105. CTime time( m_pMio->m_CopyInfo[ index ].m_ModifyTime );
  1106. m_List.SetItemText( index, m_ColDate, time.Format( L"%c" ) );
  1107. }
  1108. m_List.SetItemText( index, m_ColStatus, title );
  1109. }
  1110. } WsbCatch( hr );
  1111. WsbTraceOut( L"CRecreateChooseCopy::OnInitDialog", L"" );
  1112. return TRUE;
  1113. }
  1114. void CRecreateChooseCopy::OnOK()
  1115. {
  1116. //
  1117. // Before passing on the OK, check to see if the selected copy is
  1118. // cause for one last warning before continuing i.e. out-of-date or
  1119. // errored copy
  1120. //
  1121. BOOL okToContinue = FALSE;
  1122. int index = m_CopyToUse - 1;
  1123. if( ( index >= 0 ) && ( index < m_pMio->m_NumMediaCopies ) ) {
  1124. if( ! m_pMio->m_CopyInfo[ index ].m_Disabled ) {
  1125. USHORT status;
  1126. status = RsGetCopyStatus( m_pMio->m_CopyInfo[ index ].m_RmsId, m_pMio->m_CopyInfo[ index ].m_Hr, m_pMio->m_CopyInfo[ index ].m_NextDataSet, m_pMio->m_LastGoodNextDataSet );
  1127. switch( status ) {
  1128. case RS_MEDIA_COPY_STATUS_NONE:
  1129. case RS_MEDIA_COPY_STATUS_MISSING:
  1130. //
  1131. // Do not allow
  1132. //
  1133. break;
  1134. case RS_MEDIA_COPY_STATUS_INSYNC:
  1135. okToContinue = TRUE;
  1136. break;
  1137. case RS_MEDIA_COPY_STATUS_OUTSYNC:
  1138. case RS_MEDIA_COPY_STATUS_ERROR:
  1139. {
  1140. CString confirm, format;
  1141. format.LoadString( IDS_CONFIRM_MEDIA_RECREATE );
  1142. LPCWSTR description = m_pMio->m_Description;
  1143. AfxFormatStrings( confirm, format, &description, 1 );
  1144. if( IDYES == AfxMessageBox( confirm, MB_ICONEXCLAMATION | MB_YESNO | MB_DEFBUTTON2 ) ) {
  1145. okToContinue = TRUE;
  1146. }
  1147. }
  1148. break;
  1149. }
  1150. }
  1151. }
  1152. if( okToContinue ) {
  1153. CDialog::OnOK();
  1154. }
  1155. }
  1156. HRESULT CMediaInfoObject::DoesMasterExist( )
  1157. {
  1158. return(
  1159. ( GUID_NULL != m_MediaId ) &&
  1160. ( RMS_E_CARTRIDGE_NOT_FOUND != m_LastHr ) ? S_OK : S_FALSE );
  1161. }
  1162. HRESULT CMediaInfoObject::DoesCopyExist(INT Copy)
  1163. {
  1164. return(
  1165. ( GUID_NULL != m_CopyInfo[Copy].m_RmsId ) &&
  1166. ( RMS_E_CARTRIDGE_NOT_FOUND != m_CopyInfo[Copy].m_Hr ) ? S_OK : S_FALSE );
  1167. }
  1168. HRESULT CMediaInfoObject::IsCopyInSync(INT Copy)
  1169. {
  1170. if( RS_MEDIA_COPY_STATUS_INSYNC ==
  1171. RsGetCopyStatus(
  1172. m_CopyInfo[Copy].m_RmsId,
  1173. S_OK, // ignore errors in copy
  1174. m_CopyInfo[Copy].m_NextDataSet,
  1175. m_LastGoodNextDataSet ) ) {
  1176. return S_OK;
  1177. }
  1178. return( S_FALSE );
  1179. }
  1180. HRESULT CMediaInfoObject::IsViewable( BOOL ConsiderInactiveCopies )
  1181. {
  1182. HRESULT hr = S_FALSE;
  1183. if( S_OK == DoesMasterExist( ) ) {
  1184. hr = S_OK;
  1185. } else {
  1186. //
  1187. // Look to see if any of the copies exist
  1188. //
  1189. INT lastCopy = ConsiderInactiveCopies ? HSMADMIN_MAX_COPY_SETS : m_NumMediaCopies;
  1190. for( INT index = 0; index < lastCopy; index++ ) {
  1191. if( S_OK == DoesCopyExist( index ) ) {
  1192. hr = S_OK;
  1193. break;
  1194. }
  1195. }
  1196. }
  1197. return( hr );
  1198. }