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.

349 lines
8.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. Servpp.h
  7. Server properties implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "Servpp.h"
  12. #include "server.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. BOOL IsLocalSystemAccount(LPCTSTR pszAccount)
  19. {
  20. BOOL fLocal = FALSE;
  21. CString strLocalSystemAccount;
  22. if (pszAccount != NULL)
  23. {
  24. strLocalSystemAccount.LoadString(IDS_LOCAL_SYSTEM_ACCOUNT);
  25. if (strLocalSystemAccount.CompareNoCase(pszAccount) == 0)
  26. fLocal = TRUE;
  27. }
  28. return fLocal;
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. //
  32. // CMachineProperties holder
  33. //
  34. /////////////////////////////////////////////////////////////////////////////
  35. CMachineProperties::CMachineProperties
  36. (
  37. ITFSNode * pNode,
  38. IComponentData * pComponentData,
  39. ITFSComponentData * pTFSCompData,
  40. ISpdInfo * pSpdInfo,
  41. LPCTSTR pszSheetName,
  42. BOOL fSpdInfoLoaded
  43. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName),
  44. m_fSpdInfoLoaded(fSpdInfoLoaded)
  45. {
  46. //ASSERT(pFolderNode == GetContainerNode());
  47. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  48. AddPageToList((CPropertyPageBase*) &m_pageRefresh);
  49. Assert(pTFSCompData != NULL);
  50. m_spTFSCompData.Set(pTFSCompData);
  51. m_spSpdInfo.Set(pSpdInfo);
  52. }
  53. CMachineProperties::~CMachineProperties()
  54. {
  55. RemovePageFromList((CPropertyPageBase*) &m_pageRefresh, FALSE);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CMachinePropRefresh property page
  59. IMPLEMENT_DYNCREATE(CMachinePropRefresh, CPropertyPageBase)
  60. CMachinePropRefresh::CMachinePropRefresh() : CPropertyPageBase(CMachinePropRefresh::IDD)
  61. {
  62. //{{AFX_DATA_INIT(CMachinePropRefresh)
  63. // NOTE: the ClassWizard will add member initialization here
  64. //}}AFX_DATA_INIT
  65. }
  66. CMachinePropRefresh::~CMachinePropRefresh()
  67. {
  68. }
  69. void CMachinePropRefresh::DoDataExchange(CDataExchange* pDX)
  70. {
  71. CPropertyPageBase::DoDataExchange(pDX);
  72. //{{AFX_DATA_MAP(CMachinePropRefresh)
  73. DDX_Control(pDX, IDC_EDIT_SECONDS, m_editSeconds);
  74. DDX_Control(pDX, IDC_EDIT_MINUTES, m_editMinutes);
  75. DDX_Control(pDX, IDC_SPIN_SECONDS, m_spinSeconds);
  76. DDX_Control(pDX, IDC_SPIN_MINUTES, m_spinMinutes);
  77. DDX_Control(pDX, IDC_CHECK_ENABLE_STATS, m_checkEnableStats);
  78. DDX_Control(pDX, IDC_CHECK_ENABLE_DNS, m_checkEnableDns);
  79. //}}AFX_DATA_MAP
  80. }
  81. BEGIN_MESSAGE_MAP(CMachinePropRefresh, CPropertyPageBase)
  82. //{{AFX_MSG_MAP(CMachinePropRefresh)
  83. ON_BN_CLICKED(IDC_CHECK_ENABLE_STATS, OnCheckEnableStats)
  84. ON_BN_CLICKED(IDC_CHECK_ENABLE_DNS, OnCheckEnableDns)
  85. ON_EN_CHANGE(IDC_EDIT_MINUTES, OnChangeEditMinutes)
  86. ON_EN_CHANGE(IDC_EDIT_SECONDS, OnChangeEditSeconds)
  87. //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMachinePropRefresh message handlers
  91. BOOL CMachinePropRefresh::OnInitDialog()
  92. {
  93. CPropertyPageBase::OnInitDialog();
  94. m_spinMinutes.SetRange(0, AUTO_REFRESH_MINUTES_MAX);
  95. m_spinSeconds.SetRange(0, AUTO_REFRESH_SECONDS_MAX);
  96. m_checkEnableStats.SetCheck(m_bAutoRefresh);
  97. m_checkEnableDns.SetCheck(m_bEnableDns);
  98. // update the refresh interval
  99. int nMinutes, nSeconds;
  100. DWORD dwRefreshInterval = m_dwRefreshInterval;
  101. nMinutes = dwRefreshInterval / MILLISEC_PER_MINUTE;
  102. dwRefreshInterval -= nMinutes * MILLISEC_PER_MINUTE;
  103. nSeconds = dwRefreshInterval / MILLISEC_PER_SECOND;
  104. dwRefreshInterval -= nSeconds * MILLISEC_PER_SECOND;
  105. m_spinMinutes.SetPos(nMinutes);
  106. m_spinSeconds.SetPos(nSeconds);
  107. m_editMinutes.LimitText(2);
  108. m_editSeconds.LimitText(2);
  109. // set the button states
  110. UpdateButtons();
  111. SetDirty(FALSE);
  112. return TRUE; // return TRUE unless you set the focus to a control
  113. // EXCEPTION: OCX Property Pages should return FALSE
  114. }
  115. void CMachinePropRefresh::UpdateButtons()
  116. {
  117. int nCheck = m_checkEnableStats.GetCheck();
  118. GetDlgItem(IDC_EDIT_MINUTES)->EnableWindow(nCheck != 0);
  119. GetDlgItem(IDC_EDIT_SECONDS)->EnableWindow(nCheck != 0);
  120. GetDlgItem(IDC_SPIN_MINUTES)->EnableWindow(nCheck != 0);
  121. GetDlgItem(IDC_SPIN_SECONDS)->EnableWindow(nCheck != 0);
  122. GetDlgItem(IDC_CHECK_ENABLE_DNS)->EnableWindow(nCheck != 0);
  123. }
  124. void CMachinePropRefresh::OnCheckEnableStats()
  125. {
  126. SetDirty(TRUE);
  127. UpdateButtons();
  128. }
  129. void CMachinePropRefresh::OnCheckEnableDns()
  130. {
  131. SetDirty(TRUE);
  132. UpdateButtons();
  133. }
  134. void CMachinePropRefresh::OnChangeEditMinutes()
  135. {
  136. ValidateMinutes();
  137. SetDirty(TRUE);
  138. }
  139. void CMachinePropRefresh::OnChangeEditSeconds()
  140. {
  141. ValidateSeconds();
  142. SetDirty(TRUE);
  143. }
  144. void CMachinePropRefresh::ValidateMinutes()
  145. {
  146. CString strValue;
  147. int nValue;
  148. if (m_editMinutes.GetSafeHwnd() != NULL)
  149. {
  150. m_editMinutes.GetWindowText(strValue);
  151. if (!strValue.IsEmpty())
  152. {
  153. nValue = _ttoi(strValue);
  154. if ((nValue >= 0) &&
  155. (nValue <= AUTO_REFRESH_MINUTES_MAX))
  156. {
  157. // everything is good
  158. return;
  159. }
  160. if (nValue > AUTO_REFRESH_MINUTES_MAX)
  161. nValue = AUTO_REFRESH_MINUTES_MAX;
  162. else
  163. if (nValue < 0)
  164. nValue = 0;
  165. // set the new value and beep
  166. CString strText;
  167. LPTSTR pBuf = strText.GetBuffer(5);
  168. _itot(nValue, pBuf, 10);
  169. strText.ReleaseBuffer();
  170. MessageBeep(MB_ICONEXCLAMATION);
  171. m_editMinutes.SetWindowText(strText);
  172. m_editMinutes.SetSel(0, -1);
  173. m_editMinutes.SetFocus();
  174. }
  175. }
  176. }
  177. void CMachinePropRefresh::ValidateSeconds()
  178. {
  179. CString strValue;
  180. int nValue;
  181. if (m_editSeconds.GetSafeHwnd() != NULL)
  182. {
  183. m_editSeconds.GetWindowText(strValue);
  184. if (!strValue.IsEmpty())
  185. {
  186. nValue = _ttoi(strValue);
  187. if ((nValue >= 0) &&
  188. (nValue <= AUTO_REFRESH_SECONDS_MAX))
  189. {
  190. // everything is good
  191. return;
  192. }
  193. if (nValue > AUTO_REFRESH_SECONDS_MAX)
  194. nValue = AUTO_REFRESH_SECONDS_MAX;
  195. else
  196. if (nValue < 0)
  197. nValue = 0;
  198. CString strText;
  199. LPTSTR pBuf = strText.GetBuffer(5);
  200. _itot(nValue, pBuf, 10);
  201. strText.ReleaseBuffer();
  202. MessageBeep(MB_ICONEXCLAMATION);
  203. m_editSeconds.SetWindowText(strText);
  204. m_editSeconds.SetSel(0, -1);
  205. m_editSeconds.SetFocus();
  206. }
  207. }
  208. }
  209. BOOL CMachinePropRefresh::OnApply()
  210. {
  211. if (!IsDirty())
  212. return TRUE;
  213. UpdateData();
  214. m_bAutoRefresh = (m_checkEnableStats.GetCheck() == 1) ? TRUE : FALSE;
  215. m_bEnableDns = (m_checkEnableDns.GetCheck() == 1) ? TRUE : FALSE;
  216. // Make sure that EnableDns only if AutoRefresh is enabled
  217. if (m_bEnableDns && !m_bAutoRefresh) {
  218. m_bEnableDns = FALSE;
  219. }
  220. int nMinutes = m_spinMinutes.GetPos();
  221. int nSeconds = m_spinSeconds.GetPos();
  222. //use minutes as seconds.
  223. m_dwRefreshInterval = nMinutes * MILLISEC_PER_MINUTE;
  224. m_dwRefreshInterval += nSeconds * MILLISEC_PER_SECOND;
  225. if (m_bAutoRefresh && m_dwRefreshInterval == 0)
  226. {
  227. CString strMessage;
  228. AfxMessageBox(IDS_ERR_AUTO_REFRESH_ZERO);
  229. m_editMinutes.SetSel(0, -1);
  230. m_editMinutes.SetFocus();
  231. return FALSE;
  232. }
  233. BOOL bRet = CPropertyPageBase::OnApply();
  234. if (bRet == FALSE)
  235. {
  236. // Something bad happened... grab the error code
  237. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  238. ::IpsmMessageBox(GetHolder()->GetError());
  239. }
  240. return bRet;
  241. }
  242. BOOL CMachinePropRefresh::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  243. {
  244. SPITFSNode spNode;
  245. CIpsmServer * pServer;
  246. DWORD dwError;
  247. // do stuff here.
  248. BEGIN_WAIT_CURSOR;
  249. spNode = GetHolder()->GetNode();
  250. pServer = GETHANDLER(CIpsmServer, spNode);
  251. pServer->SetAutoRefresh(spNode, m_bAutoRefresh, m_dwRefreshInterval);
  252. pServer->SetDnsResolve(spNode, m_bEnableDns);
  253. SPITFSNodeMgr spNodeMgr;
  254. SPITFSNode spRootNode;
  255. spNode->GetNodeMgr(&spNodeMgr);
  256. spNodeMgr->GetRootNode(&spRootNode);
  257. spRootNode->SetData(TFS_DATA_DIRTY, TRUE);
  258. END_WAIT_CURSOR;
  259. return FALSE;
  260. }