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.

1382 lines
29 KiB

  1. // File : HMObject.inl
  2. //
  3. // Copyright (c) 2000 Microsoft Corporation
  4. //
  5. // 03/25/00 v-marfin 60298 Delete source object after a drag and drop MOVE
  6. // operation.
  7. // 04/05/00 v-marfin 59492b Also check for object type of CActionPolicy
  8. // in Refresh function so this type is not deleted as
  9. // part of the refresh.
  10. //
  11. //
  12. //
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Create/Destroy
  18. /////////////////////////////////////////////////////////////////////////////
  19. inline void CHMObject::Destroy(bool bDeleteClassObject /*= false*/)
  20. {
  21. TRACEX(_T("CHMObject::Destroy\n"));
  22. if( bDeleteClassObject )
  23. {
  24. DeleteClassObject();
  25. }
  26. for( int i = 0; i < GetChildCount(); i++ )
  27. {
  28. CHMObject* pObject = GetChild(i);
  29. if( pObject )
  30. {
  31. pObject->Destroy(bDeleteClassObject);
  32. delete pObject;
  33. m_Children.SetAt(i,NULL);
  34. }
  35. }
  36. m_Children.RemoveAll();
  37. RemoveAllScopeItems();
  38. // TODO : Destroy Events
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // WMI Operations
  42. /////////////////////////////////////////////////////////////////////////////
  43. inline HRESULT CHMObject::EnumerateChildren()
  44. {
  45. TRACEX(_T("CHMObject::EnumerateChildren\n"));
  46. // ASSERT(FALSE);
  47. return E_FAIL;
  48. }
  49. inline CString CHMObject::GetObjectPath()
  50. {
  51. TRACEX(_T("CHMObject::GetObjectPath\n"));
  52. return _T("");
  53. }
  54. inline CString CHMObject::GetStatusObjectPath()
  55. {
  56. TRACEX(_T("CHMObject::GetStatusObjectPath\n"));
  57. return _T("");
  58. }
  59. inline CWbemClassObject* CHMObject::GetClassObject()
  60. {
  61. TRACEX(_T("CHMObject::GetClassObject\n"));
  62. CWbemClassObject* pClassObject = new CWbemClassObject;
  63. if( ! CHECKHRESULT(pClassObject->Create(GetSystemName())) )
  64. {
  65. delete pClassObject;
  66. return NULL;
  67. }
  68. if( ! CHECKHRESULT(pClassObject->GetObject(GetObjectPath())) )
  69. {
  70. delete pClassObject;
  71. return NULL;
  72. }
  73. return pClassObject;
  74. }
  75. inline CWbemClassObject* CHMObject::GetParentClassObject()
  76. {
  77. TRACEX(_T("CHMObject::GetParentClassObject\n"));
  78. return NULL;
  79. }
  80. inline CHMEvent* CHMObject::GetStatusClassObject()
  81. {
  82. TRACEX(_T("CHMObject::GetStatusClassObject\n"));
  83. CHMEvent* pClassObject = new CHMEvent;
  84. pClassObject->SetMachineName(GetSystemName());
  85. if( ! CHECKHRESULT(pClassObject->GetObject(GetStatusObjectPath())) )
  86. {
  87. delete pClassObject;
  88. return NULL;
  89. }
  90. return pClassObject;
  91. }
  92. inline void CHMObject::DeleteClassObject()
  93. {
  94. TRACEX(_T("CHMObject::DeleteClassObject\n"));
  95. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  96. {
  97. return;
  98. }
  99. CWbemClassObject HMSystemConfig;
  100. HMSystemConfig.Create(GetSystemName());
  101. if( ! CHECKHRESULT(HMSystemConfig.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG)) )
  102. {
  103. return;
  104. }
  105. int iResult = 0;
  106. CString sArgValue;
  107. sArgValue.Format(_T("{%s}"),GetGuid());
  108. if( ! CHECKHRESULT(HMSystemConfig.ExecuteMethod(_T("Delete"),_T("TargetGUID"),sArgValue,iResult)) )
  109. {
  110. return;
  111. }
  112. }
  113. inline bool CHMObject::ImportMofFile(CArchive& ar)
  114. {
  115. TRACEX(_T("CHMObject::ImportMofFile\n"));
  116. ASSERT(ar.IsLoading());
  117. return true;
  118. }
  119. inline bool CHMObject::ExportMofFile(CArchive& ar)
  120. {
  121. TRACEX(_T("CHMObject::ExportMofFile\n"));
  122. ASSERT(ar.IsStoring());
  123. CString sText;
  124. CWbemClassObject* pClassObject = GetClassObject();
  125. pClassObject->GetObjectText(sText);
  126. USES_CONVERSION;
  127. char* pszAnsiText = T2A(sText);
  128. ar.Write(pszAnsiText,strlen(pszAnsiText)+sizeof(char));
  129. /*
  130. for( int i = 0; i < GetChildCount(); i++ )
  131. {
  132. CHMObject* pObject = GetChild(i);
  133. if( pObject )
  134. {
  135. pObject->ExportMofFile(ar);
  136. }
  137. }
  138. */
  139. return true;
  140. }
  141. /////////////////////////////////////////////////////////////////////////////
  142. // Clipboard Operations
  143. /////////////////////////////////////////////////////////////////////////////
  144. inline bool CHMObject::Copy(CString& sParentGuid, COleSafeArray& Instances)
  145. {
  146. TRACEX(_T("CHMObject::Copy\n"));
  147. CWbemClassObject SystemConfigObject;
  148. SystemConfigObject.Create(GetSystemName());
  149. HRESULT hr = SystemConfigObject.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG);
  150. if( ! CHECKHRESULT(hr) )
  151. {
  152. return false;
  153. }
  154. CWbemClassObject CopyMethodIn;
  155. CWbemClassObject CopyMethodOut;
  156. hr = SystemConfigObject.GetMethod(_T("Copy"),CopyMethodIn);
  157. if( ! CHECKHRESULT(hr) )
  158. {
  159. CnxDisplayErrorMsgBox(hr,GetSystemName());
  160. return false;
  161. }
  162. CString sGuid = _T("{") + GetGuid() + _T("}");
  163. CopyMethodIn.SetProperty(_T("TargetGUID"),sGuid);
  164. hr = SystemConfigObject.ExecuteMethod(_T("Copy"),CopyMethodIn,CopyMethodOut);
  165. if( ! CHECKHRESULT(hr) )
  166. {
  167. CnxDisplayErrorMsgBox(hr,GetSystemName());
  168. return false;
  169. }
  170. CopyMethodOut.GetProperty(_T("OriginalParentGuid"),sParentGuid);
  171. CopyMethodOut.GetProperty(_T("Instances"),Instances);
  172. return true;
  173. }
  174. // Move operations result in bIsOperationCopy = 0
  175. // Copy operations result in bIsOperationCopy = 1
  176. inline bool CHMObject::Paste(CHMObject* pObject, bool bIsOperationCopy)
  177. {
  178. TRACEX(_T("CHMObject::Paste\n"));
  179. TRACEARGn(pObject);
  180. TRACEARGn(bIsOperationCopy);
  181. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  182. {
  183. return false;
  184. }
  185. COleSafeArray Instances;
  186. CString sParentGuid;
  187. if( ! pObject->Copy(sParentGuid,Instances) )
  188. {
  189. return false;
  190. }
  191. CWbemClassObject SystemConfigObject;
  192. SystemConfigObject.Create(GetSystemName());
  193. HRESULT hr = SystemConfigObject.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG);
  194. if( ! CHECKHRESULT(hr) )
  195. {
  196. return false;
  197. }
  198. CWbemClassObject PasteMethodIn;
  199. CWbemClassObject PasteMethodOut;
  200. hr = SystemConfigObject.GetMethod(_T("Paste"),PasteMethodIn);
  201. if( ! CHECKHRESULT(hr) )
  202. {
  203. CnxDisplayErrorMsgBox(hr,GetSystemName());
  204. return false;
  205. }
  206. CString sGuid;
  207. if( GetGuid() == _T("@") )
  208. sGuid = GetGuid();
  209. else
  210. sGuid = _T("{") + GetGuid() + _T("}");
  211. PasteMethodIn.SetProperty(_T("TargetGUID"),sGuid);
  212. PasteMethodIn.SetProperty(_T("ForceReplace"),false);
  213. PasteMethodIn.SetProperty(_T("OriginalSystem"),pObject->GetSystemName());
  214. PasteMethodIn.SetProperty(_T("OriginalParentGuid"),sParentGuid);
  215. PasteMethodIn.SetProperty(_T("Instances"),Instances);
  216. hr = SystemConfigObject.ExecuteMethod(_T("Paste"),PasteMethodIn,PasteMethodOut);
  217. if( ! CHECKHRESULT(hr) )
  218. {
  219. CnxDisplayErrorMsgBox(hr,GetSystemName());
  220. return false;
  221. }
  222. // v-marfin : 60298 -----------------------------------------
  223. // If this is a move operation, delete the source object.
  224. // RemoveScopeItem instead?
  225. if (!bIsOperationCopy)
  226. {
  227. // Call the scope item's OnDelete() function which will do the
  228. // necessary cleanup etc.
  229. CHMScopeItem* pItem = (CHMScopeItem*)pObject->GetScopeItem(0);
  230. pItem->OnDelete(FALSE); // FALSE = skip the confirmation prompt
  231. }
  232. //-----------------------------------------------------------
  233. Refresh();
  234. return true;
  235. }
  236. inline bool CHMObject::QueryPaste(CHMObject* pObject)
  237. {
  238. TRACEX(_T("CHMObject::GetGuid\n"));
  239. TRACEARGn(pObject);
  240. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  241. {
  242. return false;
  243. }
  244. CString sTargetClass = GetRuntimeClass()->m_lpszClassName;
  245. CString sSourceClass = pObject->GetRuntimeClass()->m_lpszClassName;
  246. if( sTargetClass == _T("CSystemGroup") )
  247. {
  248. if( sSourceClass != _T("CSystem") )
  249. {
  250. return false;
  251. }
  252. }
  253. else if( sTargetClass == _T("CSystem") )
  254. {
  255. if( sSourceClass == _T("CSystem") || sSourceClass == _T("CSystemGroup") )
  256. {
  257. return false;
  258. }
  259. }
  260. else if( sTargetClass == _T("CDataGroup") )
  261. {
  262. if( sSourceClass == _T("CSystem") || sSourceClass == _T("CSystemGroup") )
  263. {
  264. return false;
  265. }
  266. }
  267. else if( sTargetClass == _T("CDataElement") )
  268. {
  269. if( sSourceClass != _T("CRule") )
  270. {
  271. return false;
  272. }
  273. }
  274. else if( sTargetClass == _T("CRule") )
  275. {
  276. return false;
  277. }
  278. return true;
  279. }
  280. /////////////////////////////////////////////////////////////////////////////
  281. // Operations
  282. /////////////////////////////////////////////////////////////////////////////
  283. inline CString CHMObject::GetGuid()
  284. {
  285. TRACEX(_T("CHMObject::GetGuid\n"));
  286. return m_sGUID;
  287. }
  288. inline void CHMObject::SetGuid(const CString& sGuid)
  289. {
  290. TRACEX(_T("CHMObject::SetGuid\n"));
  291. TRACEARGs(m_sGUID);
  292. m_sGUID = sGuid;
  293. if( m_sGUID[0] == _T('{') )
  294. {
  295. m_sGUID.TrimLeft(_T('{'));
  296. m_sGUID.TrimRight(_T('}'));
  297. }
  298. }
  299. inline CString CHMObject::GetName()
  300. {
  301. TRACEX(_T("CHMObject::GetName\n"));
  302. return m_sName;
  303. }
  304. inline void CHMObject::SetName(const CString& sNewName)
  305. {
  306. TRACEX(_T("CHMObject::SetName\n"));
  307. TRACEARGs(sNewName);
  308. m_sName = sNewName;
  309. }
  310. inline bool CHMObject::Rename(const CString& sNewName)
  311. {
  312. TRACEX(_T("CHMObject::Rename\n"));
  313. TRACEARGs(sNewName);
  314. if( ! GetScopeItemCount() )
  315. {
  316. return false;
  317. }
  318. // rename the WMI instance...if this object has one
  319. if( GetObjectPath().IsEmpty() ) // no object path, so just rename the scope items and the object
  320. {
  321. CHMScopeItem* pParentItem = (CHMScopeItem*)GetScopeItem(0)->GetParent();
  322. if( pParentItem )
  323. {
  324. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  325. if( pParentObject )
  326. {
  327. if( pParentObject->GetChild(sNewName) )
  328. {
  329. return false;
  330. }
  331. }
  332. }
  333. m_sName = sNewName;
  334. for(int i = 0; i < m_ScopeItems.GetSize(); i++)
  335. {
  336. m_ScopeItems[i]->SetDisplayName(0,m_sName);
  337. m_ScopeItems[i]->SetItem();
  338. }
  339. return true;
  340. }
  341. CWbemClassObject WmiInstance;
  342. if( ! CHECKHRESULT(WmiInstance.Create(GetSystemName())) )
  343. {
  344. return false;
  345. }
  346. if( ! CHECKHRESULT(WmiInstance.GetObject(GetObjectPath())) )
  347. {
  348. return false;
  349. }
  350. CHMScopeItem* pParentItem = (CHMScopeItem*)GetScopeItem(0)->GetParent();
  351. if( pParentItem )
  352. {
  353. CHMObject* pParentObject = pParentItem->GetObjectPtr();
  354. if( pParentObject )
  355. {
  356. if( pParentObject->GetChild(sNewName) )
  357. {
  358. return false;
  359. }
  360. }
  361. }
  362. WmiInstance.SetProperty(IDS_STRING_MOF_NAME,sNewName);
  363. if( ! CHECKHRESULT(WmiInstance.SaveAllProperties()) )
  364. {
  365. return false;
  366. }
  367. m_sName = sNewName;
  368. for(int i = 0; i < m_ScopeItems.GetSize(); i++)
  369. {
  370. m_ScopeItems[i]->SetDisplayName(0,m_sName);
  371. m_ScopeItems[i]->SetItem();
  372. }
  373. return true;
  374. }
  375. inline CString CHMObject::GetTypeName()
  376. {
  377. TRACEX(_T("CHMObject::GetTypeName\n"));
  378. return m_sTypeName;
  379. }
  380. inline CString CHMObject::GetUITypeName()
  381. {
  382. TRACEX(_T("CHMObject::GetUITypeName\n"));
  383. return _T("");
  384. }
  385. inline CString CHMObject::GetSystemName()
  386. {
  387. TRACEX(_T("CHMObject::GetSystemName\n"));
  388. return m_sSystemName;
  389. }
  390. inline void CHMObject::SetSystemName(const CString& sNewSystemName)
  391. {
  392. TRACEX(_T("CHMObject::SetSystemName\n"));
  393. TRACEARGs(sNewSystemName);
  394. m_sSystemName = sNewSystemName;
  395. }
  396. inline void CHMObject::ToggleStatusIcon(bool bOn /*= true*/)
  397. {
  398. TRACEX(_T("CHMObject::ToggleStatusIcon\n"));
  399. TRACEARGn(m_bStatusIconsOn);
  400. m_bStatusIconsOn = bOn;
  401. for(int i = 0; i < m_ScopeItems.GetSize(); i++)
  402. {
  403. // turn status icons on/off
  404. }
  405. }
  406. inline bool CHMObject::Refresh()
  407. {
  408. TRACEX(_T("CHMObject::Refresh\n"));
  409. for( int i = GetChildCount()-1; i >= 0; i-- )
  410. {
  411. CHMObject* pChildObject = GetChild(i);
  412. // v-marfin 59492b : Also check to see if object is a CActionPolicy ("Actions")
  413. // item since we added an object path to it before so that
  414. // handling of individual action states would work.
  415. if( pChildObject &&
  416. !pChildObject->GetObjectPath().IsEmpty() &&
  417. !pChildObject->IsActionsItem()) // 59492b
  418. {
  419. pChildObject->DestroyAllChildren();
  420. DestroyChild(i);
  421. }
  422. else
  423. {
  424. pChildObject->Refresh();
  425. }
  426. }
  427. EnumerateChildren();
  428. UpdateStatus();
  429. return true;
  430. }
  431. inline bool CHMObject::ResetStatus()
  432. {
  433. TRACEX(_T("CHMObject::ResetStatus\n"));
  434. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  435. {
  436. return false;
  437. }
  438. CWbemClassObject HMSystemConfig;
  439. HMSystemConfig.Create(GetSystemName());
  440. if( ! CHECKHRESULT(HMSystemConfig.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG)) )
  441. {
  442. return false;
  443. }
  444. int iResult = 0;
  445. CString sArgValue;
  446. if( GetGuid() == _T("@") )
  447. sArgValue.Format(_T("%s"),GetGuid());
  448. else
  449. sArgValue.Format(_T("{%s}"),GetGuid());
  450. if( ! CHECKHRESULT(HMSystemConfig.ExecuteMethod(_T("ResetDataCollectorState"),_T("TargetGUID"),sArgValue,iResult)) )
  451. {
  452. return false;
  453. }
  454. return true;
  455. }
  456. inline bool CHMObject::ResetStatistics()
  457. {
  458. TRACEX(_T("CHMObject::ResetStatistics\n"));
  459. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  460. {
  461. return false;
  462. }
  463. CWbemClassObject HMSystemConfig;
  464. HMSystemConfig.Create(GetSystemName());
  465. if( ! CHECKHRESULT(HMSystemConfig.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG)) )
  466. {
  467. return false;
  468. }
  469. int iResult = 0;
  470. CString sArgValue;
  471. if( GetGuid() == _T("@") )
  472. sArgValue.Format(_T("%s"),GetGuid());
  473. else
  474. sArgValue.Format(_T("{%s}"),GetGuid());
  475. if( ! CHECKHRESULT(HMSystemConfig.ExecuteMethod(_T("ResetDataCollectorStatistics"),_T("TargetGUID"),sArgValue,iResult)) )
  476. {
  477. return false;
  478. }
  479. return true;
  480. }
  481. inline bool CHMObject::CheckNow()
  482. {
  483. TRACEX(_T("CHMObject::ResetStatistics\n"));
  484. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  485. {
  486. return false;
  487. }
  488. CWbemClassObject HMSystemConfig;
  489. HMSystemConfig.Create(GetSystemName());
  490. if( ! CHECKHRESULT(HMSystemConfig.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG)) )
  491. {
  492. return false;
  493. }
  494. int iResult = 0;
  495. CString sArgValue;
  496. if( GetGuid() == _T("@") )
  497. sArgValue.Format(_T("%s"),GetGuid());
  498. else
  499. sArgValue.Format(_T("{%s}"),GetGuid());
  500. if( ! CHECKHRESULT(HMSystemConfig.ExecuteMethod(_T("EvaluateDataCollectorNow"),_T("TargetGUID"),sArgValue,iResult)) )
  501. {
  502. return false;
  503. }
  504. return true;
  505. }
  506. inline bool CHMObject::DeleteActionAssoc(const CString& sActionConfigGuid)
  507. {
  508. CWbemClassObject SystemConfigObject;
  509. SystemConfigObject.Create(GetSystemName());
  510. HRESULT hr = SystemConfigObject.GetObject(IDS_STRING_MOF_SYSTEM_CONFIG);
  511. if( ! CHECKHRESULT(hr) )
  512. {
  513. return false;
  514. }
  515. CWbemClassObject MethodIn;
  516. CWbemClassObject MethodOut;
  517. hr = SystemConfigObject.GetMethod(_T("DeleteConfigurationActionAssociation"),MethodIn);
  518. if( ! CHECKHRESULT(hr) )
  519. {
  520. CnxDisplayErrorMsgBox(hr,GetSystemName());
  521. return false;
  522. }
  523. CString sGuid = _T("{") + GetGuid() + _T("}");
  524. MethodIn.SetProperty(_T("TargetGUID"),sGuid);
  525. MethodIn.SetProperty(_T("ActionGUID"),sActionConfigGuid);
  526. hr = SystemConfigObject.ExecuteMethod(_T("DeleteConfigurationActionAssociation"),MethodIn,MethodOut);
  527. if( ! CHECKHRESULT(hr) )
  528. {
  529. CnxDisplayErrorMsgBox(hr,GetSystemName());
  530. return false;
  531. }
  532. return true;
  533. }
  534. inline int CHMObject::IsEnabled()
  535. {
  536. TRACEX(_T("CHMObject::IsEnabled\n"));
  537. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  538. {
  539. return false;
  540. }
  541. return( GetState() != HMS_DISABLED );
  542. }
  543. inline void CHMObject::Enable()
  544. {
  545. TRACEX(_T("CHMObject::Enable\n"));
  546. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  547. {
  548. return;
  549. }
  550. CWbemClassObject* pClassObject = GetClassObject();
  551. if( ! pClassObject )
  552. {
  553. return;
  554. }
  555. bool bEnabled = true;
  556. HRESULT hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  557. pClassObject->SaveAllProperties();
  558. delete pClassObject;
  559. if( ! CHECKHRESULT(hr) )
  560. {
  561. TRACE(_T("FAILED : CWbemClassObject::SetProperty failed.\n"));
  562. }
  563. }
  564. inline void CHMObject::Disable()
  565. {
  566. TRACEX(_T("CHMObject::Disable\n"));
  567. if( GetObjectPath().IsEmpty() ) // check if there is a WMI class associated to this object
  568. {
  569. return;
  570. }
  571. CWbemClassObject* pClassObject = GetClassObject();
  572. if( ! pClassObject )
  573. {
  574. return;
  575. }
  576. bool bEnabled = false;
  577. HRESULT hr = pClassObject->SetProperty(IDS_STRING_MOF_ENABLE,bEnabled);
  578. pClassObject->SaveAllProperties();
  579. delete pClassObject;
  580. if( ! CHECKHRESULT(hr) )
  581. {
  582. TRACE(_T("FAILED : CWbemClassObject::SetProperty failed.\n"));
  583. }
  584. }
  585. inline CTime CHMObject::GetCreateDateTime()
  586. {
  587. TRACEX(_T("CHMObject::GetCreateDateTime\n"));
  588. return m_CreateDateTime;
  589. }
  590. inline void CHMObject::GetCreateDateTime(CString& sDateTime)
  591. {
  592. TRACEX(_T("CHMObject::GetCreateDateTime\n"));
  593. TRACEARGs(sDateTime);
  594. SYSTEMTIME st;
  595. m_CreateDateTime.GetAsSystemTime(st);
  596. CString sTime;
  597. CString sDate;
  598. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,NULL,0);
  599. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  600. sTime.ReleaseBuffer();
  601. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,NULL,0);
  602. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,sDate.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  603. sDate.ReleaseBuffer();
  604. sDateTime = sDate + _T(" ") + sTime;
  605. }
  606. inline void CHMObject::SetCreateDateTime(const CTime& dtime)
  607. {
  608. TRACEX(_T("CHMObject::SetCreateDateTime\n"));
  609. m_CreateDateTime = dtime;
  610. }
  611. inline CTime CHMObject::GetModifiedDateTime()
  612. {
  613. TRACEX(_T("CHMObject::GetModifiedDateTime\n"));
  614. return m_ModifiedDateTime;
  615. }
  616. inline void CHMObject::GetModifiedDateTime(CString& sDateTime)
  617. {
  618. TRACEX(_T("CHMObject::GetModifiedDateTime\n"));
  619. TRACEARGs(sDateTime);
  620. SYSTEMTIME st;
  621. m_ModifiedDateTime.GetAsSystemTime(st);
  622. CString sTime;
  623. CString sDate;
  624. int iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,NULL,0);
  625. iLen = GetTimeFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,sTime.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  626. sTime.ReleaseBuffer();
  627. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,NULL,0);
  628. iLen = GetDateFormat(LOCALE_USER_DEFAULT,0L,&st,NULL,sDate.GetBuffer(iLen+(sizeof(TCHAR)*1)),iLen);
  629. sDate.ReleaseBuffer();
  630. sDateTime = sDate + _T(" ") + sTime;
  631. }
  632. inline void CHMObject::SetModifiedDateTime(const CTime& dtime)
  633. {
  634. TRACEX(_T("CHMObject::SetModifiedDateTime\n"));
  635. m_ModifiedDateTime = dtime;
  636. }
  637. inline CString CHMObject::GetComment()
  638. {
  639. TRACEX(_T("CHMObject::GetComment\n"));
  640. return m_sComment;
  641. }
  642. inline void CHMObject::SetComment(const CString& sComment)
  643. {
  644. TRACEX(_T("CHMObject::SetComment\n"));
  645. m_sComment = sComment;
  646. }
  647. inline void CHMObject::UpdateComment(const CString& sComment)
  648. {
  649. TRACEX(_T("CHMObject::UpdateComment\n"));
  650. SetComment(sComment);
  651. for( int i = 0; i < GetScopeItemCount(); i++ )
  652. {
  653. CStringArray& saNames = GetScopeItem(i)->GetDisplayNames();
  654. if( saNames.GetSize() > 1 )
  655. {
  656. GetScopeItem(i)->SetDisplayName((int)saNames.GetUpperBound(),sComment);
  657. GetScopeItem(i)->SetItem();
  658. }
  659. }
  660. // update the comment for the WMI instance...if this object has one
  661. if( GetObjectPath().IsEmpty() ) // no object path, so just return
  662. {
  663. return;
  664. }
  665. CWbemClassObject* pClassObject = GetClassObject();
  666. if( pClassObject )
  667. {
  668. pClassObject->SetProperty(IDS_STRING_MOF_DESCRIPTION,m_sComment);
  669. pClassObject->SaveAllProperties();
  670. delete pClassObject;
  671. }
  672. }
  673. inline void CHMObject::Serialize(CArchive& ar)
  674. {
  675. TRACEX(_T("CHMObject::Serialize\n"));
  676. CCmdTarget::Serialize(ar);
  677. if( ar.IsStoring() )
  678. {
  679. ar << GetName();
  680. }
  681. else
  682. {
  683. CString sName;
  684. ar >> sName;
  685. SetName(sName);
  686. }
  687. }
  688. /////////////////////////////////////////////////////////////////////////////
  689. // Child Members
  690. /////////////////////////////////////////////////////////////////////////////
  691. inline int CHMObject::GetChildCount(CRuntimeClass* pClass /*=NULL*/)
  692. {
  693. TRACEX(_T("CHMObject::GetChildCount\n"));
  694. TRACEARGn(pClass);
  695. if( ! pClass )
  696. {
  697. return (int)m_Children.GetSize();
  698. }
  699. int iCount = 0;
  700. for( int i = 0; i < m_Children.GetSize(); i++ )
  701. {
  702. if( m_Children[i]->IsKindOf(pClass) )
  703. {
  704. iCount++;
  705. }
  706. }
  707. return iCount;
  708. }
  709. inline int CHMObject::AddChild(CHMObject* pObject)
  710. {
  711. TRACEX(_T("CHMObject::AddChild\n"));
  712. TRACEARGn(pObject);
  713. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  714. {
  715. TRACE(_T("FAILED : pObject is not a valid pointer.\n"));
  716. return -1;
  717. }
  718. int iIndex = (int)m_Children.Add(pObject);
  719. pObject->SetScopePane(GetScopePane());
  720. for( int i = 0; i < GetScopeItemCount(); i++ )
  721. {
  722. CScopePaneItem* pItem = pObject->CreateScopeItem();
  723. if( ! pItem->Create(m_pPane,GetScopeItem(i)) )
  724. {
  725. ASSERT(FALSE);
  726. delete pItem;
  727. return -1;
  728. }
  729. pItem->SetIconIndex(pObject->GetState());
  730. pItem->SetOpenIconIndex(pObject->GetState());
  731. pItem->SetDisplayName(0,pObject->GetName());
  732. if( GfxCheckObjPtr(pItem,CHMScopeItem) )
  733. {
  734. ((CHMScopeItem*)pItem)->SetObjectPtr(pObject);
  735. }
  736. int iIndex = GetScopeItem(i)->AddChild(pItem);
  737. pItem->InsertItem(iIndex);
  738. pObject->AddScopeItem(pItem);
  739. }
  740. AddContainer(GetGuid(),pObject->GetGuid(),pObject);
  741. pObject->UpdateStatus();
  742. return iIndex;
  743. }
  744. inline bool CHMObject::CreateChild(CHMObject* pObject, const CString& sWMIClassName, const CString& sWMIAssociatorClassName)
  745. {
  746. TRACEX(_T("CHMObject::CreateChild\n"));
  747. TRACEARGn(pObject);
  748. TRACEARGs(sWMIClassName);
  749. TRACEARGs(sWMIAssociatorClassName);
  750. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  751. {
  752. return false;
  753. }
  754. pObject->SetSystemName(GetSystemName());
  755. // create the GUID
  756. GUID ChildGuid;
  757. CoCreateGuid(&ChildGuid);
  758. OLECHAR szGuid[GUID_CCH];
  759. ::StringFromGUID2(ChildGuid, szGuid, GUID_CCH);
  760. CString sGuid = OLE2CT(szGuid);
  761. pObject->SetGuid(sGuid);
  762. // Add the child
  763. AddChild(pObject);
  764. // create child instance
  765. CWbemClassObject ChildClassObject;
  766. if( ! CHECKHRESULT(ChildClassObject.Create(GetSystemName())) )
  767. {
  768. return false;
  769. }
  770. BSTR bsTemp = sWMIClassName.AllocSysString();
  771. if( ! CHECKHRESULT(ChildClassObject.CreateInstance(bsTemp)) )
  772. {
  773. ::SysFreeString(bsTemp);
  774. return false;
  775. }
  776. ::SysFreeString(bsTemp);
  777. // Save the child instance properties for name and guid
  778. ChildClassObject.SetProperty(IDS_STRING_MOF_NAME,pObject->GetName());
  779. ChildClassObject.SetProperty(IDS_STRING_MOF_GUID,sGuid);
  780. // create the association class instance
  781. CWbemClassObject Associator;
  782. if( ! CHECKHRESULT(Associator.Create(GetSystemName())) )
  783. {
  784. return false;
  785. }
  786. bsTemp = sWMIAssociatorClassName.AllocSysString();
  787. if( ! CHECKHRESULT(Associator.CreateInstance(bsTemp)) )
  788. {
  789. ::SysFreeString(bsTemp);
  790. return false;
  791. }
  792. ::SysFreeString(bsTemp);
  793. // set path properties for the association class instance
  794. Associator.SetProperty(IDS_STRING_MOF_PARENT_ASSOC,GetObjectPath());
  795. Associator.SetProperty(IDS_STRING_MOF_CHILD_ASSOC,pObject->GetObjectPath());
  796. // commit the changes to WMI
  797. ChildClassObject.SaveAllProperties();
  798. Associator.SaveAllProperties();
  799. // Add the child
  800. return true;
  801. }
  802. inline CString CHMObject::GetUniqueChildName(UINT uiFmtID /*= IDS_STRING_UNITITLED */)
  803. {
  804. TRACEX(_T("CHMObject::GetUniqueChildName\n"));
  805. CString sName;
  806. sName.LoadString(uiFmtID);
  807. sName = sName.Left(sName.GetLength()-3);
  808. while( GetChild(sName) != NULL )
  809. {
  810. sName.Format(uiFmtID,m_lNameSuffix++);
  811. }
  812. return sName;
  813. }
  814. inline CHMObject* CHMObject::GetChild(const CString& sName)
  815. {
  816. TRACEX(_T("CHMObject::GetChild\n"));
  817. for( int i = 0; i < m_Children.GetSize(); i++ )
  818. {
  819. if( m_Children[i]->GetName().CompareNoCase(sName) == 0 )
  820. {
  821. return GetChild(i);
  822. }
  823. }
  824. return NULL;
  825. }
  826. inline CHMObject* CHMObject::GetChildByGuid(const CString& sGuid)
  827. {
  828. TRACEX(_T("CHMObject::GetChildByGUID\n"));
  829. TRACEARGs(sGuid);
  830. for( int i = 0; i < m_Children.GetSize(); i++ )
  831. {
  832. if( m_Children[i]->GetGuid() == sGuid )
  833. {
  834. return GetChild(i);
  835. }
  836. }
  837. return NULL;
  838. }
  839. inline CHMObject* CHMObject::GetDescendantByGuid(const CString& sGuid)
  840. {
  841. TRACEX(_T("CHMObject::GetDescendantByGuid\n"));
  842. TRACEARGs(sGuid);
  843. for( int i = 0; i < m_Children.GetSize(); i++ )
  844. {
  845. if( m_Children[i]->GetGuid() == sGuid )
  846. {
  847. return GetChild(i);
  848. }
  849. CHMObject* pDescendantObject = m_Children[i]->GetDescendantByGuid(sGuid);
  850. if( pDescendantObject )
  851. {
  852. return pDescendantObject;
  853. }
  854. }
  855. return NULL;
  856. }
  857. inline CHMObject* CHMObject::GetChild(int iIndex)
  858. {
  859. TRACEX(_T("CHMObject::GetChild\n"));
  860. TRACEARGn(iIndex);
  861. if( iIndex >= m_Children.GetSize() || iIndex < 0 )
  862. {
  863. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  864. return NULL;
  865. }
  866. return m_Children[iIndex];
  867. }
  868. inline void CHMObject::RemoveChild(CHMObject* pObject)
  869. {
  870. TRACEX(_T("CHMObject::RemoveChild\n"));
  871. TRACEARGn(pObject);
  872. for( int i = 0; i < m_Children.GetSize(); i++ )
  873. {
  874. if( m_Children[i] == pObject )
  875. {
  876. m_Children.RemoveAt(i);
  877. return;
  878. }
  879. }
  880. }
  881. inline void CHMObject::DestroyChild(CHMObject* pChildObject, bool bDeleteClassObject /*= false*/)
  882. {
  883. TRACEX(_T("CHMObject::DestroyChild\n"));
  884. TRACEARGn(pChildObject);
  885. TRACEARGn(bDeleteClassObject);
  886. for( int i = 0; i < m_Children.GetSize(); i++ )
  887. {
  888. if( GetChild(i) == pChildObject )
  889. {
  890. DestroyChild(i,bDeleteClassObject);
  891. break;
  892. }
  893. }
  894. }
  895. inline void CHMObject::DestroyAllChildren()
  896. {
  897. TRACEX(_T("CHMObject::DestroyAllChildren\n"));
  898. for( int i = (int)m_Children.GetSize() - 1; i >= 0; i-- )
  899. {
  900. m_Children[i]->DestroyAllChildren();
  901. DestroyChild(i);
  902. }
  903. }
  904. /////////////////////////////////////////////////////////////////////////////
  905. // State Members
  906. /////////////////////////////////////////////////////////////////////////////
  907. inline void CHMObject::SetState(int iState, bool bUpdateScopeItems /*= false*/, bool bApplyToChildren /*= false*/)
  908. {
  909. TRACEX(_T("CHMObject::SetState\n"));
  910. TRACEARGn(iState);
  911. m_nState = iState;
  912. if( bUpdateScopeItems )
  913. {
  914. for( int i = 0; i < GetScopeItemCount(); i++ )
  915. {
  916. CScopePaneItem* pItem = GetScopeItem(i);
  917. if( pItem )
  918. {
  919. pItem->SetIconIndex(GetState());
  920. pItem->SetOpenIconIndex(GetState());
  921. pItem->SetItem();
  922. }
  923. }
  924. }
  925. if( bApplyToChildren )
  926. {
  927. for( int i = 0; i < GetChildCount(); i++ )
  928. {
  929. CHMObject* pObject = GetChild(i);
  930. if( pObject )
  931. {
  932. pObject->SetState(iState,bUpdateScopeItems,bApplyToChildren);
  933. }
  934. }
  935. }
  936. }
  937. inline void CHMObject::TallyChildStates()
  938. {
  939. TRACEX(_T("CHMObject::TallyChildStates\n"));
  940. m_lNormalCount = 0L;
  941. m_lWarningCount = 0L;
  942. m_lCriticalCount = 0L;
  943. m_lUnknownCount = 0L;
  944. for( int i = 0; i < m_Children.GetSize(); i++ )
  945. {
  946. switch( m_Children[i]->GetState() )
  947. {
  948. case HMS_NORMAL:
  949. {
  950. m_lNormalCount++;
  951. }
  952. break;
  953. case HMS_WARNING:
  954. {
  955. m_lWarningCount++;
  956. }
  957. break;
  958. case HMS_CRITICAL:
  959. {
  960. m_lCriticalCount++;
  961. }
  962. break;
  963. case HMS_UNKNOWN:
  964. {
  965. m_lUnknownCount++;
  966. }
  967. break;
  968. }
  969. }
  970. }
  971. /////////////////////////////////////////////////////////////////////////////
  972. // Associated Scope Pane Member
  973. /////////////////////////////////////////////////////////////////////////////
  974. inline CScopePane* CHMObject::GetScopePane()
  975. {
  976. TRACEX(_T("CHMObject::GetScopePane\n"));
  977. if( ! GfxCheckObjPtr(m_pPane,CScopePane) )
  978. {
  979. TRACE(_T("FAILED : m_pPane is not a valid pointer.\n"));
  980. return NULL;
  981. }
  982. return m_pPane;
  983. }
  984. inline void CHMObject::SetScopePane(CScopePane* pPane)
  985. {
  986. TRACEX(_T("CHMObject::SetScopePane\n"));
  987. TRACEARGn(pPane);
  988. if( ! GfxCheckObjPtr(pPane,CScopePane) )
  989. {
  990. TRACE(_T("FAILED : pPane is not a valid pointer.\n"));
  991. return;
  992. }
  993. m_pPane = pPane;
  994. }
  995. /////////////////////////////////////////////////////////////////////////////
  996. // Scope Item Members
  997. /////////////////////////////////////////////////////////////////////////////
  998. inline int CHMObject::GetScopeItemCount()
  999. {
  1000. TRACEX(_T("CHMObject::GetScopeItemCount\n"));
  1001. return (int)m_ScopeItems.GetSize();
  1002. }
  1003. inline CScopePaneItem* CHMObject::GetScopeItem(int iIndex)
  1004. {
  1005. TRACEX(_T("CHMObject::GetScopeItem\n"));
  1006. TRACEARGn(iIndex);
  1007. if( iIndex >= m_ScopeItems.GetSize() || iIndex < 0 )
  1008. {
  1009. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  1010. return NULL;
  1011. }
  1012. if( ! GfxCheckObjPtr(m_ScopeItems[iIndex],CScopePaneItem) )
  1013. {
  1014. TRACE(_T("FAILED : The Scope Pane Item pointer stored at iIndex is invalid.\n"));
  1015. return NULL;
  1016. }
  1017. return m_ScopeItems[iIndex];
  1018. }
  1019. inline int CHMObject::AddScopeItem(CScopePaneItem* pItem)
  1020. {
  1021. TRACEX(_T("CHMObject::AddScopeItem\n"));
  1022. TRACEARGn(pItem);
  1023. if( ! GfxCheckObjPtr(pItem,CScopePaneItem) )
  1024. {
  1025. TRACE(_T("FAILED : pItem is not a valid pointer.\n"));
  1026. return -1;
  1027. }
  1028. if( pItem->GetChildCount() == 0 && GetChildCount() != 0 )
  1029. {
  1030. for( int i = 0; i < m_Children.GetSize(); i++ )
  1031. {
  1032. CScopePaneItem* pNewItem = m_Children[i]->CreateScopeItem();
  1033. if( ! pNewItem->Create(m_pPane,pItem) )
  1034. {
  1035. ASSERT(FALSE);
  1036. delete pNewItem;
  1037. return -1;
  1038. }
  1039. if( m_Children[i]->GetScopeItemCount() )
  1040. {
  1041. pNewItem->SetDisplayNames(m_Children[i]->GetScopeItem(0)->GetDisplayNames());
  1042. }
  1043. else
  1044. {
  1045. pNewItem->SetDisplayName(0,m_Children[i]->GetName());
  1046. }
  1047. pNewItem->SetIconIndex(m_Children[i]->GetState());
  1048. pNewItem->SetOpenIconIndex(m_Children[i]->GetState());
  1049. int iIndex = pItem->AddChild(pNewItem);
  1050. pNewItem->InsertItem(iIndex);
  1051. m_Children[i]->AddScopeItem(pNewItem);
  1052. }
  1053. }
  1054. // make certain the new scope item has the correct icon
  1055. pItem->SetIconIndex(GetState());
  1056. pItem->SetOpenIconIndex(GetState());
  1057. return (int)m_ScopeItems.Add(pItem);
  1058. }
  1059. inline void CHMObject::RemoveScopeItem(int iIndex)
  1060. {
  1061. TRACEX(_T("CHMObject::RemoveScopeItem\n"));
  1062. TRACEARGn(iIndex);
  1063. if( iIndex >= m_ScopeItems.GetSize() || iIndex < 0 )
  1064. {
  1065. TRACE(_T("FAILED : iIndex is out of array bounds.\n"));
  1066. return;
  1067. }
  1068. if( ! GfxCheckObjPtr(m_ScopeItems[iIndex],CScopePaneItem) )
  1069. {
  1070. TRACE(_T("FAILED : The Scope Pane Item pointer stored at iIndex is invalid.\n"));
  1071. return;
  1072. }
  1073. m_ScopeItems.RemoveAt(iIndex);
  1074. }
  1075. inline void CHMObject::RemoveAllScopeItems()
  1076. {
  1077. TRACEX(_T("CHMObject::RemoveAllScopeItems\n"));
  1078. m_ScopeItems.RemoveAll();
  1079. }
  1080. inline CScopePaneItem* CHMObject::IsSelected()
  1081. {
  1082. TRACEX(_T("CHMObject::IsSelected\n"));
  1083. if( ! GetScopePane() )
  1084. {
  1085. return NULL;
  1086. }
  1087. for( int i = 0; i < GetScopeItemCount(); i++ )
  1088. {
  1089. if( m_pPane->GetSelectedScopeItem() == GetScopeItem(i) )
  1090. {
  1091. return GetScopeItem(i);
  1092. }
  1093. }
  1094. return NULL;
  1095. }