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.

130 lines
4.2 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. PERSISTCFG.H
  5. Abstract:
  6. This file implements the WinMgmt persistent configuration operations.
  7. Classes implemented:
  8. CPersistentConfig persistent configuration manager
  9. History:
  10. 1/13/98 paulall Created.
  11. --*/
  12. #ifndef _persistcfg_h_
  13. #define _persistcfg_h_
  14. #include "corepol.h"
  15. #include "sync.h"
  16. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  17. // WHEN ADDING A NEW VALUE
  18. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  19. //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  20. #define PERSIST_CFGVAL_CORE_DATABASE_DIRTY 0
  21. #define PERSIST_CFGVAL_CORE_ESS_NEEDS_LOADING 1
  22. #define PERSIST_CFGVAL_CORE_NEEDSBACKUPCHECK 2
  23. #define PERSIST_CFGVAL_CORE_FSREP_VERSION 3
  24. //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  25. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  26. // WHEN ADDING A NEW VALUE
  27. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  28. //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  29. #define PERSIST_CFGVAL_MAX_NUM_EVENTS 4
  30. //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  31. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  32. // WHEN ADDING A NEW VALUE
  33. //****** UPDATE PERSIST_CFGVAL_MAX_NUM_EVENTS *******
  34. class CDirectoryPath
  35. {
  36. TCHAR *pszDirectory ;
  37. public:
  38. CDirectoryPath();
  39. ~CDirectoryPath(){if(pszDirectory) delete pszDirectory;};
  40. TCHAR * GetStr(void){return pszDirectory;};
  41. };
  42. /*=============================================================================
  43. *
  44. * class CPersistentConfig
  45. *
  46. * Retrieves and stores persistent configuration in the $WinMgmt.CFG file.
  47. * All writes are going to be committed to disk by the return of the
  48. * operation.
  49. *=============================================================================
  50. */
  51. #pragma warning (disable : 4251)
  52. class POLARITY CPersistentConfig
  53. {
  54. public:
  55. //Number of items in the config array. Requesting/setting values
  56. //outside this range will fail the operation.
  57. enum { MaxNumberConfigEntries = PERSIST_CFGVAL_MAX_NUM_EVENTS };
  58. //Constructor. Initialises the structure.
  59. CPersistentConfig();
  60. //Retrieves the configuration from the configuration file if it
  61. //has not yet been retrieved into memory, or retrieves it from a
  62. //memory cache.
  63. // dwOffset needs to be less than MaxNumberConfigEntries and specifies
  64. // the configuration entry required.
  65. // dwValue if sucessful this will contain the value. If the value
  66. // has not been set this will return 0.
  67. // BOOL returns TRUE if successful.
  68. BOOL GetPersistentCfgValue(DWORD dwOffset, DWORD &dwValue);
  69. //Stores the value into the configuration file and to the
  70. //memory cache if it exists. The replacment of the original
  71. //file (if it exists) is the last thing it does.
  72. // dwOffset needs to be less than MaxNumberConfigEntries and specifies
  73. // the configuration entry required.
  74. // dwValue is the value to set the configuration to.
  75. // BOOL returns TRUE if successful.
  76. BOOL SetPersistentCfgValue(DWORD dwOffset, DWORD dwValue);
  77. //Should be called once at startup to make sure the configuration files are
  78. //in a stable state.
  79. void CPersistentConfig::TidyUp();
  80. protected:
  81. //Reads the $WinMgmt.CFG file into the memory cache.
  82. // BOOL returns TRUE if successful.
  83. BOOL ReadConfig();
  84. //Writes the $WinMgmt.CFG file into the memory cache and to the file. It
  85. //protects the existing file until the last minute.
  86. // BOOL returns TRUE if successful.
  87. BOOL WriteConfig();
  88. private:
  89. //This is the memory cache of the configuration.
  90. static DWORD m_ConfigValues[PERSIST_CFGVAL_MAX_NUM_EVENTS];
  91. static bool m_bInitialized;
  92. //Directory of persistent date
  93. static CDirectoryPath m_Directory ;
  94. static CCritSec m_cs;
  95. //Returns a filename with a full DB path prepended to the
  96. //specified filename. Need to delete[] the string returned.
  97. TCHAR *GetFullFilename(const TCHAR *pszFilename);
  98. //Returns TRUE if the file exists, FALSE otherwise (or if an error
  99. //occurs while opening the file.
  100. BOOL FileExists(const TCHAR *pszFilename);
  101. };
  102. #endif