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.

168 lines
4.0 KiB

  1. #include <precomp.hxx>
  2. #pragma hdrstop
  3. #include "policy.h"
  4. //
  5. // Names of registry/INI file sections and values.
  6. //
  7. TCHAR CPolicy::SZ_REGINI_WATCHDOG[] = TEXT("DiskQuotaWatchDog");
  8. TCHAR CPolicy::SZ_REGINI_SHOW_CLIENT_DIALOG[] = TEXT("ShowClientDialog");
  9. TCHAR CPolicy::SZ_REGINI_SEND_USER_EMAIL[] = TEXT("SendUserEmail");
  10. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_TO[] = TEXT("SendEmailTo");
  11. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_CC[] = TEXT("SendEmailCc");
  12. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_BCC[] = TEXT("SendEmailBcc");
  13. BOOL CPolicy::I_REGINI_SEND_USER_EMAIL_DEFAULT = 1;
  14. BOOL CPolicy::I_REGINI_SHOW_CLIENT_DIALOG_DEFAULT = 0;
  15. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_TO_DEFAULT[] = TEXT("[email protected]");
  16. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_CC_DEFAULT[] = TEXT("");
  17. TCHAR CPolicy::SZ_REGINI_SEND_EMAIL_BCC_DEFAULT[] = TEXT("");
  18. CPolicy::CPolicy(
  19. VOID
  20. ) : m_bSendUserEmail(FALSE),
  21. m_bShowClientDialog(FALSE)
  22. {
  23. }
  24. CPolicy::~CPolicy(
  25. VOID
  26. )
  27. {
  28. //
  29. // Nothing to do.
  30. //
  31. }
  32. VOID
  33. CPolicy::Reset(
  34. VOID
  35. )
  36. {
  37. m_bSendUserEmail = FALSE;
  38. m_bShowClientDialog = FALSE;
  39. m_strOtherEmailTo.Empty();
  40. m_strOtherEmailCc.Empty();
  41. m_strOtherEmailBcc.Empty();
  42. }
  43. HRESULT
  44. CPolicy::Load(
  45. LPCTSTR pszIniFile
  46. )
  47. {
  48. //
  49. // Clear out previous policy contents.
  50. //
  51. Reset();
  52. //
  53. // Load the contents of the INI file using appropriate defaults
  54. // if any values are not found.
  55. //
  56. LoadString(pszIniFile,
  57. SZ_REGINI_WATCHDOG,
  58. SZ_REGINI_SEND_EMAIL_TO,
  59. SZ_REGINI_SEND_EMAIL_TO_DEFAULT,
  60. m_strOtherEmailTo);
  61. LoadString(pszIniFile,
  62. SZ_REGINI_WATCHDOG,
  63. SZ_REGINI_SEND_EMAIL_CC,
  64. SZ_REGINI_SEND_EMAIL_CC_DEFAULT,
  65. m_strOtherEmailCc);
  66. LoadString(pszIniFile,
  67. SZ_REGINI_WATCHDOG,
  68. SZ_REGINI_SEND_EMAIL_BCC,
  69. SZ_REGINI_SEND_EMAIL_BCC_DEFAULT,
  70. m_strOtherEmailBcc);
  71. m_bShowClientDialog = GetPrivateProfileInt(SZ_REGINI_WATCHDOG,
  72. SZ_REGINI_SHOW_CLIENT_DIALOG,
  73. I_REGINI_SHOW_CLIENT_DIALOG_DEFAULT,
  74. pszIniFile);
  75. m_bSendUserEmail = GetPrivateProfileInt(SZ_REGINI_WATCHDOG,
  76. SZ_REGINI_SEND_USER_EMAIL,
  77. I_REGINI_SEND_USER_EMAIL_DEFAULT,
  78. pszIniFile);
  79. return NO_ERROR;
  80. }
  81. //
  82. // Loads policy string. Handles proper sizing of the value buffer.
  83. // Caller is responsible for calling delete[] on *ppsz.
  84. //
  85. HRESULT
  86. CPolicy::LoadString(
  87. LPCTSTR pszFile,
  88. LPCTSTR pszSection,
  89. LPCTSTR pszValueName,
  90. LPCTSTR pszDefaultValue,
  91. CString& strOut
  92. )
  93. {
  94. HRESULT hr = E_OUTOFMEMORY;
  95. INT cchIncr = MAX_PATH;
  96. INT cchValue = 0;
  97. INT cchRead = 0;
  98. do
  99. {
  100. cchValue += cchIncr;
  101. cchRead = GetPrivateProfileString(pszSection,
  102. pszValueName,
  103. pszDefaultValue,
  104. strOut.GetBuffer(cchValue),
  105. cchValue,
  106. pszFile);
  107. if (0 == cchRead)
  108. {
  109. hr = E_FAIL;
  110. }
  111. }
  112. while(SUCCEEDED(hr) && cchRead == (cchValue - 1));
  113. return hr;
  114. }
  115. HRESULT
  116. CPolicy::Load(
  117. HKEY hkeyReg
  118. )
  119. {
  120. HRESULT hr = NO_ERROR;
  121. //
  122. // Clear out previous policy contents.
  123. //
  124. Reset();
  125. return hr;
  126. }
  127. //
  128. // Should we send any email?
  129. //
  130. BOOL
  131. CPolicy::ShouldSendAnyEmail(
  132. VOID
  133. ) const
  134. {
  135. return ShouldSendUserEmail() ||
  136. 0 != m_strOtherEmailTo.Length() ||
  137. 0 != m_strOtherEmailCc.Length() ||
  138. 0 != m_strOtherEmailBcc.Length();
  139. }