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.

258 lines
5.3 KiB

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