ConfigParser.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. // API for methods that the ConfigParser can call
  7. // Implement these methods to customize what happens when the configuration is loaded
  8. class ConfigParserAPI
  9. {
  10. public:
  11. // If the -Console flag is passed in, this method is called with a buffer
  12. // The implementor will fill in the buffer and return true if a custom Console window title is desired
  13. // To not change the console title, return false
  14. static bool FillConsoleTitle(__ecount(cchBufferSize) LPWSTR buffer, size_t cchBufferSize, __in LPWSTR moduleName);
  15. // If one of the following flags:
  16. // - Console
  17. // - OutputFile
  18. // - DebugWindow
  19. // - InMemoryTrace
  20. // is set, then the ConfigParser will call the following method to give the implementor
  21. // a chance to output any headers at initialization time.
  22. static void DisplayInitialOutput(__in LPWSTR moduleName);
  23. };
  24. class ConfigParser
  25. {
  26. private:
  27. static const int MaxTokenSize = 512;
  28. static const int MaxRegSize = 2048;
  29. static const LPWSTR featureKeyName ;
  30. bool _hasReadConfig;
  31. CLANG_WNO_BEGIN("-Wunused-private-field")
  32. Js::ConfigFlagsTable& _flags;
  33. const LPCWSTR _configFileName;
  34. CLANG_WNO_END
  35. void ParseRegistryKey(HKEY hk, CmdLineArgsParser &parser);
  36. #ifdef _WIN32
  37. static void ConfigParser::SetConfigStringFromRegistry(_In_ HKEY hk, _In_z_ const char16* subKeyName, _In_z_ const char16* valName, _Inout_ Js::String& str);
  38. static void ConfigParser::ReadRegistryString(_In_ HKEY hk, _In_z_ const char16* subKeyName, _In_z_ const char16* valName, _Outptr_result_maybenull_z_ const char16** sz, _Out_ DWORD* length);
  39. #endif
  40. public:
  41. static ConfigParser s_moduleConfigParser;
  42. ConfigParser(Js::ConfigFlagsTable& outputFlags, __in LPCWSTR configFileName = _u("jscript")) :
  43. _flags(outputFlags),
  44. _hasReadConfig(false),
  45. _configFileName(configFileName)
  46. {
  47. }
  48. static void ParseOnModuleLoad(CmdLineArgsParser& parser, HANDLE hMod);
  49. #ifdef ENABLE_TEST_HOOKS
  50. static void ParseCustomConfigFile(CmdLineArgsParser& parser, const char16* strConfigFile)
  51. {
  52. s_moduleConfigParser.ParseConfig(NULL /* hMod */, parser, strConfigFile);
  53. }
  54. #endif
  55. void ParseConfig(HANDLE hmod, CmdLineArgsParser &parser, const char16* strCustomConfigFile = nullptr);
  56. void ParseRegistry(CmdLineArgsParser &parser);
  57. void ProcessConfiguration(HANDLE mod);
  58. HRESULT SetOutputFile(const WCHAR* outputFile, const WCHAR* openMode);
  59. bool HasReadConfig() { return _hasReadConfig; }
  60. };