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.

2533 lines
65 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. OBJEDIT.CPP
  5. Abstract:
  6. WBEMTEST object editor classes.
  7. History:
  8. a-raymcc 12-Jun-96 Created.
  9. --*/
  10. #include "precomp.h"
  11. #include <stdio.h>
  12. #include "wbemqual.h"
  13. #include "resource.h"
  14. #include "resrc1.h"
  15. #include "objedit.h"
  16. #include "wbemtest.h"
  17. //#include <wbemutil.h>
  18. #include "textconv.h"
  19. #include <cominit.h>
  20. #include "bstring.h"
  21. #include "WT_wstring.h"
  22. #include "method.h"
  23. // following were changed due to very large SNMP properties
  24. #define LARGE_BUF 2096
  25. #define IDC_CLASS IDC_SUPERCLASS
  26. #define IDC_REFERENCES IDC_DERIVED
  27. #define IDC_ASSOCIATIONS IDC_INSTANCES
  28. extern DWORD gdwAuthLevel;
  29. extern DWORD gdwImpLevel;
  30. extern BSTR gpPrincipal;
  31. extern COAUTHIDENTITY* gpAuthIdentity;
  32. char *ValidQualifierTypes[] =
  33. {
  34. "CIM_SINT32",
  35. "CIM_STRING",
  36. "CIM_BOOLEAN",
  37. "CIM_REAL64"
  38. };
  39. void CopyQualifierSet(IWbemQualifierSet* pDest, IWbemQualifierSet* pSrc, HWND hDlg)
  40. {
  41. pSrc->BeginEnumeration(0);
  42. BSTR strName = NULL;
  43. VARIANT vVal;
  44. VariantInit(&vVal);
  45. long lFlavor;
  46. while(pSrc->Next(0, &strName, &vVal, &lFlavor) == S_OK)
  47. {
  48. if(!_wcsicmp(strName, L"cimtype") &&
  49. !_wcsicmp(V_BSTR(&vVal), L"sint32")) continue;
  50. SCODE hres = pDest->Put(strName, &vVal, lFlavor);
  51. if(FAILED(hres))
  52. {
  53. FormatError(hres, hDlg);
  54. }
  55. }
  56. }
  57. const int nNumValidQualifierTypes = sizeof(ValidQualifierTypes) / sizeof(char *);
  58. LPSTR TypeToString(CVar *p)
  59. {
  60. return TypeToString(p->GetOleType());
  61. }
  62. LPSTR LPWSTRToLPSTR(LPWSTR pWStr)
  63. {
  64. static char buf[TEMP_BUF];
  65. wcstombs(buf, pWStr, TEMP_BUF);
  66. buf[TEMP_BUF-1] = '\0';
  67. return buf;
  68. }
  69. LPSTR CTestQualifierToString(CTestQualifier *pQualifier)
  70. {
  71. static char buf[TEMP_BUF];
  72. if (pQualifier->m_pName)
  73. {
  74. wcstombs(buf, pQualifier->m_pName, TEMP_BUF);
  75. buf[TEMP_BUF-1] = '\0';
  76. }
  77. if (pQualifier->m_pValue)
  78. {
  79. strcat(buf, "\t");
  80. strcat(buf, TypeToString(pQualifier->m_pValue));
  81. strcat(buf, "\t");
  82. strcat(buf, ValueToString(pQualifier->m_pValue));
  83. }
  84. return buf;
  85. }
  86. BOOL CTestQualifierEditor::Verify()
  87. {
  88. // Get the Qualifier name.
  89. // =======================
  90. char NameBuf[TEMP_BUF];
  91. char buf[TEMP_BUF];
  92. if (GetWindowText(m_hQualifierName, NameBuf, TEMP_BUF) == 0)
  93. {
  94. MessageBox(IDS_INVALID_QUALIFIER_NAME, IDS_ERROR, MB_OK);
  95. return FALSE;
  96. }
  97. StripTrailingWs(NameBuf);
  98. delete m_pTarget->m_pName;
  99. WString Tmp(NameBuf);
  100. m_pTarget->m_pName = new wchar_t[wcslen(Tmp) + 1];
  101. wcscpy(m_pTarget->m_pName, Tmp);
  102. // Get the Qualifier flavor.
  103. // =========================
  104. m_pTarget->m_lType = 0;
  105. if (SendMessage(m_hRadioPropClass, BM_GETCHECK, 0, 0) == BST_CHECKED)
  106. m_pTarget->m_lType |= WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS;
  107. if (SendMessage(m_hRadioPropInst, BM_GETCHECK, 0, 0) == BST_CHECKED)
  108. m_pTarget->m_lType |= WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE;
  109. if (SendMessage(m_hRadioOverride, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
  110. m_pTarget->m_lType |= WBEM_FLAVOR_NOT_OVERRIDABLE;
  111. if (SendMessage(m_hRadioAmended, BM_GETCHECK, 0, 0) == BST_CHECKED)
  112. m_pTarget->m_lType |= WBEM_FLAVOR_AMENDED;
  113. // NOTE: do not retrieve origin!
  114. // Get the type string.
  115. // ====================
  116. LRESULT nIndex = SendMessage(m_hQualifierType, CB_GETCURSEL, 0, 0);
  117. if (SendMessage(m_hQualifierType, CB_GETLBTEXT, nIndex, LPARAM(buf)) == CB_ERR)
  118. {
  119. MessageBox(IDS_INVALID_QUALIFIER_TYPE, IDS_ERROR, MB_OK);
  120. return FALSE;
  121. }
  122. // Convert type string to a type.
  123. // ==============================
  124. int nType = StringToType(buf);
  125. if (nType == 0)
  126. {
  127. MessageBox(IDS_INVALID_QUALIFIER_TYPE, IDS_ERROR, MB_OK);
  128. return FALSE;
  129. }
  130. if(GetCheck(IDC_ARRAY) == BST_CHECKED)
  131. nType |= VT_ARRAY;
  132. // Get the value.
  133. // ==============
  134. if (m_pTarget->m_pValue)
  135. {
  136. m_pTarget->m_pValue->Empty();
  137. m_pTarget->m_pValue->SetAsNull();
  138. }
  139. CVar *pTemp = 0;
  140. if (GetWindowText(m_hQualifierVal, buf, TEMP_BUF))
  141. {
  142. StripTrailingWs(buf);
  143. pTemp = StringToValue(buf, nType);
  144. }
  145. else // Value is NULL
  146. {
  147. pTemp = new CVar;
  148. }
  149. if (pTemp)
  150. {
  151. if (m_pTarget->m_pValue)
  152. {
  153. *m_pTarget->m_pValue = *pTemp;
  154. delete pTemp;
  155. }
  156. else
  157. m_pTarget->m_pValue = pTemp;
  158. }
  159. else
  160. {
  161. MessageBox(IDS_INVALID_VALUE, IDS_ERROR, MB_OK);
  162. return FALSE;
  163. }
  164. return TRUE;
  165. }
  166. BOOL CTestQualifierEditor::OnInitDialog()
  167. {
  168. CenterOnParent();
  169. m_hQualifierName = GetDlgItem(IDC_ATTRIB_NAME);
  170. m_hQualifierVal = GetDlgItem(IDC_ATTRIB_VALUE);
  171. m_hQualifierType = GetDlgItem(IDC_ATTRIB_TYPE);
  172. m_hRadioPropInst = GetDlgItem(IDC_PROP_INST);
  173. m_hRadioPropClass = GetDlgItem(IDC_PROP_CLASS);
  174. m_hRadioOverride = GetDlgItem(IDC_OVERRIDE);
  175. m_hRadioPropagated = GetDlgItem(IDC_PROPAGATED);
  176. m_hRadioAmended = GetDlgItem(IDC_AMENDED);
  177. SendMessage(m_hRadioPropInst, BM_SETCHECK,
  178. (m_pTarget->m_lType & WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE)?BST_CHECKED:BST_UNCHECKED,
  179. 0);
  180. SendMessage(m_hRadioPropClass, BM_SETCHECK,
  181. (m_pTarget->m_lType & WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS)?BST_CHECKED:BST_UNCHECKED,
  182. 0);
  183. SendMessage(m_hRadioOverride, BM_SETCHECK,
  184. (m_pTarget->m_lType & WBEM_FLAVOR_NOT_OVERRIDABLE)?BST_UNCHECKED:BST_CHECKED,
  185. 0);
  186. SendMessage(m_hRadioPropagated, BM_SETCHECK,
  187. (m_pTarget->m_lType & WBEM_FLAVOR_ORIGIN_PROPAGATED)?BST_CHECKED:BST_UNCHECKED,
  188. 0);
  189. SendMessage(m_hRadioAmended, BM_SETCHECK,
  190. (m_pTarget->m_lType & WBEM_FLAVOR_AMENDED)?BST_CHECKED:BST_UNCHECKED,
  191. 0);
  192. EnableWindow(m_hRadioPropagated, FALSE);
  193. // Default property name.
  194. // ======================
  195. if (m_pTarget->m_pName)
  196. SetWindowText(m_hQualifierName, LPWSTRToLPSTR(m_pTarget->m_pName));
  197. // Populate the combo box with the valid Qualifier types
  198. // ======================================================
  199. for (int i = 0; i < nNumValidQualifierTypes; i++)
  200. SendMessage(m_hQualifierType, CB_ADDSTRING, 0, LPARAM(ValidQualifierTypes[i]));
  201. // If a type is assigned, select it.
  202. // =================================
  203. if (m_pTarget->m_pValue)
  204. {
  205. long lType = m_pTarget->m_pValue->GetOleType();
  206. LPSTR pTypeStr = TypeToString(lType & ~VT_ARRAY);
  207. SendMessage(m_hQualifierType, CB_SELECTSTRING, WPARAM(-1),
  208. LPARAM(pTypeStr));
  209. // Set the array bit
  210. // =================
  211. SetCheck(IDC_ARRAY,
  212. ((lType & VT_ARRAY) ? BST_CHECKED : BST_UNCHECKED));
  213. }
  214. // Else select VT_BSTR by default.
  215. // ===============================
  216. else
  217. {
  218. SendMessage(m_hQualifierType, CB_SELECTSTRING, WPARAM(-1), LPARAM("CIM_STRING"));
  219. }
  220. // If a value is assigned, initialize it.
  221. // ======================================
  222. if (m_pTarget->m_pValue)
  223. {
  224. LPSTR pVal = ValueToString(m_pTarget->m_pValue);
  225. SetWindowText(m_hQualifierVal, pVal);
  226. }
  227. // If editing, don't allow the user to change
  228. // the Qualifier name or type.
  229. // ==========================================
  230. if (m_bEditing)
  231. {
  232. EnableWindow(m_hQualifierName, FALSE);
  233. }
  234. return TRUE;
  235. }
  236. CTestQualifierEditor::CTestQualifierEditor(
  237. HWND hParent,
  238. CTestQualifier *pTarget,
  239. BOOL bEditing
  240. ) : CWbemDialog(IDD_ATTRIB_EDITOR, hParent)
  241. {
  242. m_pTarget = pTarget;
  243. m_bEditing = bEditing;
  244. }
  245. INT_PTR CTestQualifierEditor::Edit()
  246. {
  247. return Run();
  248. }
  249. CEmbeddedObjectListEditor::CEmbeddedObjectListEditor(HWND hParent, LONG lGenFlags, LONG lQryFlags,
  250. LPCWSTR wszPropName, CVarVector* pVarVector)
  251. : CQueryResultDlg(hParent, lGenFlags, lQryFlags), m_wsPropName((LPWSTR)wszPropName)
  252. {
  253. m_pVarVector = pVarVector;
  254. for(int i = 0; i < pVarVector->Size(); i++)
  255. {
  256. CVar vTemp;
  257. pVarVector->FillCVarAt( i, vTemp );
  258. IWbemClassObject* pObj = (IWbemClassObject*) vTemp.GetEmbeddedObject();
  259. m_InternalArray.Add(pObj);
  260. // Verify the object pointer
  261. if ( NULL != pObj )
  262. {
  263. pObj->Release();
  264. }
  265. }
  266. }
  267. CEmbeddedObjectListEditor::~CEmbeddedObjectListEditor()
  268. {
  269. // Prevent object release --- we don't own them.
  270. // =============================================
  271. }
  272. BOOL CEmbeddedObjectListEditor::OnInitDialog()
  273. {
  274. char szBuffer[1000];
  275. char szFormat[104];
  276. if(LoadString(GetModuleHandle(NULL), IDS_EMBEDDED_ARRAY, szFormat, 104))
  277. {
  278. sprintf(szBuffer, szFormat, (LPWSTR)m_wsPropName);
  279. SetTitle(szBuffer);
  280. }
  281. else
  282. SetTitle("Embedded array");
  283. BOOL bRet = CQueryResultDlg::OnInitDialog();
  284. SetComplete(WBEM_S_NO_ERROR, NULL, NULL);
  285. return bRet;
  286. }
  287. BOOL CEmbeddedObjectListEditor::Verify()
  288. {
  289. // First AddRef all elements - this is so we don't release objects
  290. // out from underneath ourselves.
  291. for(int i = 0; i < m_InternalArray.Size(); i++)
  292. {
  293. IWbemClassObject* pObj = (IWbemClassObject*)m_InternalArray[i];
  294. if ( NULL != pObj )
  295. {
  296. pObj->AddRef();
  297. }
  298. }
  299. // Now axe the elements in the Vector
  300. while(m_pVarVector->Size()) m_pVarVector->RemoveAt(0);
  301. // First AddRef all elements - this is so we don't release objects
  302. // out from underneath ourselves.
  303. for(int i = 0; i < m_InternalArray.Size(); i++)
  304. {
  305. IWbemClassObject* pObj = (IWbemClassObject*)m_InternalArray[i];
  306. CVar v;
  307. v.SetEmbeddedObject((I_EMBEDDED_OBJECT*)pObj);
  308. m_pVarVector->Add( v );
  309. }
  310. return TRUE;
  311. }
  312. IWbemClassObject* CEmbeddedObjectListEditor::AddNewElement()
  313. {
  314. return _CreateInstance(m_hDlg, m_lGenFlags, m_lSync, m_lTimeout);
  315. }
  316. BOOL CEmbeddedObjectListEditor::DeleteListElement(int nSel)
  317. {
  318. return TRUE;
  319. }
  320. //***************************************************************************
  321. //
  322. // class CTestPropertyEditor
  323. //
  324. //***************************************************************************
  325. class CTestPropertyEditor : public CWbemDialog
  326. {
  327. CTestProperty *m_pTarget;
  328. BOOL m_bEditOnly;
  329. BOOL m_bInstance;
  330. LONG m_lGenFlags; // generic WBEM_FLAG_ .. flags
  331. LONG m_lSync; // sync, async, semisync
  332. LONG m_lTimeout; // used for semisync
  333. // Control handles.
  334. // ================
  335. HWND m_hPropName;
  336. HWND m_hPropType;
  337. HWND m_hValue;
  338. HWND m_hQualifierList;
  339. public:
  340. CTestPropertyEditor(HWND hParent, LONG lGenFlags, BOOL bEditOnly, LONG lSync,
  341. CTestProperty *pProp, BOOL bInstance, LONG lTimeout);
  342. INT_PTR Edit();
  343. BOOL OnInitDialog();
  344. BOOL Verify();
  345. BOOL OnCommand(WORD wCode, WORD wID);
  346. BOOL OnDoubleClick(int nID);
  347. BOOL OnSelChange(int nID);
  348. void Refresh();
  349. void OnAddQualifier();
  350. void OnDelQualifier();
  351. void OnEditQualifier();
  352. void OnKey();
  353. void OnIndexed();
  354. void OnNotNull();
  355. void ViewEmbedding();
  356. void OnValueNull();
  357. void OnValueNotNull();
  358. void OnArray();
  359. int RemoveSysQuals();
  360. void SetSystemCheck(int nID);
  361. };
  362. void CTestPropertyEditor::OnAddQualifier()
  363. {
  364. CTestQualifier att;
  365. att.m_lType =
  366. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  367. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS;
  368. CTestQualifierEditor ed(m_hDlg, &att, FALSE);
  369. INT_PTR nRes = ed.Edit();
  370. if ((nRes == IDCANCEL) || (nRes == 0))
  371. return;
  372. // If here, the Qualifier is being added.
  373. // ======================================
  374. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  375. VARIANT *p = att.m_pValue->GetNewVariant();
  376. HRESULT hres = pQualifierSet->Put(att.m_pName, p, att.m_lType);
  377. if(FAILED(hres))
  378. {
  379. FormatError(hres, m_hDlg);
  380. }
  381. VariantClear(p);
  382. Refresh();
  383. }
  384. void CTestPropertyEditor::SetSystemCheck(int nID)
  385. {
  386. SetCheck(IDC_KEY, BST_UNCHECKED);
  387. SetCheck(IDC_INDEXED, BST_UNCHECKED);
  388. SetCheck(IDC_NOT_NULL, BST_UNCHECKED);
  389. SetCheck(IDC_NORMAL, BST_UNCHECKED);
  390. SetCheck(nID, BST_CHECKED);
  391. }
  392. int CTestPropertyEditor::RemoveSysQuals()
  393. {
  394. IWbemQualifierSet* pSet = m_pTarget->m_pQualifiers;
  395. HRESULT hres;
  396. hres = pSet->Delete(L"key");
  397. if(FAILED(hres) && hres != WBEM_E_NOT_FOUND)
  398. {
  399. SetSystemCheck(IDC_KEY);
  400. return IDC_KEY;
  401. }
  402. hres = pSet->Delete(L"indexed");
  403. if(FAILED(hres) && hres != WBEM_E_NOT_FOUND)
  404. {
  405. SetSystemCheck(IDC_INDEXED);
  406. return IDC_INDEXED;
  407. }
  408. hres = pSet->Delete(L"not_null");
  409. if(FAILED(hres) && hres != WBEM_E_NOT_FOUND)
  410. {
  411. SetSystemCheck(IDC_NOT_NULL);
  412. return IDC_NOT_NULL;
  413. }
  414. return 0;
  415. }
  416. void CTestPropertyEditor::OnIndexed()
  417. {
  418. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  419. int nRes = RemoveSysQuals();
  420. if(nRes != 0)
  421. {
  422. MessageBox(IDS_CANNOT_CHANGE_SYSTEM_QUALS, IDS_ERROR, MB_OK);
  423. return;
  424. }
  425. VARIANT v;
  426. V_VT(&v) = VT_BOOL;
  427. V_BOOL(&v) = VARIANT_TRUE;
  428. HRESULT hres = pQualifierSet->Put(L"indexed",
  429. &v,
  430. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  431. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS);
  432. if(FAILED(hres))
  433. {
  434. MessageBox(IDS_MAY_NOT_SPECIFY_INDEXED, IDS_ERROR,
  435. MB_OK | MB_ICONSTOP);
  436. SetSystemCheck(IDC_NORMAL);
  437. }
  438. }
  439. void CTestPropertyEditor::OnKey()
  440. {
  441. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  442. int nRes = RemoveSysQuals();
  443. if(nRes != 0)
  444. {
  445. MessageBox(IDS_CANNOT_CHANGE_SYSTEM_QUALS, IDS_ERROR, MB_OK);
  446. return;
  447. }
  448. VARIANT v;
  449. V_VT(&v) = VT_BOOL;
  450. V_BOOL(&v) = VARIANT_TRUE;
  451. HRESULT hres = pQualifierSet->Put(L"key",
  452. &v,
  453. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  454. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS);
  455. if(FAILED(hres) && hres == WBEM_E_CANNOT_BE_KEY)
  456. {
  457. MessageBox(IDS_MAY_NOT_SPECIFY_KEY, IDS_ERROR,
  458. MB_OK | MB_ICONSTOP);
  459. SetSystemCheck(IDC_NORMAL);
  460. }
  461. }
  462. void CTestPropertyEditor::OnNotNull()
  463. {
  464. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  465. int nRes = RemoveSysQuals();
  466. if(nRes != 0)
  467. {
  468. MessageBox(IDS_CANNOT_CHANGE_SYSTEM_QUALS, IDS_ERROR, MB_OK);
  469. return;
  470. }
  471. VARIANT v;
  472. V_VT(&v) = VT_BOOL;
  473. V_BOOL(&v) = VARIANT_TRUE;
  474. HRESULT hres = pQualifierSet->Put(L"not_null",
  475. &v,
  476. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  477. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS);
  478. if(FAILED(hres))
  479. {
  480. MessageBox(IDS_MAY_NOT_SPECIFY_NOT_NULL, IDS_ERROR,
  481. MB_OK | MB_ICONSTOP);
  482. SetSystemCheck(IDC_NORMAL);
  483. }
  484. }
  485. void CTestPropertyEditor::OnEditQualifier()
  486. {
  487. // See if anything is selected.
  488. // ============================
  489. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  490. if (nSel == LB_ERR)
  491. return;
  492. char buf[TEMP_BUF];
  493. *buf = 0;
  494. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf));
  495. if (*buf == 0)
  496. return;
  497. // At this point, the text of the selected Qualifier is in <buf>.
  498. // ==============================================================
  499. char name[TEMP_BUF];
  500. *name = 0;
  501. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  502. return;
  503. if (*name == 0)
  504. return;
  505. WString WName = name;
  506. // Find the Qualifier in question.
  507. // ===============================
  508. VARIANT v;
  509. VariantInit(&v);
  510. LONG lType = 0;
  511. IWbemQualifierSet* pQualifierSet = m_pTarget->m_pQualifiers;
  512. CBString bsWName(WName);
  513. SCODE res = pQualifierSet->Get(bsWName.GetString(), 0, &v, &lType);
  514. if (res != 0)
  515. {
  516. MessageBox(IDS_QUALIFIER_NOT_FOUND, IDS_CRITICAL_ERROR, MB_OK);
  517. return;
  518. }
  519. // If here, convert temporarily to a CTestQualifier object for the duration of
  520. // the edit.
  521. // ====================================================================
  522. CVar *pNewVal = new CVar;
  523. pNewVal->SetVariant(&v);
  524. VariantClear(&v);
  525. CTestQualifier att;
  526. att.m_pValue = pNewVal;
  527. att.m_pName = new wchar_t[wcslen(WName) + 1];
  528. wcscpy(att.m_pName, WName);
  529. att.m_lType = lType;
  530. CTestQualifierEditor ed(m_hDlg, &att, TRUE);
  531. INT_PTR nRes = ed.Edit();
  532. if ((nRes == IDCANCEL) || (nRes == 0))
  533. {
  534. return;
  535. }
  536. // If here, the Qualifier is being added.
  537. // ======================================
  538. VARIANT *p = att.m_pValue->GetNewVariant();
  539. CBString bsName(att.m_pName);
  540. res = pQualifierSet->Put(bsName.GetString(), p, att.m_lType);
  541. if(FAILED(res))
  542. {
  543. FormatError(res, m_hDlg);
  544. }
  545. VariantClear(p);
  546. Refresh();
  547. }
  548. //ok
  549. void CTestPropertyEditor::OnDelQualifier()
  550. {
  551. // See if anything is selected.
  552. // ============================
  553. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  554. if (nSel == LB_ERR)
  555. return;
  556. char buf[TEMP_BUF];
  557. *buf = 0;
  558. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf));
  559. if (*buf == 0)
  560. return;
  561. // At this point, the text of the selected Qualifier is in <buf>.
  562. // ==============================================================
  563. char name[TEMP_BUF];
  564. *name = 0;
  565. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  566. return;
  567. if (*name == 0)
  568. return;
  569. WString WName = name;
  570. // Remove the Qualifier.
  571. // =====================
  572. IWbemQualifierSet *pQualifierSet = m_pTarget->m_pQualifiers;
  573. CBString bsName(WName);
  574. HRESULT hres = pQualifierSet->Delete(bsName.GetString());
  575. if(FAILED(hres) || hres != 0)
  576. {
  577. FormatError(hres, m_hDlg);
  578. }
  579. Refresh();
  580. }
  581. void CTestPropertyEditor::Refresh()
  582. {
  583. // Zap the current contents.
  584. // =========================
  585. SendMessage(m_hQualifierList, LB_RESETCONTENT, 0, 0);
  586. SetCheck(IDC_KEY, BST_UNCHECKED);
  587. SetCheck(IDC_INDEXED, BST_UNCHECKED);
  588. SetCheck(IDC_NOT_NULL, BST_UNCHECKED);
  589. SetCheck(IDC_NORMAL, BST_CHECKED);
  590. // Fill in the Qualifier list.
  591. // ===========================
  592. IWbemQualifierSet *pQualifiers = m_pTarget->m_pQualifiers;
  593. if(pQualifiers == NULL)
  594. {
  595. EnableWindow(m_hQualifierList, FALSE);
  596. EnableWindow(GetDlgItem(IDC_KEY), FALSE);
  597. EnableWindow(GetDlgItem(IDC_INDEXED), FALSE);
  598. EnableWindow(GetDlgItem(IDC_NOT_NULL), FALSE);
  599. EnableWindow(GetDlgItem(IDC_NORMAL), FALSE);
  600. EnableWindow(GetDlgItem(IDC_ADD_ATTRIB), FALSE);
  601. EnableWindow(GetDlgItem(IDC_EDIT_ATTRIB), FALSE);
  602. EnableWindow(GetDlgItem(IDC_DELETE_ATTRIB), FALSE);
  603. EnableWindow(GetDlgItem(IDC_STATIC_QUAL), FALSE);
  604. }
  605. if (pQualifiers)
  606. {
  607. pQualifiers->BeginEnumeration(0);
  608. BSTR strName = NULL;
  609. long lFlavor;
  610. VARIANT vVal;
  611. VariantInit(&vVal);
  612. while(pQualifiers->Next(0, &strName, &vVal, &lFlavor) == S_OK)
  613. {
  614. if(!_wcsicmp(strName, L"key"))
  615. {
  616. SetSystemCheck(IDC_KEY);
  617. SysFreeString(strName);
  618. strName = NULL;
  619. continue;
  620. }
  621. else if(!_wcsicmp(strName, L"indexed"))
  622. {
  623. if(GetCheck(IDC_KEY) == BST_UNCHECKED)
  624. {
  625. SetSystemCheck(IDC_INDEXED);
  626. }
  627. SysFreeString(strName);
  628. strName = NULL;
  629. continue;
  630. }
  631. else if(!_wcsicmp(strName, L"not_null"))
  632. {
  633. if(GetCheck(IDC_KEY) == BST_UNCHECKED &&
  634. GetCheck(IDC_INDEXED) == BST_UNCHECKED)
  635. {
  636. SetSystemCheck(IDC_NOT_NULL);
  637. }
  638. SysFreeString(strName);
  639. strName = NULL;
  640. continue;
  641. }
  642. CTestQualifier A;
  643. A.m_pName = new wchar_t[wcslen(strName) + 1];
  644. wcscpy(A.m_pName, strName);
  645. A.m_pValue = new CVar(&vVal);
  646. A.m_lType = lFlavor;
  647. // Build list box string.
  648. // ======================
  649. SendMessage(m_hQualifierList, LB_ADDSTRING, 0,LPARAM(CTestQualifierToString(&A)));
  650. VariantClear(&vVal);
  651. SysFreeString(strName);
  652. strName = NULL;
  653. }
  654. pQualifiers->EndEnumeration();
  655. VariantClear(&vVal);
  656. }
  657. }
  658. BOOL CTestPropertyEditor::OnDoubleClick(int nID)
  659. {
  660. if(nID == IDC_ATTRIB_LIST)
  661. {
  662. OnEditQualifier();
  663. return TRUE;
  664. }
  665. return FALSE;
  666. }
  667. BOOL CTestPropertyEditor::OnSelChange(int nID)
  668. {
  669. if(nID == IDC_TYPE_LIST)
  670. {
  671. char* pszType = GetCBCurSelString(IDC_TYPE_LIST);
  672. BOOL bArray = (GetCheck(IDC_ARRAY) == BST_CHECKED);
  673. m_pTarget->m_lType = StringToType(pszType);
  674. if(bArray)
  675. m_pTarget->m_lType |= VT_ARRAY;
  676. if((m_pTarget->m_lType & ~VT_ARRAY) == VT_EMBEDDED_OBJECT)
  677. {
  678. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_SHOW);
  679. }
  680. else
  681. {
  682. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_HIDE);
  683. }
  684. delete [] pszType;
  685. }
  686. return TRUE;
  687. }
  688. BOOL CTestPropertyEditor::OnCommand(WORD wCode, WORD wID)
  689. {
  690. switch(wID)
  691. {
  692. case IDC_EDIT_ATTRIB: OnEditQualifier(); return TRUE;
  693. case IDC_ADD_ATTRIB: OnAddQualifier(); return TRUE;
  694. case IDC_DELETE_ATTRIB: OnDelQualifier(); return TRUE;
  695. case IDC_KEY:
  696. if(wCode == BN_CLICKED)
  697. OnKey();
  698. return TRUE;
  699. case IDC_INDEXED:
  700. if(wCode == BN_CLICKED)
  701. OnIndexed();
  702. return TRUE;
  703. case IDC_NOT_NULL:
  704. if(wCode == BN_CLICKED)
  705. OnNotNull();
  706. return TRUE;
  707. case IDC_NORMAL:
  708. if(wCode == BN_CLICKED)
  709. RemoveSysQuals();
  710. return TRUE;
  711. case IDC_VALUE_NULL:
  712. OnValueNull();
  713. return TRUE;
  714. case IDC_VALUE_NOT_NULL:
  715. OnValueNotNull();
  716. return TRUE;
  717. case IDC_EMBEDDING:
  718. ViewEmbedding();
  719. return TRUE;
  720. case IDC_ARRAY:
  721. OnArray();
  722. return TRUE;
  723. }
  724. return TRUE;
  725. }
  726. void CTestPropertyEditor::OnArray()
  727. {
  728. if(GetCheck(IDC_ARRAY) == BST_CHECKED)
  729. m_pTarget->m_lType |= VT_ARRAY;
  730. else
  731. m_pTarget->m_lType &= ~VT_ARRAY;
  732. }
  733. void CTestPropertyEditor::OnValueNull()
  734. {
  735. if((m_pTarget->m_lType & ~VT_ARRAY) == VT_EMBEDDED_OBJECT)
  736. {
  737. if(MessageBox(IDS_SAVE_EMBEDDING, IDS_WARNING,
  738. MB_ICONQUESTION | MB_YESNO) == IDYES)
  739. {
  740. SetCheck(IDC_VALUE_NULL, BST_UNCHECKED);
  741. SetCheck(IDC_VALUE_NOT_NULL, BST_CHECKED);
  742. return;
  743. }
  744. else
  745. {
  746. delete m_pTarget->m_pValue;
  747. m_pTarget->m_pValue = NULL;
  748. SetDlgItemText(IDC_VALUE, "");
  749. }
  750. }
  751. EnableWindow(m_hValue, FALSE);
  752. EnableWindow(GetDlgItem(IDC_EMBEDDING), FALSE);
  753. }
  754. void CTestPropertyEditor::OnValueNotNull()
  755. {
  756. if((m_pTarget->m_lType & ~VT_ARRAY) != VT_EMBEDDED_OBJECT)
  757. {
  758. EnableWindow(m_hValue, TRUE);
  759. }
  760. EnableWindow(GetDlgItem(IDC_EMBEDDING), TRUE);
  761. }
  762. BOOL CTestPropertyEditor::OnInitDialog()
  763. {
  764. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_HIDE);
  765. CenterOnParent();
  766. m_hPropName = GetDlgItem(IDC_PROPNAME);
  767. m_hPropType = GetDlgItem(IDC_TYPE_LIST);
  768. m_hValue = GetDlgItem(IDC_VALUE);
  769. m_hQualifierList = GetDlgItem(IDC_ATTRIB_LIST);
  770. LONG Tabs[] = { 80, 140, 170 };
  771. int TabCount = 3;
  772. SendMessage(m_hQualifierList, LB_SETTABSTOPS,
  773. (WPARAM) TabCount, (LPARAM) Tabs);
  774. // Populate the combo box with the valid prop types
  775. // ================================================
  776. for (int i = 0; i < g_nNumValidPropTypes; i++)
  777. SendMessage(m_hPropType, CB_ADDSTRING, 0, LPARAM(g_aValidPropTypes[i]));
  778. SendMessage(m_hPropType, CB_SELECTSTRING, WPARAM(-1), LPARAM("CIM_STRING"));
  779. // Now initialize the controls with the contents of the
  780. // current object, if any.
  781. // ====================================================
  782. if (m_pTarget->m_pName)
  783. {
  784. SetWindowText(m_hPropName, LPWSTRToLPSTR(m_pTarget->m_pName));
  785. }
  786. if(m_pTarget->m_pClass)
  787. {
  788. SetDlgItemText(IDC_ORIGIN, LPWSTRToLPSTR(m_pTarget->m_pClass));
  789. }
  790. // If the value is available, set the text and select.
  791. // ===================================================
  792. if (m_pTarget->m_pValue)
  793. {
  794. LPSTR pTypeStr = TypeToString(m_pTarget->m_lType & ~VT_ARRAY);
  795. SendMessage(m_hPropType, CB_SELECTSTRING, WPARAM(-1), LPARAM(pTypeStr));
  796. if(m_pTarget->m_lType & VT_ARRAY)
  797. SetCheck(IDC_ARRAY, BST_CHECKED);
  798. else
  799. SetCheck(IDC_ARRAY, BST_UNCHECKED);
  800. if((m_pTarget->m_lType & ~VT_ARRAY) == VT_EMBEDDED_OBJECT)
  801. {
  802. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_SHOW);
  803. }
  804. if(m_pTarget->m_pValue->IsNull())
  805. {
  806. SetCheck(IDC_VALUE_NULL, BST_CHECKED);
  807. EnableWindow(m_hValue, FALSE);
  808. EnableWindow(GetDlgItem(IDC_EMBEDDING), FALSE);
  809. }
  810. else
  811. {
  812. SetCheck(IDC_VALUE_NOT_NULL, BST_CHECKED);
  813. LPSTR pValStr = ValueToNewString(m_pTarget->m_pValue,
  814. m_pTarget->m_lType);
  815. SetWindowText(m_hValue, pValStr);
  816. delete [] pValStr;
  817. EnableWindow(m_hValue, strstr(pTypeStr, "VT_EMBEDDED_OBJECT")
  818. == NULL);
  819. }
  820. }
  821. else
  822. {
  823. SetCheck(IDC_VALUE_NULL, BST_CHECKED);
  824. SendMessage(m_hPropType, CB_SELECTSTRING, WPARAM(-1), LPARAM("VT_BSTR"));
  825. EnableWindow(m_hValue, FALSE);
  826. EnableWindow(GetDlgItem(IDC_EMBEDDING), FALSE);
  827. }
  828. // Refresh the Qualifiers.
  829. // =======================
  830. Refresh();
  831. // If editing, don't allow type/name change.
  832. // =========================================
  833. if (m_bEditOnly)
  834. {
  835. EnableWindow(m_hPropName, FALSE);
  836. EnableWindow(m_hPropType, FALSE);
  837. }
  838. if(m_bInstance)
  839. {
  840. EnableWindow(GetDlgItem(IDC_KEY), FALSE);
  841. EnableWindow(GetDlgItem(IDC_INDEXED), FALSE);
  842. EnableWindow(GetDlgItem(IDC_NOT_NULL), FALSE);
  843. EnableWindow(GetDlgItem(IDC_NORMAL), FALSE);
  844. }
  845. return TRUE;
  846. }
  847. void CTestPropertyEditor::ViewEmbedding()
  848. {
  849. if(m_pTarget->m_lType == VT_EMBEDDED_OBJECT)
  850. {
  851. if(m_pTarget->m_pValue != NULL &&
  852. m_pTarget->m_pValue->GetType() != VT_EMBEDDED_OBJECT)
  853. {
  854. delete m_pTarget->m_pValue;
  855. m_pTarget->m_pValue = NULL;
  856. }
  857. if(m_pTarget->m_pValue == NULL)
  858. {
  859. m_pTarget->m_pValue = new CVar;
  860. m_pTarget->m_pValue->SetEmbeddedObject(NULL);
  861. }
  862. IWbemClassObject* pCurrentEmbed =
  863. (IWbemClassObject*)m_pTarget->m_pValue->GetEmbeddedObject();
  864. IWbemClassObject* pEmbed;
  865. if(pCurrentEmbed == NULL)
  866. {
  867. pEmbed = PreCreateInstance(m_hDlg, m_lGenFlags, m_lSync, m_lTimeout);
  868. if(pEmbed == NULL) return;
  869. }
  870. else
  871. {
  872. pCurrentEmbed->Clone(&pEmbed);
  873. pCurrentEmbed->Release();
  874. }
  875. CObjectEditor ed(m_hDlg, m_lGenFlags, CObjectEditor::readwrite, m_lSync,
  876. pEmbed, m_lTimeout);
  877. if(ed.Edit() == IDOK)
  878. {
  879. m_pTarget->m_pValue->SetEmbeddedObject(pEmbed);
  880. SetDlgItemText(IDC_VALUE, "<embedded object>");
  881. }
  882. pEmbed->Release();
  883. }
  884. else if(m_pTarget->m_lType == (VT_EMBEDDED_OBJECT | VT_ARRAY))
  885. {
  886. if(m_pTarget->m_pValue != NULL &&
  887. m_pTarget->m_pValue->GetType() != VT_EX_CVARVECTOR)
  888. {
  889. delete m_pTarget->m_pValue;
  890. m_pTarget->m_pValue = NULL;
  891. }
  892. if(m_pTarget->m_pValue == NULL)
  893. {
  894. m_pTarget->m_pValue = new CVar;
  895. CVarVector* pvv = new CVarVector(VT_EMBEDDED_OBJECT);
  896. m_pTarget->m_pValue->SetVarVector(pvv, TRUE);
  897. }
  898. CVarVector* pCurrentEmbed = m_pTarget->m_pValue->GetVarVector();
  899. CEmbeddedObjectListEditor ed(m_hDlg, m_lGenFlags, 0, m_pTarget->m_pName,
  900. pCurrentEmbed);
  901. // Pass on invocation method (sync, async..) related settings for use
  902. // by any further operations (editing/deleting/etc. of an instance).
  903. ed.SetCallMethod(m_lSync);
  904. ed.SetTimeout(m_lTimeout);
  905. ed.Run();
  906. SetDlgItemText(IDC_VALUE, "<array of embedded objects>");
  907. }
  908. else
  909. {
  910. ShowWindow(GetDlgItem(IDC_EMBEDDING), SW_HIDE);
  911. }
  912. }
  913. BOOL CTestPropertyEditor::Verify()
  914. {
  915. // Buffer is used for property name, value string (which can be long if an array), and type string).
  916. // Find the largest of the three for buffer length (TEMP_BUF size is used for type).
  917. int buflen = max(max(GetWindowTextLength(m_hPropName), GetWindowTextLength(m_hValue)) + 1, TEMP_BUF);
  918. char* buf = new char[buflen];
  919. // Verify that name is present.
  920. // ============================
  921. if (GetWindowText(m_hPropName, buf, buflen) == 0)
  922. {
  923. MessageBox(IDS_NO_PROPERTY_NAME, IDS_ERROR, MB_OK);
  924. delete [] buf;
  925. return FALSE;
  926. }
  927. StripTrailingWs(buf);
  928. WString Name = buf;
  929. if (m_pTarget->m_pName)
  930. delete m_pTarget->m_pName;
  931. m_pTarget->m_pName = new wchar_t[wcslen(Name) + 1];
  932. wcscpy(m_pTarget->m_pName, Name);
  933. // Get the type.
  934. // =============
  935. LRESULT nIndex = SendMessage(m_hPropType, CB_GETCURSEL, 0, 0);
  936. if (SendMessage(m_hPropType, CB_GETLBTEXT, nIndex, LPARAM(buf)) == CB_ERR)
  937. {
  938. MessageBox(IDS_INVALID_PROPERTY_TYPE, IDS_ERROR, MB_OK);
  939. delete [] buf;
  940. return FALSE;
  941. }
  942. // Convert type string to a type.
  943. // ==============================
  944. int nType = StringToType(buf);
  945. if(GetCheck(IDC_ARRAY) == BST_CHECKED)
  946. nType |= VT_ARRAY;
  947. if (nType == 0)
  948. {
  949. MessageBox(IDS_INVALID_PROPERTY_TYPE, IDS_ERROR, MB_OK);
  950. delete [] buf;
  951. return FALSE;
  952. }
  953. m_pTarget->m_lType = nType;
  954. // Verify that Value is present.
  955. // =============================
  956. CVar *p;
  957. if(GetCheck(IDC_VALUE_NULL) == BST_CHECKED)
  958. {
  959. p = new CVar;
  960. p->SetAsNull();
  961. }
  962. else
  963. {
  964. *buf = 0;
  965. GetWindowText(m_hValue, buf, buflen);
  966. StripTrailingWs(buf);
  967. // Convert value string to the correct value.
  968. // ==========================================
  969. if((nType & ~VT_ARRAY) != VT_EMBEDDED_OBJECT)
  970. {
  971. p = StringToValue(buf, nType);
  972. }
  973. else
  974. {
  975. // otherwise already there
  976. p = m_pTarget->m_pValue;
  977. }
  978. }
  979. if (!p)
  980. {
  981. MessageBox(IDS_INVALID_PROPERTY_VALUE, IDS_ERROR, MB_OK);
  982. delete [] buf;
  983. return FALSE;
  984. }
  985. if(m_pTarget->m_pValue != p)
  986. {
  987. if (m_pTarget->m_pValue)
  988. delete m_pTarget->m_pValue;
  989. m_pTarget->m_pValue = p;
  990. }
  991. delete [] buf;
  992. return TRUE;
  993. }
  994. CTestPropertyEditor::CTestPropertyEditor(HWND hParent, LONG lGenFlags, BOOL bEditOnly, LONG lSync,
  995. CTestProperty* pProp, BOOL bInstance, LONG lTimeout)
  996. : CWbemDialog(IDD_PROPERTY_EDITOR, hParent)
  997. {
  998. m_pTarget = pProp;
  999. m_lGenFlags = lGenFlags;
  1000. m_bEditOnly = bEditOnly;
  1001. m_lSync = lSync;
  1002. m_bInstance = bInstance;
  1003. m_lTimeout = lTimeout;
  1004. }
  1005. INT_PTR CTestPropertyEditor::Edit()
  1006. {
  1007. return Run();
  1008. }
  1009. void CObjectEditor::OnAddQualifier()
  1010. {
  1011. CTestQualifier att;
  1012. att.m_lType = WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  1013. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS;
  1014. CTestQualifierEditor ed(m_hDlg, &att, FALSE);
  1015. INT_PTR nRes = ed.Edit();
  1016. if ((nRes == IDCANCEL) || (nRes == 0))
  1017. return;
  1018. // If here, the Qualifier is being added.
  1019. // ======================================
  1020. IWbemQualifierSet* pQualifierSet = 0;
  1021. m_pObj->GetQualifierSet(&pQualifierSet);
  1022. VARIANT *p = att.m_pValue->GetNewVariant();
  1023. CBString bsName(att.m_pName);
  1024. /*
  1025. DWORD dwFlavor =
  1026. WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE |
  1027. WBEM_FLAVOR_FLAG_PROPAGATE_TO_DERIVED_CLASS;
  1028. */
  1029. HRESULT hres = pQualifierSet->Put(bsName.GetString(), p, att.m_lType);
  1030. if(FAILED(hres))
  1031. {
  1032. FormatError(hres, m_hDlg);
  1033. }
  1034. VariantClear(p);
  1035. pQualifierSet->Release();
  1036. Refresh();
  1037. }
  1038. void CObjectEditor::OnEditQualifier()
  1039. {
  1040. // See if anything is selected.
  1041. // ============================
  1042. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  1043. if (nSel == LB_ERR)
  1044. return;
  1045. char buf[TEMP_BUF];
  1046. *buf = 0;
  1047. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf));
  1048. if (*buf == 0)
  1049. return;
  1050. // At this point, the text of the selected Qualifier is in <buf>.
  1051. // ==============================================================
  1052. char name[TEMP_BUF];
  1053. *name = 0;
  1054. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  1055. return;
  1056. if (*name == 0)
  1057. return;
  1058. WString WName = name;
  1059. // Find the Qualifier in question.
  1060. // ===============================
  1061. IWbemQualifierSet* pQualifierSet = 0;
  1062. VARIANT v;
  1063. VariantInit(&v);
  1064. LONG lType = 0;
  1065. m_pObj->GetQualifierSet(&pQualifierSet);
  1066. SCODE res = pQualifierSet->Get(WName, 0, &v, &lType);
  1067. if (res != 0)
  1068. {
  1069. MessageBox(IDS_QUALIFIER_NOT_FOUND, IDS_CRITICAL_ERROR, MB_OK);
  1070. pQualifierSet->Release();
  1071. return;
  1072. }
  1073. // If here, convert temporarily to a CTestQualifier object for the duration of
  1074. // the edit.
  1075. // ====================================================================
  1076. CVar *pNewVal = new CVar;
  1077. pNewVal->SetVariant(&v);
  1078. VariantClear(&v);
  1079. CTestQualifier att;
  1080. att.m_pValue = pNewVal;
  1081. att.m_pName = new wchar_t[wcslen(WName) + 1];
  1082. wcscpy(att.m_pName, WName);
  1083. att.m_lType = lType;
  1084. CTestQualifierEditor ed(m_hDlg, &att, TRUE);
  1085. INT_PTR nRes = ed.Edit();
  1086. if ((nRes == IDCANCEL) || (nRes == 0))
  1087. {
  1088. pQualifierSet->Release();
  1089. return;
  1090. }
  1091. // If here, the Qualifier is being added.
  1092. // ======================================
  1093. m_pObj->GetQualifierSet(&pQualifierSet);
  1094. VARIANT *p = att.m_pValue->GetNewVariant();
  1095. CBString bsName(att.m_pName);
  1096. res = pQualifierSet->Put(bsName.GetString(), p, att.m_lType);
  1097. if(FAILED(res))
  1098. {
  1099. FormatError(res, m_hDlg);
  1100. }
  1101. VariantClear(p);
  1102. pQualifierSet->Release();
  1103. Refresh();
  1104. }
  1105. //
  1106. //
  1107. // Called when deleting an Qualifier on the object itself.
  1108. //
  1109. void CObjectEditor::OnDelQualifier()
  1110. {
  1111. // See if anything is selected.
  1112. // ============================
  1113. LRESULT nSel = SendMessage(m_hQualifierList, LB_GETCURSEL, 0, 0);
  1114. if (nSel == LB_ERR)
  1115. return;
  1116. char buf[TEMP_BUF];
  1117. *buf = 0;
  1118. SendMessage(m_hQualifierList, LB_GETTEXT, nSel, LPARAM(buf));
  1119. if (*buf == 0)
  1120. return;
  1121. // At this point, the text of the selected Qualifier is in <buf>.
  1122. // ==============================================================
  1123. char name[TEMP_BUF];
  1124. *name = 0;
  1125. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  1126. return;
  1127. if (*name == 0)
  1128. return;
  1129. WString WName = name;
  1130. // Remove the Qualifier.
  1131. // =====================
  1132. IWbemQualifierSet *pQualifierSet;
  1133. m_pObj->GetQualifierSet(&pQualifierSet);
  1134. HRESULT hres = pQualifierSet->Delete(WName);
  1135. if(FAILED(hres) || hres != 0)
  1136. {
  1137. FormatError(hres, m_hDlg);
  1138. }
  1139. pQualifierSet->Release();
  1140. Refresh();
  1141. }
  1142. void CObjectEditor::OnAddProp()
  1143. {
  1144. HRESULT hres;
  1145. // Add a dummy property for now
  1146. // ============================
  1147. VARIANT v;
  1148. VariantInit(&v);
  1149. V_VT(&v) = VT_I4;
  1150. V_I4(&v) = 1;
  1151. CBString bsTemp(L"DUMMY_PROPERTY__D");
  1152. if(FAILED(m_pObj->Put(bsTemp.GetString(), 0, &v, 0)))
  1153. {
  1154. MessageBox(NULL, IDS_CANNOT_ADD_PROPERTIES, IDS_ERROR, MB_OK|MB_ICONSTOP);
  1155. return;
  1156. }
  1157. IWbemQualifierSet* pQualifierSet;
  1158. m_pObj->GetPropertyQualifierSet(bsTemp.GetString(), &pQualifierSet);
  1159. // Create CTestProperty with the dummy attr set for now
  1160. // ================================================
  1161. CTestProperty prop(pQualifierSet);
  1162. VariantClear(&v);
  1163. hres = m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL);
  1164. if (hres != S_OK || V_VT(&v) != VT_BSTR )
  1165. {
  1166. prop.m_pClass = new wchar_t[wcslen(L"Unknown") + 1];
  1167. wcscpy(prop.m_pClass, L"Unknown");
  1168. }
  1169. else
  1170. {
  1171. prop.m_pClass = new wchar_t[wcslen(V_BSTR(&v)) + 1];
  1172. wcscpy(prop.m_pClass, V_BSTR(&v));
  1173. VariantClear(&v);
  1174. }
  1175. CTestPropertyEditor ed(m_hDlg, m_lGenFlags, FALSE, m_lSync, &prop, FALSE,
  1176. m_lTimeout);
  1177. INT_PTR nRes = ed.Edit();
  1178. if ((nRes == IDCANCEL) || (nRes == 0))
  1179. {
  1180. pQualifierSet->Release();
  1181. m_pObj->Delete(bsTemp.GetString());
  1182. return;
  1183. }
  1184. // Set the property
  1185. // ================
  1186. VARIANT* pVariant = prop.m_pValue->GetNewVariant();
  1187. bsTemp = prop.m_pName;
  1188. VARTYPE vtType;
  1189. if(m_bClass)
  1190. {
  1191. vtType = (VARTYPE)prop.m_lType;
  1192. }
  1193. else
  1194. {
  1195. vtType = 0;
  1196. }
  1197. hres = m_pObj->Put(bsTemp.GetString(), 0, pVariant, vtType);
  1198. VariantClear(pVariant);
  1199. if(FAILED(hres))
  1200. {
  1201. FormatError(hres, m_hDlg);
  1202. return;
  1203. }
  1204. // Copy the Qualifiers
  1205. // ===================
  1206. IWbemQualifierSet* pRealQualifierSet;
  1207. bsTemp = prop.m_pName;
  1208. m_pObj->GetPropertyQualifierSet(bsTemp.GetString(), &pRealQualifierSet);
  1209. CopyQualifierSet(pRealQualifierSet, pQualifierSet, m_hDlg);
  1210. pQualifierSet->EndEnumeration();
  1211. pQualifierSet->Release();
  1212. pRealQualifierSet->Release();
  1213. bsTemp = L"DUMMY_PROPERTY__D";
  1214. m_pObj->Delete(bsTemp.GetString());
  1215. Refresh();
  1216. }
  1217. void CObjectEditor::OnEditProp()
  1218. {
  1219. // Find out which property is selected.
  1220. // ====================================
  1221. LRESULT nIndex = SendMessage(m_hPropList, LB_GETCURSEL, 0, 0);
  1222. if (nIndex == LB_ERR)
  1223. return;
  1224. char buf[TEMP_BUF];
  1225. *buf = 0;
  1226. SendMessage(m_hPropList, LB_GETTEXT, nIndex, LPARAM(buf));
  1227. if (*buf == 0)
  1228. return;
  1229. // Scan out the property name.
  1230. // ===========================
  1231. char name[TEMP_BUF];
  1232. *name = 0;
  1233. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  1234. return;
  1235. if (*name == 0)
  1236. return;
  1237. WString wsName = name;
  1238. // Get the property value from the object
  1239. // ======================================
  1240. VARIANT vVal;
  1241. CIMTYPE ctType;
  1242. m_pObj->Get((LPWSTR)wsName, 0, &vVal, &ctType, NULL);
  1243. // Create a CTestProperty from it
  1244. // ==========================
  1245. IWbemQualifierSet* pQualifierSet = 0;
  1246. SCODE sc = m_pObj->GetPropertyQualifierSet((LPWSTR)wsName, &pQualifierSet);
  1247. CTestProperty Copy(pQualifierSet);
  1248. if (pQualifierSet)
  1249. pQualifierSet->Release();
  1250. Copy.m_pName = new wchar_t[wcslen(wsName) + 1];
  1251. wcscpy(Copy.m_pName, wsName);
  1252. Copy.m_pValue = new CVar(&vVal);
  1253. Copy.m_lType = ctType;
  1254. // Note that GetPropertyOrigin can fail for objects returned by Projection
  1255. // Queries, so we need to be careful with strClass.
  1256. BSTR strClass = NULL;
  1257. m_pObj->GetPropertyOrigin((LPWSTR)wsName, &strClass);
  1258. if ( NULL != strClass )
  1259. {
  1260. Copy.m_pClass = new wchar_t[wcslen(strClass)+1];
  1261. wcscpy(Copy.m_pClass, strClass);
  1262. SysFreeString(strClass);
  1263. }
  1264. // Edit it.
  1265. // =========
  1266. CTestPropertyEditor ed(m_hDlg, m_lGenFlags, TRUE, m_lSync, &Copy, !m_bClass,
  1267. m_lTimeout);
  1268. INT_PTR nRes = ed.Edit();
  1269. if ((nRes == IDCANCEL) || (nRes == 0))
  1270. return;
  1271. // If here, we must replace the info for the property.
  1272. // ===================================================
  1273. VARIANT* pVariant = Copy.m_pValue->GetNewVariant();
  1274. if(m_bClass && V_VT(pVariant) == VT_NULL)
  1275. ctType = (VARTYPE)Copy.m_lType;
  1276. else
  1277. ctType = 0;
  1278. sc = m_pObj->Put(Copy.m_pName, 0, pVariant, ctType);
  1279. VariantClear(pVariant);
  1280. if(FAILED(sc))
  1281. {
  1282. FormatError(sc, m_hDlg);
  1283. }
  1284. Refresh();
  1285. }
  1286. void CObjectEditor::OnDelProp()
  1287. {
  1288. // Find out which property is selected.
  1289. // ====================================
  1290. LRESULT nIndex = SendMessage(m_hPropList, LB_GETCURSEL, 0, 0);
  1291. if (nIndex == LB_ERR)
  1292. return;
  1293. char buf[TEMP_BUF];
  1294. *buf = 0;
  1295. SendMessage(m_hPropList, LB_GETTEXT, nIndex, LPARAM(buf));
  1296. if (*buf == 0)
  1297. return;
  1298. // Scan out the property name.
  1299. // ===========================
  1300. char name[TEMP_BUF];
  1301. *name = 0;
  1302. if (sscanf(buf, "%[^\t\0]", name) == EOF)
  1303. return;
  1304. if (*name == 0)
  1305. return;
  1306. WString WName = name;
  1307. if(FAILED(m_pObj->Delete(LPWSTR(WName))))
  1308. {
  1309. MessageBox(NULL, IDS_CANNOT_EDIT_PROPERTY, IDS_ERROR,
  1310. MB_OK|MB_ICONSTOP);
  1311. return;
  1312. }
  1313. Refresh();
  1314. }
  1315. class CMofViewer : public CWbemDialog
  1316. {
  1317. BSTR m_strText;
  1318. public:
  1319. CMofViewer(HWND hParent, BSTR strText)
  1320. : CWbemDialog(IDD_MOF, hParent), m_strText(strText)
  1321. {}
  1322. BOOL OnInitDialog();
  1323. };
  1324. BOOL CMofViewer::OnInitDialog()
  1325. {
  1326. int iSize = wcslen(m_strText)*2+1;
  1327. char* szText = new char[iSize];
  1328. wcstombs(szText, m_strText, iSize);
  1329. char* szText1 = new char[strlen(szText)*2+1];
  1330. char* pc = szText;
  1331. char* pc1 = szText1;
  1332. while(*pc)
  1333. {
  1334. if(*pc == '\n')
  1335. {
  1336. *(pc1++) = '\r';
  1337. }
  1338. *(pc1++) = *(pc++);
  1339. }
  1340. *pc1 = 0;
  1341. SetDlgItemText(IDC_MOF, szText1);
  1342. delete [] szText;
  1343. return TRUE;
  1344. }
  1345. void CObjectEditor::OnShowMof()
  1346. {
  1347. BSTR strText;
  1348. HRESULT hres = m_pObj->GetObjectText(0, &strText);
  1349. if(FAILED(hres))
  1350. {
  1351. MessageBox(IDS_MOF_FAILED, IDS_ERROR, MB_OK);
  1352. }
  1353. else
  1354. {
  1355. CMofViewer mv(m_hDlg, strText);
  1356. mv.Run();
  1357. }
  1358. }
  1359. void CObjectEditor::OnRefreshObject()
  1360. {
  1361. #if 0
  1362. BSTR strText;
  1363. HRESULT res;
  1364. // Asynchronous
  1365. if (m_lSync & ASYNC)
  1366. {
  1367. MessageBox(IDS_ASYNC_NOT_SUPPORTED, IDS_ERROR, MB_OK);
  1368. return;
  1369. }
  1370. else if (m_lSync & SEMISYNC)
  1371. {
  1372. IWbemCallResultEx* pCallRes = NULL;
  1373. CHourGlass hg;
  1374. res = g_pServicesEx->RefreshObject(&m_pObj,
  1375. m_lGenFlags | WBEM_FLAG_RETURN_IMMEDIATELY,
  1376. g_Context, &pCallRes);
  1377. if (SUCCEEDED(res))
  1378. {
  1379. LONG lStatus;
  1380. SetInterfaceSecurityEx(pCallRes, gpAuthIdentity, gpPrincipal, gdwAuthLevel, gdwImpLevel);
  1381. while ((res = pCallRes->GetCallStatus(m_lTimeout, &lStatus)) == WBEM_S_TIMEDOUT)
  1382. {
  1383. // wait
  1384. }
  1385. if (res == WBEM_S_NO_ERROR)
  1386. {
  1387. res = (HRESULT)lStatus; // lStatus is the final result of the above IWbemServices::PutClass call
  1388. }
  1389. pCallRes->Release();
  1390. }
  1391. }
  1392. // Synchronous
  1393. else
  1394. {
  1395. CHourGlass hg;
  1396. res = g_pServicesEx->RefreshObject(&m_pObj,
  1397. m_lGenFlags ,
  1398. g_Context, NULL);
  1399. }
  1400. HRESULT hres = g_pServicesEx->RefreshObject(&m_pObj, 0, NULL, NULL );
  1401. if(FAILED(hres))
  1402. {
  1403. FormatError(hres, m_hDlg, NULL);
  1404. }
  1405. else
  1406. Refresh();
  1407. #endif
  1408. HRESULT res;
  1409. if (m_pObj)
  1410. {
  1411. VARIANT Var;
  1412. VariantInit(&Var);
  1413. res = m_pObj->Get(L"__RELPATH",0,&Var,NULL,NULL);
  1414. if (SUCCEEDED(res))
  1415. {
  1416. if (VT_BSTR == V_VT(&Var))
  1417. {
  1418. IWbemClassObject * pObj = NULL;
  1419. res = g_pNamespace->GetObject(V_BSTR(&Var),
  1420. m_lGenFlags ,
  1421. g_Context,
  1422. &pObj,
  1423. NULL);
  1424. if (SUCCEEDED(res))
  1425. {
  1426. m_pObj->Release();
  1427. m_pObj = pObj;
  1428. }
  1429. else
  1430. {
  1431. FormatError(res, m_hDlg, NULL);
  1432. }
  1433. }
  1434. else
  1435. {
  1436. FormatError(WBEM_E_INVALID_OBJECT, m_hDlg, NULL);
  1437. }
  1438. }
  1439. else
  1440. {
  1441. FormatError(res, m_hDlg, NULL);
  1442. }
  1443. VariantClear(&Var);
  1444. }
  1445. }
  1446. BOOL CObjectEditor::OnInitDialog()
  1447. {
  1448. CenterOnParent();
  1449. m_hPropList = GetDlgItem(IDC_PROP_LIST);
  1450. m_hQualifierList = GetDlgItem(IDC_ATTRIB_LIST);
  1451. m_hMethodList = GetDlgItem(IDC_METHOD_LIST);
  1452. // Set tabs in the property list box.
  1453. // ==================================
  1454. LONG Tabs[] = { 80, 140, 170 };
  1455. int TabCount = 3;
  1456. SendMessage(m_hPropList, LB_SETTABSTOPS,
  1457. (WPARAM) TabCount, (LPARAM) Tabs);
  1458. SendMessage(m_hPropList, LB_SETHORIZONTALEXTENT, 1000, 0);
  1459. SendMessage(m_hQualifierList, LB_SETTABSTOPS,
  1460. (WPARAM) TabCount, (LPARAM) Tabs);
  1461. SendMessage(m_hQualifierList, LB_SETHORIZONTALEXTENT, 1000, 0);
  1462. SendMessage(m_hMethodList, LB_SETTABSTOPS,
  1463. (WPARAM) TabCount, (LPARAM) Tabs);
  1464. SendMessage(m_hMethodList, LB_SETHORIZONTALEXTENT, 1000, 0);
  1465. if (m_dwEditMode == readonly)
  1466. {
  1467. EnableWindow(GetDlgItem(IDOK), FALSE);
  1468. }
  1469. if (m_bClass)
  1470. {
  1471. SetCheck(IDC_UPDATE_NORMAL, TRUE);
  1472. SetCheck(IDC_UPDATE_COMPATIBLE, TRUE);
  1473. }
  1474. else
  1475. {
  1476. SetCheck(IDC_UPDATE_NORMAL, TRUE);
  1477. EnableWindow(GetDlgItem(IDC_UPDATE_COMPATIBLE), FALSE);
  1478. EnableWindow(GetDlgItem(IDC_UPDATE_SAFE), FALSE);
  1479. EnableWindow(GetDlgItem(IDC_UPDATE_FORCE), FALSE);
  1480. }
  1481. Refresh();
  1482. return TRUE;
  1483. }
  1484. BOOL CObjectEditor::OnDoubleClick(int nID)
  1485. {
  1486. if(nID == IDC_ATTRIB_LIST)
  1487. {
  1488. OnEditQualifier();
  1489. return TRUE;
  1490. }
  1491. else if(nID == IDC_PROP_LIST)
  1492. {
  1493. OnEditProp();
  1494. return TRUE;
  1495. }
  1496. else if(nID == IDC_METHOD_LIST)
  1497. {
  1498. OnEditMethod();
  1499. return TRUE;
  1500. }
  1501. else return FALSE;
  1502. }
  1503. BOOL CObjectEditor::OnCommand(WORD wCode, WORD wID)
  1504. {
  1505. switch(wID)
  1506. {
  1507. case IDC_EDIT_ATTRIB: OnEditQualifier(); return TRUE;
  1508. case IDC_ADD_ATTRIB: OnAddQualifier(); return TRUE;
  1509. case IDC_DELETE_ATTRIB: OnDelQualifier(); return TRUE;
  1510. case IDC_SHOW_MOF: OnShowMof(); return TRUE;
  1511. case IDC_ADD_PROP: OnAddProp(); return TRUE;
  1512. case IDC_EDIT_PROP: OnEditProp(); return TRUE;
  1513. case IDC_DELETE_PROP: OnDelProp(); return TRUE;
  1514. case IDC_ADD_METHOD: OnAddMethod(); return TRUE;
  1515. case IDC_EDIT_METHOD: OnEditMethod(); return TRUE;
  1516. case IDC_DELETE_METHOD: OnDelMethod(); return TRUE;
  1517. case IDC_REFRESH_OBJECT: OnRefreshObject(); return TRUE;
  1518. case IDC_SUPERCLASS:
  1519. if(m_bClass) OnSuperclass();
  1520. else OnClass();
  1521. return TRUE;
  1522. case IDC_DERIVED:
  1523. if(m_bClass) OnDerived();
  1524. else OnRefs();
  1525. return TRUE;
  1526. case IDC_INSTANCES:
  1527. if(m_bClass) OnInstances();
  1528. else OnAssocs();
  1529. return TRUE;
  1530. case IDC_HIDE_SYSTEM:
  1531. OnHideSystem();
  1532. return TRUE;
  1533. case IDC_HIDE_DERIVED:
  1534. OnHideDerived();
  1535. return TRUE;
  1536. }
  1537. return FALSE;
  1538. }
  1539. void CObjectEditor::OnSuperclass()
  1540. {
  1541. // Get the superclass
  1542. // ==================
  1543. VARIANT v;
  1544. VariantInit(&v);
  1545. if(FAILED(m_pObj->Get(L"__SUPERCLASS", 0, &v, NULL, NULL)) ||
  1546. V_VT(&v) != VT_BSTR)
  1547. {
  1548. MessageBox(IDS_NO_SUPERCLASS, IDS_ERROR, MB_OK);
  1549. return;
  1550. }
  1551. ShowClass(m_hDlg, m_lGenFlags, V_BSTR(&v), m_lSync, m_pOwner, m_lTimeout);
  1552. }
  1553. void CObjectEditor::OnClass()
  1554. {
  1555. // Get the class
  1556. // =============
  1557. VARIANT v;
  1558. VariantInit(&v);
  1559. if(FAILED(m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL)))
  1560. {
  1561. MessageBox(IDS_CRITICAL_ERROR, IDS_ERROR, MB_OK);
  1562. return;
  1563. }
  1564. ShowClass(m_hDlg, m_lGenFlags, V_BSTR(&v), m_lSync, m_pOwner, m_lTimeout);
  1565. }
  1566. void CObjectEditor::OnDerived()
  1567. {
  1568. // Get the children
  1569. // ================
  1570. VARIANT v;
  1571. VariantInit(&v);
  1572. if(FAILED(m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL)) ||
  1573. SysStringLen(V_BSTR(&v)) == 0)
  1574. {
  1575. MessageBox(IDS_INCOMPLETE_CLASS, IDS_ERROR, MB_OK);
  1576. return;
  1577. }
  1578. ShowClasses(m_hDlg, m_lGenFlags, WBEM_FLAG_SHALLOW, V_BSTR(&v), m_lSync, m_pOwner,
  1579. m_lTimeout, m_nBatch);
  1580. }
  1581. void CObjectEditor::OnInstances()
  1582. {
  1583. // Get the instances
  1584. // ================
  1585. VARIANT v;
  1586. VariantInit(&v);
  1587. if(FAILED(m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL)) ||
  1588. SysStringLen(V_BSTR(&v)) == 0)
  1589. {
  1590. MessageBox(IDS_INCOMPLETE_CLASS, IDS_ERROR, MB_OK);
  1591. return;
  1592. }
  1593. ShowInstances(m_hDlg, m_lGenFlags, WBEM_FLAG_SHALLOW, V_BSTR(&v), m_lSync, m_pOwner,
  1594. m_lTimeout, m_nBatch);
  1595. }
  1596. void CObjectEditor::OnRefs()
  1597. {
  1598. CQueryResultDlg* pResDlg = new CQueryResultDlg(m_hDlg, m_lGenFlags, WBEM_FLAG_DEEP);
  1599. // Pass on invocation method (sync, async..) and related settings for this
  1600. // query and by any further operations (editing/deleting/etc. of an instance).
  1601. pResDlg->SetCallMethod(m_lSync);
  1602. pResDlg->SetTimeout(m_lTimeout);
  1603. pResDlg->SetBatchCount(m_nBatch);
  1604. VARIANT v;
  1605. VariantInit(&v);
  1606. if(FAILED(m_pObj->Get(L"__RELPATH", 0, &v, NULL, NULL)) ||
  1607. V_VT(&v) != VT_BSTR)
  1608. {
  1609. MessageBox(IDS_UNREFERENCABLE_OBJECT, IDS_ERROR, MB_OK);
  1610. delete pResDlg;
  1611. return;
  1612. }
  1613. WCHAR* wszQuery = new WCHAR[wcslen(V_BSTR(&v))+100];
  1614. swprintf(wszQuery, L"references of {%s}", V_BSTR(&v)); // Actual query, dont internationalize
  1615. char szTitle[1000];
  1616. char szFormat[104];
  1617. char* pTitle = NULL;
  1618. if(LoadString(GetModuleHandle(NULL), IDS_REFERENCES_OF, szFormat, 104))
  1619. {
  1620. sprintf(szTitle, szFormat, V_BSTR(&v));
  1621. pTitle = szTitle;
  1622. }
  1623. if(_ExecQuery(m_hDlg, m_lGenFlags, WBEM_FLAG_DEEP, wszQuery, L"WQL", m_lSync,
  1624. pResDlg, pTitle, m_lTimeout, m_nBatch))
  1625. {
  1626. pResDlg->RunDetached(m_pOwner);
  1627. }
  1628. else
  1629. {
  1630. delete pResDlg;
  1631. }
  1632. delete [] wszQuery;
  1633. }
  1634. void CObjectEditor::OnAssocs()
  1635. {
  1636. CQueryResultDlg* pResDlg = new CQueryResultDlg(m_hDlg, m_lGenFlags, WBEM_FLAG_DEEP);
  1637. // Pass on invocation method (sync, async..) and related settings for this
  1638. // query and by any further operations (editing/deleting/etc. of an instance).
  1639. pResDlg->SetCallMethod(m_lSync);
  1640. pResDlg->SetTimeout(m_lTimeout);
  1641. pResDlg->SetBatchCount(m_nBatch);
  1642. VARIANT v;
  1643. VariantInit(&v);
  1644. if(FAILED(m_pObj->Get(L"__RELPATH", 0, &v, NULL, NULL)) ||
  1645. V_VT(&v) != VT_BSTR)
  1646. {
  1647. MessageBox(IDS_UNREFERENCABLE_OBJECT, IDS_ERROR, MB_OK);
  1648. delete pResDlg;
  1649. return;
  1650. }
  1651. WCHAR* wszQuery = new WCHAR[wcslen(V_BSTR(&v))+100];
  1652. swprintf(wszQuery, L"associators of {%s}", V_BSTR(&v)); // Actual query, dont internationalize
  1653. char szTitle[1000];
  1654. char szFormat[104];
  1655. char* pTitle = NULL;
  1656. if(LoadString(GetModuleHandle(NULL), IDS_ASSOCIATORS_OF, szFormat, 104))
  1657. {
  1658. sprintf(szTitle, szFormat, V_BSTR(&v));
  1659. pTitle = szTitle;
  1660. }
  1661. if(_ExecQuery(m_hDlg, m_lGenFlags, WBEM_FLAG_DEEP, wszQuery, L"WQL", m_lSync,
  1662. pResDlg, pTitle, m_lTimeout, m_nBatch))
  1663. {
  1664. pResDlg->RunDetached(m_pOwner);
  1665. }
  1666. else
  1667. {
  1668. delete pResDlg;
  1669. }
  1670. delete [] wszQuery;
  1671. }
  1672. BOOL CObjectEditor::mstatic_bHideSystemDefault = FALSE;
  1673. void CObjectEditor::OnHideSystem()
  1674. {
  1675. m_bHideSystem = (GetCheck(IDC_HIDE_SYSTEM) == BST_CHECKED);
  1676. mstatic_bHideSystemDefault = m_bHideSystem;
  1677. Refresh();
  1678. }
  1679. void CObjectEditor::OnHideDerived()
  1680. {
  1681. m_bHideDerived = (GetCheck(IDC_HIDE_DERIVED) == BST_CHECKED);
  1682. Refresh();
  1683. }
  1684. void CObjectEditor::Refresh()
  1685. {
  1686. // Zap the current contents.
  1687. // =========================
  1688. SendMessage(m_hPropList, LB_RESETCONTENT, 0, 0);
  1689. SendMessage(m_hQualifierList, LB_RESETCONTENT, 0, 0);
  1690. SendMessage(m_hMethodList, LB_RESETCONTENT, 0, 0);
  1691. // Set the title to relpath
  1692. // ========================
  1693. char buf[TEMP_BUF];
  1694. char szFormat[1024];
  1695. VARIANT v;
  1696. VariantInit(&v);
  1697. HRESULT hres = m_pObj->Get(L"__RELPATH", 0, &v, NULL, NULL);
  1698. if(FAILED(hres) || V_VT(&v) == VT_NULL)
  1699. {
  1700. hres = m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL);
  1701. if(FAILED(hres) || V_VT(&v) == VT_NULL)
  1702. {
  1703. hres = m_pObj->Get(L"__SUPERCLASS", 0, &v, NULL, NULL);
  1704. if(FAILED(hres) || V_VT(&v) != VT_BSTR)
  1705. {
  1706. LoadString(GetModuleHandle(NULL), IDS_NEW_TOP_LEVEL_CLASS, buf, TEMP_BUF);
  1707. }
  1708. else
  1709. {
  1710. LoadString(GetModuleHandle(NULL), IDS_NEW_CHILD_OF, szFormat, 1024);
  1711. _snprintf(buf, sizeof(buf)/sizeof(buf[0]), szFormat, V_BSTR(&v));
  1712. }
  1713. }
  1714. else
  1715. {
  1716. LoadString(GetModuleHandle(NULL), IDS_INSTANCE_OF, szFormat, 1024);
  1717. _snprintf(buf, sizeof(buf)/sizeof(buf[0]), szFormat, V_BSTR(&v));
  1718. }
  1719. }
  1720. else
  1721. {
  1722. LoadString(GetModuleHandle(NULL), IDS_OBJECT_EDITOR_FOR, szFormat, 1024);
  1723. _snprintf(buf, sizeof(buf)/sizeof(buf[0]), szFormat, V_BSTR(&v));
  1724. }
  1725. buf[sizeof(buf)-1] = '\0';
  1726. VariantClear(&v);
  1727. SetWindowText(m_hDlg, buf);
  1728. // Fill in the property list.
  1729. // ==========================
  1730. LONG lConFlags = 0; // condition flags (i.e., WBEM_CONDITION_FLAG_TYPE)
  1731. if(m_bHideDerived)
  1732. lConFlags = WBEM_FLAG_LOCAL_ONLY;
  1733. else if(m_bHideSystem)
  1734. lConFlags = WBEM_FLAG_NONSYSTEM_ONLY;
  1735. m_pObj->BeginEnumeration(lConFlags);
  1736. BSTR Name = NULL;
  1737. CIMTYPE ctType;
  1738. while (m_pObj->Next(0, &Name, &v, &ctType, NULL) == WBEM_S_NO_ERROR)
  1739. {
  1740. char buf2[TEMP_BUF];
  1741. CVar value(&v);
  1742. LPSTR TypeString = TypeToString(ctType);
  1743. LPSTR ValueString = ValueToNewString(&value, ctType);
  1744. if(strlen(ValueString) > 100)
  1745. {
  1746. ValueString[100] = 0;
  1747. }
  1748. sprintf(buf2, "%S\t%s\t%s", Name, TypeString, ValueString);
  1749. delete [] ValueString;
  1750. SendMessage(m_hPropList, LB_ADDSTRING, 0, LPARAM(buf2));
  1751. VariantClear(&v);
  1752. }
  1753. m_pObj->EndEnumeration();
  1754. // Fill in the Qualifier list.
  1755. // ===========================
  1756. IWbemQualifierSet *pQualifiers = NULL;
  1757. hres = m_pObj->GetQualifierSet(&pQualifiers);
  1758. if(SUCCEEDED(hres))
  1759. {
  1760. pQualifiers->BeginEnumeration(0);
  1761. BSTR strName = NULL;
  1762. VARIANT vVal;
  1763. VariantInit(&vVal);
  1764. long lFlavor;
  1765. while(pQualifiers->Next(0, &strName, &vVal, &lFlavor) == S_OK)
  1766. {
  1767. CTestQualifier A;
  1768. A.m_pName = new wchar_t[wcslen(strName)+1];
  1769. wcscpy(A.m_pName, strName);
  1770. A.m_pValue = new CVar(&vVal);
  1771. A.m_lType = lFlavor;
  1772. // Build list box string.
  1773. // ======================
  1774. SendMessage(m_hQualifierList, LB_ADDSTRING, 0,
  1775. LPARAM(CTestQualifierToString(&A)));
  1776. }
  1777. pQualifiers->EndEnumeration();
  1778. pQualifiers->Release();
  1779. }
  1780. else
  1781. EnableWindow(m_hQualifierList, FALSE);
  1782. // Fill in the methods
  1783. m_pObj->BeginMethodEnumeration(0);
  1784. while (m_pObj->NextMethod(0, &Name, NULL, NULL) == WBEM_S_NO_ERROR)
  1785. {
  1786. char buf3[TEMP_BUF];
  1787. wcstombs(buf3, Name, TEMP_BUF);
  1788. buf3[TEMP_BUF-1] = '\0';
  1789. SendMessage(m_hMethodList, LB_ADDSTRING, 0, LPARAM(buf3));
  1790. VariantClear(&v);
  1791. }
  1792. m_pObj->EndMethodEnumeration();
  1793. // Configure the buttons
  1794. // =====================
  1795. ConfigureButtons();
  1796. }
  1797. void CObjectEditor::ConfigureButtons()
  1798. {
  1799. VARIANT v;
  1800. VariantInit(&v);
  1801. if(m_bClass)
  1802. {
  1803. // Configure for class
  1804. // ===================
  1805. if(FAILED(m_pObj->Get(L"__SUPERCLASS", 0, &v, NULL, NULL)) ||
  1806. V_VT(&v) != VT_BSTR)
  1807. {
  1808. EnableWindow(GetDlgItem(IDC_SUPERCLASS), FALSE);
  1809. }
  1810. else
  1811. {
  1812. VariantClear(&v);
  1813. EnableWindow(GetDlgItem(IDC_SUPERCLASS), TRUE);
  1814. }
  1815. }
  1816. else
  1817. {
  1818. // Configure for instance
  1819. // ======================
  1820. SetDlgItemText(IDC_CLASS, IDS_CLASS);
  1821. SetDlgItemText(IDC_REFERENCES, IDS_REFERENCES);
  1822. SetDlgItemText(IDC_ASSOCIATIONS, IDS_ASSOCIATORS);
  1823. EnableWindow(GetDlgItem(IDC_KEY), FALSE);
  1824. EnableWindow(GetDlgItem(IDC_INDEXED), FALSE);
  1825. }
  1826. if(m_bNoMethods || !m_bClass)
  1827. {
  1828. EnableWindow(GetDlgItem(IDC_ADD_METHOD), FALSE);
  1829. EnableWindow(GetDlgItem(IDC_EDIT_METHOD), FALSE);
  1830. EnableWindow(GetDlgItem(IDC_DELETE_METHOD), FALSE);
  1831. }
  1832. SetCheck(IDC_HIDE_SYSTEM, m_bHideSystem?BST_CHECKED:BST_UNCHECKED);
  1833. SetCheck(IDC_HIDE_DERIVED, m_bHideDerived?BST_CHECKED:BST_UNCHECKED);
  1834. EnableWindow(GetDlgItem(IDC_HIDE_SYSTEM), !m_bHideDerived);
  1835. if(m_dwEditMode == foreign)
  1836. {
  1837. EnableWindow(GetDlgItem(IDC_CLASS), FALSE);
  1838. EnableWindow(GetDlgItem(IDC_REFERENCES), FALSE);
  1839. EnableWindow(GetDlgItem(IDC_ASSOCIATIONS), FALSE);
  1840. EnableWindow(GetDlgItem(IDOK), FALSE);
  1841. }
  1842. }
  1843. CObjectEditor::CObjectEditor(HWND hParent, LONG lGenFlags, DWORD dwEditMode, LONG lSync,
  1844. IWbemClassObject *pObj, LONG lTimeout, ULONG nBatch)
  1845. : CWbemDialog(IDD_OBJECT_EDITOR, hParent)
  1846. {
  1847. m_pObj = pObj;
  1848. pObj->AddRef();
  1849. m_dwEditMode = dwEditMode;
  1850. m_bHideSystem = mstatic_bHideSystemDefault;
  1851. m_bHideDerived = FALSE;
  1852. m_bNoMethods = dwEditMode & nomethods;
  1853. m_lGenFlags = lGenFlags; // generic flags (i.e., WBEM_GENERIC_FLAG_TYPE)
  1854. m_lSync = lSync; // sync, async, semisync
  1855. m_lTimeout = lTimeout; // used in semisync only
  1856. m_nBatch = nBatch; // used in semisync and sync enumerations
  1857. VARIANT v;
  1858. VariantInit(&v);
  1859. m_pObj->Get(L"__GENUS", 0, &v, NULL, NULL);
  1860. m_bClass = (V_I4(&v) == WBEM_GENUS_CLASS);
  1861. m_bResultingObj = NULL;
  1862. }
  1863. CObjectEditor::~CObjectEditor()
  1864. {
  1865. m_pObj->Release();
  1866. }
  1867. INT_PTR CObjectEditor::Edit()
  1868. {
  1869. return Run();
  1870. }
  1871. BOOL CObjectEditor::OnOK()
  1872. {
  1873. if(m_bResultingObj)
  1874. {
  1875. //We need to extract the flag values...
  1876. LONG lChgFlags = 0; // change flags (i.e., WBEM_CHANGE_FLAG_TYPE)
  1877. if (GetCheck(IDC_UPDATE_NORMAL))
  1878. lChgFlags |= WBEM_FLAG_CREATE_OR_UPDATE;
  1879. if (GetCheck(IDC_UPDATE_CREATE))
  1880. lChgFlags |= WBEM_FLAG_CREATE_ONLY;
  1881. if (GetCheck(IDC_UPDATE_UPDATE))
  1882. lChgFlags |= WBEM_FLAG_UPDATE_ONLY;
  1883. if (GetCheck(IDC_UPDATE_COMPATIBLE))
  1884. lChgFlags |= WBEM_FLAG_UPDATE_COMPATIBLE;
  1885. if (GetCheck(IDC_UPDATE_SAFE))
  1886. lChgFlags |= WBEM_FLAG_UPDATE_SAFE_MODE;
  1887. if (GetCheck(IDC_UPDATE_FORCE))
  1888. lChgFlags |= WBEM_FLAG_UPDATE_FORCE_MODE;
  1889. if (!ResultingObject(m_pObj, lChgFlags))
  1890. return TRUE;
  1891. }
  1892. return CBasicWbemDialog::OnOK();
  1893. }
  1894. void CObjectEditor::RunDetached(CRefCountable* pOwner)
  1895. {
  1896. m_bResultingObj = TRUE;
  1897. SetOwner(pOwner);
  1898. SetDeleteOnClose();
  1899. Create(FALSE);
  1900. }
  1901. BOOL CObjectEditor::ResultingObject(IWbemClassObject* pObj, LONG lChgFlags)
  1902. {
  1903. BOOL bRes;
  1904. if(m_bClass)
  1905. bRes = _PutClass(m_hDlg, m_lGenFlags, lChgFlags, m_lSync, pObj, m_lTimeout);
  1906. else
  1907. bRes = _PutInstance(m_hDlg, m_lGenFlags, lChgFlags, m_lSync, pObj, m_lTimeout);
  1908. return bRes;
  1909. }
  1910. void CObjectEditor::OnAddMethod()
  1911. {
  1912. // Add a dummy property for now
  1913. // ============================
  1914. SCODE hres;
  1915. VARIANT v;
  1916. v.vt = VT_BSTR;
  1917. IWbemClassObject * pIn = NULL;
  1918. IWbemClassObject * pOut = NULL;
  1919. SCODE sc;
  1920. CBString bsParm(L"__PARAMETERS");
  1921. sc = g_pNamespace->GetObject(bsParm.GetString(), m_lGenFlags, g_Context, &pIn, NULL);
  1922. sc = g_pNamespace->GetObject(bsParm.GetString(), m_lGenFlags, g_Context, &pOut, NULL);
  1923. CBString bsTemp(L"__CLASS");
  1924. v.bstrVal = SysAllocString(L"InArgs");
  1925. sc = pIn->Put(bsTemp.GetString(), 0, &v, 0);
  1926. SysFreeString(v.bstrVal);
  1927. v.bstrVal = SysAllocString(L"OutArgs");
  1928. sc = pOut->Put(bsTemp.GetString(), 0, &v, 0);
  1929. SysFreeString(v.bstrVal);
  1930. bsTemp = L"DUMMY_METHOD__D";
  1931. if(FAILED(m_pObj->PutMethod(bsTemp.GetString(), 0, NULL, NULL)))
  1932. {
  1933. MessageBox(NULL, IDS_CANNOT_EDIT_METHOD, IDS_ERROR, MB_OK|MB_ICONSTOP);
  1934. return;
  1935. }
  1936. IWbemQualifierSet* pQualifierSet;
  1937. m_pObj->GetMethodQualifierSet(bsTemp.GetString(), &pQualifierSet);
  1938. // Create CTestMethod with the dummy attr set for now
  1939. // =================================================
  1940. CTestMethod method(pQualifierSet, pIn, pOut, FALSE, FALSE);
  1941. m_pObj->Get(L"__CLASS", 0, &v, NULL, NULL);
  1942. method.m_pClass = new wchar_t[wcslen(V_BSTR(&v)) + 1];
  1943. wcscpy(method.m_pClass, V_BSTR(&v));
  1944. VariantClear(&v);
  1945. CMethodEditor ed(m_hDlg, &method, FALSE, FALSE);
  1946. INT_PTR nRes = ed.Edit();
  1947. if ((nRes == IDCANCEL) || (nRes == 0))
  1948. {
  1949. pQualifierSet->Release();
  1950. goto DeleteDummy;
  1951. }
  1952. // Set the method
  1953. // ================
  1954. bsTemp = method.m_pName;
  1955. hres = m_pObj->PutMethod(bsTemp.GetString(), 0,
  1956. (method.m_bEnableInputArgs) ? method.m_pInArgs: NULL,
  1957. (method.m_bEnableOutputArgs) ? method.m_pOutArgs : NULL);
  1958. if(FAILED(hres))
  1959. {
  1960. FormatError(hres, m_hDlg, NULL);
  1961. goto DeleteDummy;
  1962. }
  1963. // Copy the Qualifiers
  1964. // ===================
  1965. IWbemQualifierSet* pRealQualifierSet;
  1966. m_pObj->GetMethodQualifierSet(bsTemp.GetString(), &pRealQualifierSet);
  1967. CopyQualifierSet(pRealQualifierSet, pQualifierSet, m_hDlg);
  1968. pQualifierSet->EndEnumeration();
  1969. pQualifierSet->Release();
  1970. pRealQualifierSet->Release();
  1971. DeleteDummy:
  1972. bsTemp = L"DUMMY_METHOD__D";
  1973. m_pObj->DeleteMethod(bsTemp.GetString());
  1974. Refresh();
  1975. return;
  1976. }
  1977. void CObjectEditor::OnEditMethod()
  1978. {
  1979. SCODE sc;
  1980. IWbemClassObject * pIn = NULL;
  1981. IWbemClassObject * pOut = NULL;
  1982. // Find out which property is selected.
  1983. // ====================================
  1984. LRESULT nIndex = SendMessage(m_hMethodList, LB_GETCURSEL, 0, 0);
  1985. if (nIndex == LB_ERR)
  1986. return;
  1987. char buf[TEMP_BUF];
  1988. *buf = 0;
  1989. SendMessage(m_hMethodList, LB_GETTEXT, nIndex, LPARAM(buf));
  1990. if (*buf == 0)
  1991. return;
  1992. WString wsName = buf;
  1993. CBString bsTemp(L"__CLASS");
  1994. // Get the property value from the object
  1995. // ======================================
  1996. m_pObj->GetMethod((LPWSTR)wsName, 0, &pIn, &pOut);
  1997. // Create a CTestMethod from it
  1998. // ==========================
  1999. IWbemQualifierSet* pQualifierSet = 0;
  2000. sc = m_pObj->GetMethodQualifierSet((LPWSTR)wsName, &pQualifierSet);
  2001. IWbemClassObject * pTempIn = pIn;
  2002. IWbemClassObject * pTempOut = pOut;
  2003. VARIANT v;
  2004. v.vt = VT_BSTR;
  2005. // If the current methods lacks an input or output object, then just create a
  2006. // temporary one in case the user decides to start using the input or output object.
  2007. if(pTempIn == NULL)
  2008. {
  2009. CBString bsParm(L"__PARAMETERS");
  2010. sc = g_pNamespace->GetObject(bsParm.GetString(), m_lGenFlags, g_Context,
  2011. &pTempIn, NULL);
  2012. v.bstrVal = SysAllocString(L"InArgs");
  2013. sc = pTempIn->Put(bsTemp.GetString(), 0, &v, 0);
  2014. SysFreeString(v.bstrVal);
  2015. }
  2016. if(pTempOut == NULL)
  2017. {
  2018. CBString bsParm(L"__PARAMETERS");
  2019. sc = g_pNamespace->GetObject(bsParm.GetString(), m_lGenFlags, g_Context,
  2020. &pTempOut, NULL);
  2021. v.bstrVal = SysAllocString(L"OutArgs");
  2022. sc = pTempOut->Put(bsTemp.GetString(), 0, &v, 0);
  2023. SysFreeString(v.bstrVal);
  2024. }
  2025. CTestMethod Copy(pQualifierSet, pTempIn, pTempOut, pIn != NULL, pOut != NULL);
  2026. if (pQualifierSet)
  2027. pQualifierSet->Release();
  2028. Copy.m_pName = new wchar_t[wcslen(wsName) + 1];
  2029. wcscpy(Copy.m_pName, wsName);
  2030. BSTR strClass;
  2031. m_pObj->GetMethodOrigin((LPWSTR)wsName, &strClass);
  2032. Copy.m_pClass = new wchar_t[wcslen(strClass) + 1];
  2033. wcscpy(Copy.m_pClass, strClass);
  2034. SysFreeString(strClass);
  2035. // Edit it.
  2036. // =========
  2037. CMethodEditor ed(m_hDlg, &Copy, TRUE, !m_bClass);
  2038. INT_PTR nRes = ed.Edit();
  2039. if ((nRes == IDCANCEL) || (nRes == 0))
  2040. return;
  2041. // If here, we must replace the info for the property.
  2042. // ===================================================
  2043. sc = m_pObj->PutMethod(Copy.m_pName, 0,
  2044. (Copy.m_bEnableInputArgs) ? Copy.m_pInArgs : NULL,
  2045. (Copy.m_bEnableOutputArgs) ? Copy.m_pOutArgs : NULL);
  2046. if(FAILED(sc))
  2047. {
  2048. FormatError(sc, m_hDlg);
  2049. }
  2050. Refresh();
  2051. }
  2052. void CObjectEditor::OnDelMethod()
  2053. {
  2054. // Find out which property is selected.
  2055. // ====================================
  2056. LRESULT nIndex = SendMessage(m_hMethodList, LB_GETCURSEL, 0, 0);
  2057. if (nIndex == LB_ERR)
  2058. return;
  2059. char buf[TEMP_BUF];
  2060. *buf = 0;
  2061. SendMessage(m_hMethodList, LB_GETTEXT, nIndex, LPARAM(buf));
  2062. if (*buf == 0)
  2063. return;
  2064. WString WName = buf;
  2065. if(FAILED(m_pObj->DeleteMethod(LPWSTR(WName))))
  2066. {
  2067. MessageBox(NULL, IDS_CANNOT_EDIT_METHOD, IDS_ERROR,
  2068. MB_OK|MB_ICONSTOP);
  2069. return;
  2070. }
  2071. Refresh();
  2072. }