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.

261 lines
5.5 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: WMIParse.cpp
  4. //
  5. // Copyright (c) 1995-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. // Author: Kjell Swedin
  8. // Maintainer: MikeCo, JackN
  9. //
  10. //-----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "string.h"
  13. #include "WMIParse.h"
  14. #include "resource.h"
  15. #include "WMIlfile.h"
  16. #include "WMIlprs.h"
  17. //*****************************************************************************
  18. //
  19. // CWMILocParser Construction
  20. //
  21. //*****************************************************************************
  22. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  23. //
  24. // Constructor for CWMILocParser.
  25. //
  26. //-----------------------------------------------------------------------------
  27. CWMILocParser::CWMILocParser() : CPULocParser(g_hDll)
  28. {
  29. m_fOptionInit = FALSE;
  30. IncrementClassCount();
  31. }
  32. CWMILocParser::~CWMILocParser()
  33. {
  34. DEBUGONLY(AssertValid());
  35. DecrementClassCount();
  36. // Remove any options
  37. UnRegisterOptions();
  38. }
  39. //*****************************************************************************
  40. //
  41. // CWMILocParser Overrides
  42. //
  43. //*****************************************************************************
  44. ///////////////////////////////////////////////////////////////////////////////
  45. //
  46. // ILocVersion
  47. //
  48. ///////////////////////////////////////////////////////////////////////////////
  49. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  50. //
  51. // Reports the parser version information.
  52. //
  53. //-----------------------------------------------------------------------------
  54. void
  55. CWMILocParser::OnGetParserVersion(
  56. DWORD &dwMajor,
  57. DWORD &dwMinor,
  58. BOOL &fDebug) const
  59. {
  60. dwMajor = dwCurrentMajorVersion;
  61. dwMinor = dwCurrentMinorVersion;
  62. fDebug = fCurrentDebugMode;
  63. }
  64. ///////////////////////////////////////////////////////////////////////////////
  65. //
  66. // ILocParser
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70. //
  71. // Initializes the parser. Registers options for the WMI parser.
  72. //
  73. //-----------------------------------------------------------------------------
  74. HRESULT
  75. CWMILocParser::OnInit(
  76. IUnknown * pUnk
  77. )
  78. {
  79. UNREFERENCED_PARAMETER(pUnk);
  80. LTASSERT(!m_fOptionInit);
  81. RegisterOptions();
  82. return ERROR_SUCCESS;
  83. }
  84. HRESULT
  85. CWMILocParser::OnCreateFileInstance(
  86. ILocFile *&pLocFile,
  87. FileType ft)
  88. {
  89. SCODE sc = E_INVALIDARG;
  90. pLocFile = NULL;
  91. if (ft == ftUnknown ||
  92. ft == ftWMIFileType)
  93. {
  94. try
  95. {
  96. pLocFile = new CWMILocFile(NULL);
  97. sc = S_OK;
  98. }
  99. catch (const CMemoryException *)
  100. {
  101. sc = E_OUTOFMEMORY;
  102. }
  103. }
  104. return ResultFromScode(sc);
  105. }
  106. void
  107. CWMILocParser::OnGetParserInfo(
  108. ParserInfo &pi)
  109. const
  110. {
  111. LTASSERT(pi.elExtensions.GetCount() == 0);
  112. pi.aParserIds.SetSize(1);
  113. pi.aParserIds[0].m_pid = pidWMI;
  114. pi.aParserIds[0].m_pidParent = pidNone;
  115. try
  116. {
  117. LTVERIFY(pi.strDescription.LoadString(g_hDll, IDS_WMI_PARSER_DESC));
  118. LTVERIFY(pi.strHelp.LoadString(g_hDll, IDS_OPT_HELP));
  119. pi.elExtensions.AddTail("MOF");
  120. }
  121. catch (CMemoryException *pe)
  122. {
  123. pi.strDescription.Empty();
  124. pe->Delete();
  125. }
  126. }
  127. void
  128. CWMILocParser::OnGetFileDescriptions(
  129. CEnumCallback &cb)
  130. const
  131. {
  132. CWMILocFile::GetFileDescriptions(cb);
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////
  135. //
  136. // ILocStringValidation
  137. //
  138. ///////////////////////////////////////////////////////////////////////////////
  139. CVC::ValidationCode
  140. CWMILocParser::OnValidateString(
  141. const CLocTypeId &ltiType,
  142. const CLocTranslation &trTrans,
  143. CReporter *pReporter,
  144. const CContext &context)
  145. {
  146. CLString strContext;
  147. DEBUGONLY(ltiType.AssertValid());
  148. DEBUGONLY(trTrans.AssertValid());
  149. LTASSERT(pReporter != NULL);
  150. DEBUGONLY(pReporter->AssertValid());
  151. return ::ValidateString(ltiType, trTrans.GetTargetString(), *pReporter,
  152. context.GetLocation(), context.GetContext());
  153. }
  154. //*****************************************************************************
  155. //
  156. // Parser options.
  157. //
  158. //*****************************************************************************
  159. // Reference count the registering of options since these are global to the
  160. // parser.
  161. static INT g_nOptionRegisterCount = 0;
  162. BEGIN_LOC_UI_OPTIONS_BOOL(optsParserBools)
  163. LOC_UI_OPTIONS_BOOL_ENTRY(OPT_DISABLE_WATERMARKING,
  164. FALSE, CLocUIOption::etCheckBox,
  165. IDS_DISABLE_WATERMARKING_BOOL,
  166. IDS_DISABLE_WATERMARKING_BOOL_HELP,
  167. NULL, CLocUIOption::stUser | CLocUIOption::stOverride),
  168. END_LOC_UI_OPTIONS_BOOL();
  169. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  170. //
  171. // Register any options for the parser.
  172. //
  173. //-----------------------------------------------------------------------------
  174. void
  175. CWMILocParser::RegisterOptions()
  176. {
  177. LTASSERT(g_nOptionRegisterCount >= 0);
  178. if (g_nOptionRegisterCount++ > 0)
  179. {
  180. // Already registered
  181. return;
  182. }
  183. SmartRef<CLocUIOptionSet> spOptSet;
  184. CLocUIOptionImpHelper OptHelp(g_hDll);
  185. spOptSet = new CLocUIOptionSetDef;
  186. spOptSet->SetGroupName(g_puid.GetName());
  187. OptHelp.SetBools(optsParserBools, COUNTOF(optsParserBools));
  188. OptHelp.GetOptions(spOptSet.GetInterface(), IDS_OPT_DESC,
  189. IDS_OPT_HELP);
  190. m_fOptionInit = RegisterParserOptions(spOptSet.GetInterface());
  191. if (m_fOptionInit)
  192. {
  193. spOptSet.Extract();
  194. }
  195. }
  196. void
  197. CWMILocParser::UnRegisterOptions()
  198. {
  199. if (m_fOptionInit)
  200. {
  201. if (--g_nOptionRegisterCount == 0)
  202. {
  203. UnRegisterParserOptions(g_puid);
  204. }
  205. }
  206. }