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.

142 lines
3.2 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "rssubdat.h"
  4. ///////////////////////////////////////////////////////////////////////////////
  5. // Public methods
  6. ///////////////////////////////////////////////////////////////////////////////
  7. BOOL CRSSubData::InitRegSupport(HKEY hkey, LPCTSTR pszKey1, LPCTSTR pszKey2,
  8. LPCTSTR pszKey3, DWORD cbSizeOfData,
  9. BOOL fVolatile)
  10. {
  11. DWORD dwDefaultOptions = REG_OPTION_NON_VOLATILE;
  12. if (fVolatile)
  13. {
  14. dwDefaultOptions = REG_OPTION_VOLATILE;
  15. }
  16. _SetSizeOfData(cbSizeOfData);
  17. RSInitRoot(hkey, pszKey1, pszKey2, REG_OPTION_NON_VOLATILE, dwDefaultOptions);
  18. RSCVInitSubKey(pszKey3);
  19. return TRUE;
  20. }
  21. BOOL CRSSubData::Update()
  22. {
  23. BOOL fRet = TRUE;
  24. BOOL fNeedUpdate = FALSE;
  25. if (!_fHoldUpdate)
  26. {
  27. if (_IsValid())
  28. {
  29. if (!_RSCVIsValidVersion())
  30. {
  31. DWORD cbSizeOfData = _cbSizeOfData;
  32. if (RSGetDWORDValue(RSCVGetSubKey(), TEXT("LastUpdate"), _GetTickLastUpdatePtr()) &&
  33. RSGetBinaryValue(RSCVGetSubKey(), TEXT("Cache"), (PBYTE)_GetDataPtr(), &cbSizeOfData))
  34. {
  35. if (cbSizeOfData != _cbSizeOfData)
  36. {
  37. fNeedUpdate = TRUE;
  38. }
  39. else
  40. {
  41. _RSCVUpdateVersionOnCacheRead();
  42. }
  43. }
  44. else
  45. {
  46. fNeedUpdate = TRUE;
  47. }
  48. }
  49. // Is the information expired?
  50. if (!fNeedUpdate && _IsExpired())
  51. {
  52. // Yes
  53. fNeedUpdate = TRUE;
  54. }
  55. }
  56. if (!_IsValid() || fNeedUpdate)
  57. {
  58. Invalidate();
  59. fRet = CSubData::Update();
  60. if (fRet)
  61. {
  62. _Propagate();
  63. }
  64. }
  65. }
  66. return fRet;
  67. }
  68. BOOL CRSSubData::Propagate()
  69. {
  70. return _Propagate();
  71. }
  72. BOOL CRSSubData::ExistInReg()
  73. {
  74. return RSSubKeyExist(RSCVGetSubKey());
  75. }
  76. void CRSSubData::WipeReg()
  77. {
  78. RSDeleteSubKey(RSCVGetSubKey());
  79. }
  80. void CRSSubData::Invalidate()
  81. {
  82. _RSCVIncrementRegVersion();
  83. CSubData::Invalidate();
  84. }
  85. CRSSubData::CRSSubData()
  86. {}
  87. void CRSSubData::_RSCVDeleteRegCache()
  88. {
  89. RSDeleteValue(RSCVGetSubKey(), TEXT("LastUpdate"));
  90. RSDeleteValue(RSCVGetSubKey(), TEXT("Cache"));
  91. }
  92. BOOL CRSSubData::_Propagate()
  93. {
  94. RSSetDWORDValue(RSCVGetSubKey(), TEXT("LastUpdate"), _GetTickLastUpdate());
  95. RSSetBinaryValue(RSCVGetSubKey(), TEXT("Cache"), (PBYTE)_GetDataPtr(), _cbSizeOfData);
  96. // HACKHACK - we increment twice, because it dont work if we do it only once.
  97. _RSCVUpdateVersionOnCacheWrite();
  98. _RSCVUpdateVersionOnCacheWrite();
  99. return TRUE;
  100. }
  101. BOOL CRSSubData::_RSSDGetDataFromReg()
  102. {
  103. DWORD cbSizeOfData = _cbSizeOfData;
  104. return RSGetBinaryValue(RSCVGetSubKey(), TEXT("Cache"),
  105. (PBYTE)_GetDataPtr(), &cbSizeOfData);
  106. }
  107. void CRSSubData::_SetSizeOfData(DWORD cbSizeOfData)
  108. {
  109. _cbSizeOfData = cbSizeOfData;
  110. }
  111. DWORD CRSSubData::_GetSizeOfData()
  112. {
  113. return _cbSizeOfData;
  114. }