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.

1680 lines
40 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. repnodpp.cpp
  7. Replication Node Property page
  8. FILE HISTORY:
  9. */
  10. // RepNodpp.cpp : implementation file
  11. //
  12. #include "stdafx.h"
  13. #include "winssnap.h"
  14. #include "server.h"
  15. #include "ipadddlg.h"
  16. #include "tregkey.h"
  17. #include "RepNodpp.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. #define MAX_DAY UD_MAXVAL
  24. #define MAX_HOUR 23
  25. #define MAX_MINUTE 59
  26. const CRepNodePropAdvanced::REGKEYNAME CRepNodePropAdvanced::lpstrPartnersRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Partners");
  27. const LPCTSTR lpstrPersonaMode = _T("PersonaMode");
  28. const LPCTSTR lpstrPersonaNonGrata = _T("PersonaNonGrata");
  29. const LPCTSTR lpstrPersonaGrata = _T("PersonaGrata");
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CRepNodePropGen property page
  32. IMPLEMENT_DYNCREATE(CRepNodePropGen, CPropertyPageBase)
  33. CRepNodePropGen::CRepNodePropGen() : CPropertyPageBase(CRepNodePropGen::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CRepNodePropGen)
  36. m_fMigrate = FALSE;
  37. m_fPushwithPartners = FALSE;
  38. //}}AFX_DATA_INIT
  39. }
  40. CRepNodePropGen::~CRepNodePropGen()
  41. {
  42. }
  43. void CRepNodePropGen::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CPropertyPageBase::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CRepNodePropGen)
  47. DDX_Control(pDX, IDC_CHECK_REP_WITH_PARTNERS, m_checkPushwithPartners);
  48. DDX_Control(pDX, IDC_CHECK_MIGRATE, m_checkMigrate);
  49. DDX_Check(pDX, IDC_CHECK_MIGRATE, m_fMigrate);
  50. DDX_Check(pDX, IDC_CHECK_REP_WITH_PARTNERS, m_fPushwithPartners);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CRepNodePropGen, CPropertyPageBase)
  54. //{{AFX_MSG_MAP(CRepNodePropGen)
  55. ON_BN_CLICKED(IDC_CHECK_MIGRATE, OnCheckMigrate)
  56. ON_BN_CLICKED(IDC_CHECK_REP_WITH_PARTNERS, OnCheckRepWithPartners)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CRepNodePropGen message handlers
  61. BOOL
  62. CRepNodePropGen::OnApply()
  63. {
  64. if (!IsDirty())
  65. return TRUE;
  66. HRESULT hr = UpdateServerConfiguration();
  67. if (FAILED(hr))
  68. {
  69. return FALSE;
  70. }
  71. else
  72. {
  73. return CPropertyPageBase::OnApply();
  74. }
  75. }
  76. void
  77. CRepNodePropGen::OnOK()
  78. {
  79. CPropertyPageBase::OnOK();
  80. }
  81. BOOL
  82. CRepNodePropGen::OnInitDialog()
  83. {
  84. CPropertyPageBase::OnInitDialog();
  85. SPITFSNode spNode;
  86. CWinsServerHandler *pServer;
  87. SPITFSNode spParentNode;
  88. GetConfig();
  89. m_checkMigrate.SetCheck(m_pConfig->m_fMigrateOn);
  90. m_checkPushwithPartners.SetCheck(m_pConfig->m_fRplOnlyWithPartners);
  91. // load the correct icon
  92. for (int i = 0; i < ICON_IDX_MAX; i++)
  93. {
  94. if (g_uIconMap[i][1] == m_uImage)
  95. {
  96. HICON hIcon = LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(g_uIconMap[i][0]));
  97. if (hIcon)
  98. ((CStatic *) GetDlgItem(IDC_STATIC_ICON))->SetIcon(hIcon);
  99. break;
  100. }
  101. }
  102. return TRUE;
  103. }
  104. void CRepNodePropGen::OnCheckMigrate()
  105. {
  106. SetDirty(TRUE);
  107. }
  108. void CRepNodePropGen::OnCheckRepWithPartners()
  109. {
  110. SetDirty(TRUE);
  111. }
  112. /*---------------------------------------------------------------------------
  113. CRepNodePropGen::GetConfig()
  114. Gets the CConfiguration object from the server node
  115. ---------------------------------------------------------------------------*/
  116. HRESULT
  117. CRepNodePropGen::GetConfig()
  118. {
  119. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  120. HRESULT hr = hrOK;
  121. m_pConfig = ((CRepNodeProperties *) GetHolder())->GetConfig();
  122. return hr;
  123. }
  124. /*---------------------------------------------------------------------------
  125. CRepNodePropGen::UpdateServerConfiguration()
  126. Updates the values for the CConfiguration object in the Server Node
  127. ---------------------------------------------------------------------------*/
  128. HRESULT
  129. CRepNodePropGen::UpdateServerConfiguration()
  130. {
  131. // Reflect the changes in the server's CConfiguration object
  132. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  133. HRESULT hr = hrOK;
  134. SPITFSNode spNode;
  135. CWinsServerHandler *pServer;
  136. SPITFSNode spParentNode;
  137. UpdateData();
  138. // get the server
  139. spNode = GetHolder()->GetNode();
  140. // get it's parent
  141. spNode->GetParent(&spParentNode);
  142. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  143. UpdateConfig();
  144. // now write to server
  145. DWORD err = m_pConfig->Store();
  146. if (err != ERROR_SUCCESS)
  147. {
  148. // something bad happened
  149. WinsMessageBox(err);
  150. }
  151. else
  152. {
  153. // success update our local copy
  154. pServer->SetConfig(*m_pConfig);
  155. }
  156. return HRESULT_FROM_WIN32(err);
  157. }
  158. /*---------------------------------------------------------------------------
  159. CRepNodePropGen::UpdateConfig()
  160. Updates the values for the CConfiguration object in the Server Node
  161. ---------------------------------------------------------------------------*/
  162. void
  163. CRepNodePropGen::UpdateConfig()
  164. {
  165. m_pConfig->m_fMigrateOn = m_fMigrate;
  166. m_pConfig->m_fRplOnlyWithPartners = m_fPushwithPartners;
  167. }
  168. /////////////////////////////////////////////////////////////////////////////
  169. // CRepNodePropPush property page
  170. IMPLEMENT_DYNCREATE(CRepNodePropPush, CPropertyPageBase)
  171. CRepNodePropPush::CRepNodePropPush() : CPropertyPageBase(CRepNodePropPush::IDD)
  172. {
  173. //{{AFX_DATA_INIT(CRepNodePropPush)
  174. m_fRepOnAddrChange = FALSE;
  175. m_fPushStartup = FALSE;
  176. m_dwPushUpdateCount = 0;
  177. //}}AFX_DATA_INIT
  178. }
  179. CRepNodePropPush::~CRepNodePropPush()
  180. {
  181. }
  182. void CRepNodePropPush::DoDataExchange(CDataExchange* pDX)
  183. {
  184. CPropertyPageBase::DoDataExchange(pDX);
  185. //{{AFX_DATA_MAP(CRepNodePropPush)
  186. DDX_Control(pDX, IDC_CHECK_PUSH_PERSIST, m_checkPushPersistence);
  187. DDX_Control(pDX, IDC_SPIN_UPDATE_COUNT, m_spinUpdateCount);
  188. DDX_Control(pDX, IDC_EDIT_UPDATE_COUNT, m_editUpdateCount);
  189. DDX_Control(pDX, IDC_CHECK_PUSH_ON_STARTUP, m_checkPushStartup);
  190. DDX_Control(pDX, IDC_CHECK_PUSH_ON_ADDRESS_CHANGE, m_checkRepOnAddrChange);
  191. DDX_Check(pDX, IDC_CHECK_PUSH_ON_ADDRESS_CHANGE, m_fRepOnAddrChange);
  192. DDX_Check(pDX, IDC_CHECK_PUSH_ON_STARTUP, m_fPushStartup);
  193. DDX_Text(pDX, IDC_EDIT_UPDATE_COUNT, m_dwPushUpdateCount);
  194. //}}AFX_DATA_MAP
  195. }
  196. BEGIN_MESSAGE_MAP(CRepNodePropPush, CPropertyPageBase)
  197. //{{AFX_MSG_MAP(CRepNodePropPush)
  198. ON_BN_CLICKED(IDC_CHECK_PUSH_ON_ADDRESS_CHANGE, OnCheckPushOnAddressChange)
  199. ON_BN_CLICKED(IDC_CHECK_PUSH_ON_STARTUP, OnCheckPushOnStartup)
  200. ON_BN_CLICKED(IDC_CHECK_PUSH_PERSIST, OnCheckPushPersist)
  201. ON_EN_CHANGE(IDC_EDIT_UPDATE_COUNT, OnChangeEditUpdateCount)
  202. //}}AFX_MSG_MAP
  203. END_MESSAGE_MAP()
  204. /////////////////////////////////////////////////////////////////////////////
  205. // CRepNodePropPush message handlers
  206. BOOL
  207. CRepNodePropPush::OnApply()
  208. {
  209. if (!IsDirty())
  210. return TRUE;
  211. HRESULT hr = UpdateServerConfiguration();
  212. if (FAILED(hr))
  213. {
  214. return FALSE;
  215. }
  216. else
  217. {
  218. return CPropertyPageBase::OnApply();
  219. }
  220. }
  221. void
  222. CRepNodePropPush::OnOK()
  223. {
  224. CPropertyPageBase::OnOK();
  225. }
  226. BOOL
  227. CRepNodePropPush::OnInitDialog()
  228. {
  229. CPropertyPageBase::OnInitDialog();
  230. SPITFSNode spNode;
  231. CWinsServerHandler *pServer;
  232. SPITFSNode spParentNode;
  233. GetConfig();
  234. m_checkPushStartup.SetCheck(m_pConfig->m_fPushInitialReplication);
  235. m_checkRepOnAddrChange.SetCheck(m_pConfig->m_fPushReplOnAddrChange);
  236. m_spinUpdateCount.SetRange(0, UD_MAXVAL);
  237. m_editUpdateCount.SetWindowText(ToString(m_pConfig->m_dwPushUpdateCount));
  238. // now for the persistence info
  239. if (m_pConfig->m_dwMajorVersion < 5)
  240. {
  241. // not supported, disable controls
  242. m_checkPushPersistence.SetCheck(FALSE);
  243. m_checkPushPersistence.EnableWindow(FALSE);
  244. }
  245. else
  246. {
  247. if (m_pConfig->m_dwPushPersistence)
  248. m_checkPushPersistence.SetCheck(TRUE);
  249. else
  250. m_checkPushPersistence.SetCheck(FALSE);
  251. }
  252. return TRUE;
  253. }
  254. void CRepNodePropPush::OnCheckPushOnAddressChange()
  255. {
  256. SetDirty(TRUE);
  257. }
  258. void CRepNodePropPush::OnCheckPushOnStartup()
  259. {
  260. SetDirty(TRUE);
  261. }
  262. void CRepNodePropPush::OnCheckPushPersist()
  263. {
  264. SetDirty(TRUE);
  265. }
  266. void CRepNodePropPush::OnChangeEditUpdateCount()
  267. {
  268. SetDirty(TRUE);
  269. }
  270. /*---------------------------------------------------------------------------
  271. CRepNodePropPush::GetConfig()
  272. Gets the CConfiguration object from the server node
  273. ---------------------------------------------------------------------------*/
  274. HRESULT
  275. CRepNodePropPush::GetConfig()
  276. {
  277. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  278. HRESULT hr = hrOK;
  279. m_pConfig = ((CRepNodeProperties *) GetHolder())->GetConfig();
  280. return hr;
  281. }
  282. /*---------------------------------------------------------------------------
  283. CRepNodePropPush::UpdateServerConfiguration()
  284. Updates the values for the CConfiguration object in the Server Node
  285. ---------------------------------------------------------------------------*/
  286. HRESULT
  287. CRepNodePropPush::UpdateServerConfiguration()
  288. {
  289. // Reflect the changes in the server's CConfiguration object
  290. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  291. HRESULT hr = hrOK;
  292. SPITFSNode spNode;
  293. CWinsServerHandler *pServer;
  294. SPITFSNode spParentNode;
  295. UpdateData();
  296. if ( ( (m_dwPushUpdateCount > 0) &
  297. (m_dwPushUpdateCount < WINSCNF_MIN_VALID_UPDATE_CNT) ) &
  298. (!m_pConfig->m_dwPushPersistence) )
  299. {
  300. CString strMessage, strValue;
  301. strValue.Format(_T("%d"), WINSCNF_MIN_VALID_UPDATE_CNT);
  302. AfxFormatString1(strMessage, IDS_ERR_UPDATE_COUNT, strValue);
  303. AfxMessageBox(strMessage);
  304. m_editUpdateCount.SetFocus();
  305. return E_FAIL;
  306. }
  307. // get the server
  308. spNode = GetHolder()->GetNode();
  309. // get it's parent
  310. spNode->GetParent(&spParentNode);
  311. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  312. UpdateConfig();
  313. // now write to server
  314. DWORD err = m_pConfig->Store();
  315. if (err != ERROR_SUCCESS)
  316. {
  317. // something bad happened
  318. WinsMessageBox(err);
  319. }
  320. else
  321. {
  322. // success update our local copy
  323. pServer->SetConfig(*m_pConfig);
  324. }
  325. return HRESULT_FROM_WIN32(err);
  326. }
  327. /*---------------------------------------------------------------------------
  328. CRepNodePropPush::UpdateConfig()
  329. Updates the values for the CConfiguration object in the Server Node
  330. ---------------------------------------------------------------------------*/
  331. void
  332. CRepNodePropPush::UpdateConfig()
  333. {
  334. m_pConfig->m_fPushInitialReplication = m_fPushStartup;
  335. m_pConfig->m_fPushReplOnAddrChange = m_fRepOnAddrChange;
  336. m_pConfig->m_dwPushUpdateCount = m_dwPushUpdateCount;
  337. // persistence stuff
  338. BOOL bPushPersist = m_checkPushPersistence.GetCheck() ? TRUE: FALSE;
  339. m_pConfig->m_dwPushPersistence = bPushPersist ? 1:0;
  340. }
  341. /*---------------------------------------------------------------------------
  342. CRepNodePropPush::ToString(int nNumber)
  343. converts integet to string
  344. ---------------------------------------------------------------------------*/
  345. CString
  346. CRepNodePropPush::ToString(int nNumber)
  347. {
  348. TCHAR szStr[20];
  349. _itot(nNumber, szStr, 10);
  350. CString str(szStr);
  351. return str;
  352. }
  353. /////////////////////////////////////////////////////////////////////////////
  354. // CRepNodePropPull property page
  355. IMPLEMENT_DYNCREATE(CRepNodePropPull, CPropertyPageBase)
  356. CRepNodePropPull::CRepNodePropPull() : CPropertyPageBase(CRepNodePropPull::IDD)
  357. {
  358. //{{AFX_DATA_INIT(CRepNodePropPull)
  359. m_fpullTrigOnStartup = FALSE;
  360. m_dwRetryCount = 0;
  361. m_nPullStartHour = 0;
  362. m_nPullStartMinute = 0;
  363. m_nPullStartSecond = 0;
  364. m_nRepliDay = 0;
  365. m_nRepliHour = 0;
  366. m_nRepliMinute= 0;
  367. //}}AFX_DATA_INIT
  368. }
  369. CRepNodePropPull::~CRepNodePropPull()
  370. {
  371. }
  372. void CRepNodePropPull::DoDataExchange(CDataExchange* pDX)
  373. {
  374. CPropertyPageBase::DoDataExchange(pDX);
  375. //{{AFX_DATA_MAP(CRepNodePropPull)
  376. DDX_Control(pDX, IDC_CHECK_PULL_PERSIST, m_checkPullPersistence);
  377. DDX_Control(pDX, IDC_SPIN_START_SECOND, m_spinStartSecond);
  378. DDX_Control(pDX, IDC_SPIN_START_MINUTE, m_spinStartMinute);
  379. DDX_Control(pDX, IDC_SPIN_START_HOUR, m_spinStartHour);
  380. DDX_Control(pDX, IDC_SPIN_RETRY_COUNT, m_spinRetryCount);
  381. DDX_Control(pDX, IDC_SPIN_REP_INT_MINUTE, m_spinRepIntMinute);
  382. DDX_Control(pDX, IDC_SPIN_REP_INT_HOUR, m_spinRepIntHour);
  383. DDX_Control(pDX, IDC_SPIN_REP_INT_DAY, m_spinRepIntDay);
  384. DDX_Control(pDX, IDC_EDIT_START_SECOND, m_editStartSecond);
  385. DDX_Control(pDX, IDC_EDIT_START_MINUTE, m_editStartMinute);
  386. DDX_Control(pDX, IDC_EDIT_START_HOUR, m_editStartHour);
  387. DDX_Control(pDX, IDC_EDIT_RETRY_COUNT, m_editRetryCount);
  388. DDX_Control(pDX, IDC_EDIT_REP_INT_MINUTE, m_editRepIntMinute);
  389. DDX_Control(pDX, IDC_EDIT_REP_INT_HOUR, m_editRepIntHour);
  390. DDX_Control(pDX, IDC_EDIT_REP_INT_DAY, m_editRepIntDay);
  391. DDX_Control(pDX, IDC_CHECK_TRIGGER_PULL_STARTUP, m_checkpullTrigOnStartup);
  392. DDX_Check(pDX, IDC_CHECK_TRIGGER_PULL_STARTUP, m_fpullTrigOnStartup);
  393. DDX_Text(pDX, IDC_EDIT_RETRY_COUNT, m_dwRetryCount);
  394. DDX_Text(pDX, IDC_EDIT_START_HOUR, m_nPullStartHour);
  395. DDV_MinMaxInt(pDX, m_nPullStartHour, 0, 23);
  396. DDX_Text(pDX, IDC_EDIT_START_MINUTE, m_nPullStartMinute);
  397. DDV_MinMaxInt(pDX, m_nPullStartMinute, 0, 59);
  398. DDX_Text(pDX, IDC_EDIT_START_SECOND, m_nPullStartSecond);
  399. DDV_MinMaxInt(pDX, m_nPullStartSecond, 0, 59);
  400. DDX_Text(pDX, IDC_EDIT_REP_INT_DAY, m_nRepliDay);
  401. DDV_MinMaxInt(pDX, m_nRepliDay, 0, 365);
  402. DDX_Text(pDX, IDC_EDIT_REP_INT_HOUR, m_nRepliHour);
  403. DDV_MinMaxInt(pDX, m_nRepliHour, 0, 23);
  404. DDX_Text(pDX, IDC_EDIT_REP_INT_MINUTE, m_nRepliMinute);
  405. DDV_MinMaxInt(pDX, m_nRepliMinute, 0, 59);
  406. //}}AFX_DATA_MAP
  407. }
  408. BEGIN_MESSAGE_MAP(CRepNodePropPull, CPropertyPageBase)
  409. //{{AFX_MSG_MAP(CRepNodePropPull)
  410. ON_EN_CHANGE(IDC_EDIT_REP_INT_DAY, OnChangeEditRepIntHour)
  411. ON_EN_CHANGE(IDC_EDIT_REP_INT_HOUR, OnChangeEditRepIntHour)
  412. ON_EN_CHANGE(IDC_EDIT_REP_INT_MINUTE, OnChangeEditRepIntHour)
  413. ON_EN_CHANGE(IDC_EDIT_RETRY_COUNT, OnChangeEditRepIntHour)
  414. ON_EN_CHANGE(IDC_EDIT_START_HOUR, OnChangeEditRepIntHour)
  415. ON_EN_CHANGE(IDC_EDIT_START_MINUTE, OnChangeEditRepIntHour)
  416. ON_EN_CHANGE(IDC_EDIT_START_SECOND, OnChangeEditRepIntHour)
  417. ON_EN_CHANGE(IDC_EDIT_UPDATE_COUNT, OnChangeEditRepIntHour)
  418. ON_BN_CLICKED(IDC_CHECK_MIGRATE, OnChangeEditRepIntHour)
  419. ON_BN_CLICKED(IDC_CHECK_PUSH_ON_ADDRESS_CHANGE, OnChangeEditRepIntHour)
  420. ON_BN_CLICKED(IDC_CHECK_REP_WITH_PARTNERS, OnChangeEditRepIntHour)
  421. ON_BN_CLICKED(IDC_CHECK_TRIGGER_PULL_STARTUP, OnChangeEditRepIntHour)
  422. ON_BN_CLICKED(IDC_CHECK_PUSH_PERSIST, OnChangeEditRepIntHour)
  423. ON_BN_CLICKED(IDC_CHECK_PUSH_ON_STARTUP, OnChangeEditRepIntHour)
  424. ON_BN_CLICKED(IDC_CHECK_PULL_PERSIST, OnCheckPullPersist)
  425. //}}AFX_MSG_MAP
  426. END_MESSAGE_MAP()
  427. /////////////////////////////////////////////////////////////////////////////
  428. // CRepNodePropPull message handlers
  429. BOOL
  430. CRepNodePropPull::OnApply()
  431. {
  432. if (!IsDirty())
  433. return TRUE;
  434. HRESULT hr = UpdateServerConfiguration();
  435. if (FAILED(hr))
  436. {
  437. return FALSE;
  438. }
  439. else
  440. {
  441. return CPropertyPageBase::OnApply();
  442. }
  443. }
  444. void
  445. CRepNodePropPull::OnOK()
  446. {
  447. CPropertyPageBase::OnOK();
  448. }
  449. BOOL
  450. CRepNodePropPull::OnInitDialog()
  451. {
  452. CPropertyPageBase::OnInitDialog();
  453. SPITFSNode spNode;
  454. CWinsServerHandler *pServer;
  455. SPITFSNode spParentNode;
  456. GetConfig();
  457. m_checkpullTrigOnStartup.SetCheck(m_pConfig->m_fPullInitialReplication);
  458. m_spinRetryCount.SetRange(0, UD_MAXVAL);
  459. m_editRetryCount.SetWindowText(ToString(m_pConfig->m_dwPullRetryCount));
  460. SetPullStartTimeData(m_pConfig->m_dwPullSpTime);
  461. SetPullTimeIntData(m_pConfig->m_dwPullTimeInterval);
  462. // now for the persistence info
  463. if (m_pConfig->m_dwMajorVersion < 5)
  464. {
  465. // not supported, disable controls
  466. m_checkPullPersistence.SetCheck(FALSE);
  467. m_checkPullPersistence.EnableWindow(FALSE);
  468. }
  469. else
  470. {
  471. if (m_pConfig->m_dwPullPersistence)
  472. m_checkPullPersistence.SetCheck(TRUE);
  473. else
  474. m_checkPullPersistence.SetCheck(FALSE);
  475. }
  476. return TRUE;
  477. }
  478. void CRepNodePropPull::OnCheckPullPersist()
  479. {
  480. SetDirty(TRUE);
  481. }
  482. /*---------------------------------------------------------------------------
  483. CRepNodePropPull::SetPullStartTimeData(DWORD dwPullStartTime)
  484. Sets the PullSpTime in the controls
  485. ---------------------------------------------------------------------------*/
  486. void
  487. CRepNodePropPull::SetPullStartTimeData(DWORD dwPullStartTime)
  488. {
  489. int nHours = 0, nMinutes = 0, nSeconds = 0;
  490. CTime time(dwPullStartTime);
  491. m_spinStartSecond.SetRange(0, 59);
  492. m_spinStartMinute.SetRange(0, 59);
  493. m_spinStartHour.SetRange(0, 23);
  494. if (dwPullStartTime)
  495. {
  496. nHours = time.GetHour();
  497. nMinutes = time.GetMinute();
  498. nSeconds = time.GetSecond();
  499. }
  500. m_spinStartHour.SetPos(nHours);
  501. m_spinStartMinute.SetPos(nMinutes);
  502. m_spinStartSecond.SetPos(nSeconds);
  503. }
  504. /*---------------------------------------------------------------------------
  505. CRepNodePropPull::SetPullTimeIntData(DWORD dwPullInternal)
  506. Sets the Pull Replication Interval in the controls
  507. ---------------------------------------------------------------------------*/
  508. void
  509. CRepNodePropPull::SetPullTimeIntData(DWORD dwPullInternal)
  510. {
  511. m_spinRepIntMinute.SetRange(0, 59);
  512. m_spinRepIntHour.SetRange(0, 23);
  513. m_spinRepIntDay.SetRange(0, UD_MAXVAL);
  514. int nDays = 0, nHours = 0, nMinutes = 0;
  515. if (dwPullInternal)
  516. {
  517. nDays = dwPullInternal / SEC_PER_DAY;
  518. dwPullInternal -= nDays * SEC_PER_DAY;
  519. if (dwPullInternal)
  520. {
  521. nHours = dwPullInternal / SEC_PER_HOUR;
  522. dwPullInternal -= nHours * SEC_PER_HOUR;
  523. if (dwPullInternal)
  524. {
  525. nMinutes = dwPullInternal / SEC_PER_MINUTE;
  526. dwPullInternal -= nMinutes * SEC_PER_MINUTE;
  527. }
  528. }
  529. }
  530. m_spinRepIntDay.SetPos(nDays);
  531. m_spinRepIntHour.SetPos(nHours);
  532. m_spinRepIntMinute.SetPos(nMinutes);
  533. }
  534. /*---------------------------------------------------------------------------
  535. CRepNodePropPull::GetConfig()
  536. Gets the CConfiguration object from the server node
  537. ---------------------------------------------------------------------------*/
  538. HRESULT
  539. CRepNodePropPull::GetConfig()
  540. {
  541. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  542. HRESULT hr = hrOK;
  543. m_pConfig = ((CRepNodeProperties *) GetHolder())->GetConfig();
  544. return hr;
  545. }
  546. /*---------------------------------------------------------------------------
  547. CRepNodePropGen::UpdateServerConfiguration()
  548. Updates the values for the CConfiguration object in the Server Node
  549. ---------------------------------------------------------------------------*/
  550. HRESULT
  551. CRepNodePropPull::UpdateServerConfiguration()
  552. {
  553. // Reflect the changes in the server's CConfiguration object
  554. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  555. HRESULT hr = hrOK;
  556. SPITFSNode spNode;
  557. CWinsServerHandler *pServer;
  558. SPITFSNode spParentNode;
  559. UpdateData();
  560. // get the server
  561. spNode = GetHolder()->GetNode();
  562. // get it's parent
  563. spNode->GetParent(&spParentNode);
  564. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  565. UpdateConfig();
  566. // now write to server
  567. DWORD err = m_pConfig->Store();
  568. if (err != ERROR_SUCCESS)
  569. {
  570. // something bad happened
  571. WinsMessageBox(err);
  572. }
  573. else
  574. {
  575. // success update our local copy
  576. pServer->SetConfig(*m_pConfig);
  577. }
  578. return HRESULT_FROM_WIN32(err);
  579. }
  580. /*---------------------------------------------------------------------------
  581. CRepNodePropPull::UpdateConfig()
  582. Updates the values for the CConfiguration object in the Server Node
  583. ---------------------------------------------------------------------------*/
  584. void
  585. CRepNodePropPull::UpdateConfig()
  586. {
  587. m_pConfig->m_fPullInitialReplication = m_fpullTrigOnStartup;
  588. m_pConfig->m_dwPullRetryCount = m_dwRetryCount;
  589. m_pConfig->m_dwPullTimeInterval = CalculateReplInt();
  590. m_pConfig->m_dwPullSpTime = CalculatePullStartInt();
  591. // persistence stuff
  592. BOOL bPullPersist = m_checkPullPersistence.GetCheck() ? TRUE: FALSE;
  593. m_pConfig->m_dwPullPersistence = bPullPersist ? 1:0;
  594. }
  595. /*---------------------------------------------------------------------------
  596. CRepNodePropPull ::CalculatePullStartInt()
  597. Calculates the pullSPTime from the values in the controls
  598. ---------------------------------------------------------------------------*/
  599. DWORD
  600. CRepNodePropPull ::CalculatePullStartInt()
  601. {
  602. CTime timePull;
  603. DWORD dwPullStartTime;
  604. if (m_nPullStartHour || m_nPullStartMinute || m_nPullStartSecond)
  605. {
  606. CTime time = CTime::GetCurrentTime();
  607. CTime timeStart(time.GetYear(),
  608. time.GetMonth(),
  609. time.GetDay(),
  610. m_nPullStartHour,
  611. m_nPullStartMinute,
  612. m_nPullStartSecond);
  613. timePull = timeStart;
  614. }
  615. else
  616. {
  617. CTime time(0);
  618. timePull = time;
  619. }
  620. m_spinStartHour.SetPos(m_nPullStartHour);
  621. m_spinStartMinute.SetPos(m_nPullStartMinute);
  622. m_spinStartMinute.SetPos(m_nPullStartSecond);
  623. dwPullStartTime = (DWORD) timePull.GetTime();
  624. return dwPullStartTime;
  625. }
  626. /*---------------------------------------------------------------------------
  627. CRepNodePropPull ::CalculateReplInt()
  628. Calculates the pullReplInt from the values in the controls
  629. ---------------------------------------------------------------------------*/
  630. DWORD
  631. CRepNodePropPull::CalculateReplInt()
  632. {
  633. DWORD dwReplInt = m_nRepliDay *SEC_PER_DAY +
  634. m_nRepliHour *SEC_PER_HOUR +
  635. m_nRepliMinute * SEC_PER_MINUTE;
  636. m_spinRepIntDay.SetPos(m_nRepliDay);
  637. m_spinRepIntHour.SetPos(m_nRepliHour);
  638. m_spinRepIntMinute.SetPos(m_nRepliMinute);
  639. return dwReplInt;
  640. }
  641. /*---------------------------------------------------------------------------
  642. CRepNodePropPull::ToString(int nNumber)
  643. converts integet to string
  644. ---------------------------------------------------------------------------*/
  645. CString
  646. CRepNodePropPull::ToString(int nNumber)
  647. {
  648. TCHAR szStr[20];
  649. _itot(nNumber, szStr, 10);
  650. CString str(szStr);
  651. return str;
  652. }
  653. void CRepNodePropPull::OnChangeEditRepIntHour()
  654. {
  655. SetDirty(TRUE);
  656. }
  657. int CALLBACK RepNodeAdvancedPageCompareFunc
  658. (
  659. LPARAM lParam1,
  660. LPARAM lParam2,
  661. LPARAM lParamSort
  662. )
  663. {
  664. return ((CRepNodePropAdvanced *) lParamSort)->HandleSort(lParam1, lParam2);
  665. }
  666. /////////////////////////////////////////////////////////////////////////////
  667. // CRepNodePropAdvanced property page
  668. IMPLEMENT_DYNCREATE(CRepNodePropAdvanced, CPropertyPage)
  669. CRepNodePropAdvanced::CRepNodePropAdvanced() : CPropertyPageBase(CRepNodePropAdvanced::IDD)
  670. {
  671. //{{AFX_DATA_INIT(cRepNodePropAdvanced)
  672. m_fEnableAuto = FALSE;
  673. m_dwHours = 0;
  674. m_dwMinutes = 0;
  675. m_dwSeconds = 0;
  676. m_dwMulticastTTL = 0;
  677. m_dwPersonaMode = PERSMODE_NON_GRATA;
  678. //}}AFX_DATA_INIT
  679. m_nSortColumn = -1;
  680. for (int i = 0; i < COLUMN_MAX; i++)
  681. {
  682. m_aSortOrder[i] = TRUE; // ascending
  683. }
  684. }
  685. CRepNodePropAdvanced::~CRepNodePropAdvanced()
  686. {
  687. }
  688. void
  689. CRepNodePropAdvanced::DoDataExchange(CDataExchange* pDX)
  690. {
  691. CPropertyPageBase::DoDataExchange(pDX);
  692. //{{AFX_DATA_MAP(cRepNodePropAdvanced)
  693. DDX_Control(pDX, IDC_BUTTON_ADD, m_buttonAdd);
  694. DDX_Control(pDX, IDC_BUTTON_REMOVE, m_buttonRemove);
  695. DDX_Control(pDX, IDC_LIST_OWNERS, m_listOwners);
  696. DDX_Control(pDX, IDC_STATIC_DESP, m_staticDesp);
  697. DDX_Control(pDX, IDC_STATIC_MUTICASTINT, m_staticMulticastTTL);
  698. DDX_Control(pDX, IDC_STATIC_MULTICAST_TTL, m_staticMulticastInt);
  699. DDX_Control(pDX, IDC_SPIN_MULTICAST_TTL, m_spinMulticastTTL);
  700. DDX_Control(pDX, IDC_SPIN_MULTICAST_SECOND, m_spinMulticastSecond);
  701. DDX_Control(pDX, IDC_SPIN_MULTICAST_MINUTE, m_spinMulticastMinute);
  702. DDX_Control(pDX, IDC_SPIN_MULTICAST_HOUR, m_spinMulticastHour);
  703. DDX_Control(pDX, IDC_EDIT_MULTICAST_SECOND, m_editMulticastSecond);
  704. DDX_Control(pDX, IDC_EDIT_MULTICAST_TTL, m_editMulticastTTL);
  705. DDX_Control(pDX, IDC_EDIT_MULTICAST_MINUTE, m_editMulticastMinute);
  706. DDX_Control(pDX, IDC_EDIT_MULTICAST_HOUR, m_editMulticastHour);
  707. DDX_Control(pDX, IDC_CHECK_ENABLE_AUTO_PARTNER_CONFIG, m_checkenableAutoConfig);
  708. DDX_Check(pDX, IDC_CHECK_ENABLE_AUTO_PARTNER_CONFIG, m_fEnableAuto);
  709. DDX_Text(pDX, IDC_EDIT_MULTICAST_HOUR, m_dwHours);
  710. DDV_MinMaxDWord(pDX, m_dwHours, 0, 23);
  711. DDX_Text(pDX, IDC_EDIT_MULTICAST_MINUTE, m_dwMinutes);
  712. DDV_MinMaxDWord(pDX, m_dwMinutes, 0, 59);
  713. DDX_Text(pDX, IDC_EDIT_MULTICAST_SECOND, m_dwSeconds);
  714. DDV_MinMaxDWord(pDX, m_dwSeconds, 0, 59);
  715. DDX_Text(pDX, IDC_EDIT_MULTICAST_TTL, m_dwMulticastTTL);
  716. DDV_MinMaxDWord(pDX, m_dwMulticastTTL, WINSCNF_MIN_MCAST_TTL, WINSCNF_MAX_MCAST_TTL);
  717. //}}AFX_DATA_MAP
  718. }
  719. BEGIN_MESSAGE_MAP(CRepNodePropAdvanced, CPropertyPageBase)
  720. //{{AFX_MSG_MAP(cRepNodePropAdvanced)
  721. ON_BN_CLICKED(IDC_CHECK_ENABLE_AUTO_PARTNER_CONFIG, OnCheckEnableAutoPartnerConfig)
  722. ON_EN_CHANGE(IDC_EDIT_MULTICAST_HOUR, OnChangeEditMulticastHour)
  723. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  724. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  725. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_OWNERS, OnItemchangedListOwners)
  726. ON_EN_CHANGE(IDC_EDIT_MULTICAST_MINUTE, OnChangeEditMulticastHour)
  727. ON_EN_CHANGE(IDC_EDIT_MULTICAST_SECOND, OnChangeEditMulticastHour)
  728. ON_EN_CHANGE(IDC_EDIT_MULTICAST_TTL, OnChangeEditMulticastHour)
  729. ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_OWNERS, OnColumnclickListOwners)
  730. ON_BN_CLICKED(IDC_RADIO_GRATA, OnRadioGrata)
  731. ON_BN_CLICKED(IDC_RADIO_NON_GRATA, OnRadioNonGrata)
  732. //}}AFX_MSG_MAP
  733. END_MESSAGE_MAP()
  734. /////////////////////////////////////////////////////////////////////////////
  735. // cRepNodePropAdvanced message handlers
  736. BOOL
  737. CRepNodePropAdvanced::OnApply()
  738. {
  739. if (!IsDirty())
  740. return TRUE;
  741. HRESULT hr = UpdateServerConfiguration();
  742. if (FAILED(hr))
  743. {
  744. return FALSE;
  745. }
  746. else
  747. {
  748. return CPropertyPageBase::OnApply();
  749. }
  750. }
  751. void
  752. CRepNodePropAdvanced::OnOK()
  753. {
  754. // TODO: Add your specialized code here and/or call the base class
  755. CPropertyPageBase::OnOK();
  756. }
  757. BOOL
  758. CRepNodePropAdvanced::OnInitDialog()
  759. {
  760. CPropertyPageBase::OnInitDialog();
  761. GetConfig();
  762. InitializeControls();
  763. if (m_pConfig->m_fUseSelfFndPnrs)
  764. {
  765. m_checkenableAutoConfig.SetCheck(TRUE);
  766. EnableControls();
  767. FillControls();
  768. }
  769. else
  770. {
  771. m_checkenableAutoConfig.SetCheck(FALSE);
  772. // disable the controls
  773. FillControls();
  774. EnableControls(FALSE);
  775. }
  776. // now for the owner list box
  777. // fill the header informnation for the list control
  778. //CString strOwner;
  779. //strOwner.LoadString(IDS_WINSSERVER);
  780. //m_listOwners.InsertColumn(0,strOwner, LVCFMT_LEFT, 150,1);
  781. CString strID;
  782. strID.LoadString(IDS_IPADDRESS);
  783. m_listOwners.InsertColumn(0, strID, LVCFMT_LEFT, 150, -1);
  784. FillServerInfo();
  785. SetRemoveButtonState();
  786. SetDirty(FALSE);
  787. return TRUE;
  788. }
  789. void
  790. CRepNodePropAdvanced::InitializeControls()
  791. {
  792. m_spinMulticastHour.SetRange(0, UD_MAXVAL);
  793. m_spinMulticastMinute.SetRange(0, 59);
  794. m_spinMulticastSecond.SetRange(0, 59);
  795. m_spinMulticastTTL.SetRange(WINSCNF_MIN_MCAST_TTL, WINSCNF_MAX_MCAST_TTL);
  796. }
  797. void
  798. CRepNodePropAdvanced::EnableControls(BOOL bEnable )
  799. {
  800. m_staticMulticastInt.EnableWindow(bEnable);
  801. m_staticMulticastTTL.EnableWindow(bEnable);
  802. m_staticDesp.EnableWindow(bEnable);
  803. m_editMulticastHour.EnableWindow(bEnable);
  804. m_editMulticastMinute.EnableWindow(bEnable);
  805. m_editMulticastSecond.EnableWindow(bEnable);
  806. m_spinMulticastHour.EnableWindow(bEnable);
  807. m_spinMulticastMinute.EnableWindow(bEnable);
  808. m_spinMulticastSecond.EnableWindow(bEnable);
  809. m_spinMulticastTTL.EnableWindow(bEnable);
  810. m_editMulticastTTL.EnableWindow(bEnable);
  811. }
  812. void
  813. CRepNodePropAdvanced::FillControls()
  814. {
  815. DWORD dwMulticastInt = m_pConfig->m_dwMulticastInt;
  816. int nHours = dwMulticastInt / SEC_PER_HOUR;
  817. dwMulticastInt -= nHours * SEC_PER_HOUR;
  818. int nMinutes = dwMulticastInt / SEC_PER_MINUTE;
  819. dwMulticastInt -= nMinutes * SEC_PER_MINUTE;
  820. int nSeconds = dwMulticastInt;
  821. m_spinMulticastHour.SetPos(nHours);
  822. m_spinMulticastMinute.SetPos(nMinutes);
  823. m_spinMulticastSecond.SetPos(nSeconds);
  824. m_editMulticastTTL.SetWindowText(ToString(m_pConfig->m_dwMcastTtl));
  825. }
  826. CString
  827. CRepNodePropAdvanced::ToString(int nNumber)
  828. {
  829. TCHAR szStr[20];
  830. _itot(nNumber, szStr, 10);
  831. CString str(szStr);
  832. return str;
  833. }
  834. void
  835. CRepNodePropAdvanced::UpdateConfig()
  836. {
  837. if (m_fEnableAuto)
  838. {
  839. DWORD dwInt = m_dwHours*SEC_PER_HOUR +
  840. m_dwMinutes *SEC_PER_MINUTE +
  841. m_dwSeconds;
  842. m_pConfig->m_dwMulticastInt = dwInt;
  843. m_pConfig->m_dwMcastTtl = m_dwMulticastTTL;
  844. m_pConfig->m_fUseSelfFndPnrs = m_fEnableAuto;
  845. }
  846. else
  847. {
  848. m_pConfig->m_fUseSelfFndPnrs = m_fEnableAuto;
  849. }
  850. }
  851. HRESULT
  852. CRepNodePropAdvanced::UpdateServerConfiguration()
  853. {
  854. // Reflect the changes in the server's CConfiguration object
  855. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  856. HRESULT hr = hrOK;
  857. SPITFSNode spNode;
  858. CWinsServerHandler *pServer;
  859. SPITFSNode spParentNode;
  860. DWORD err = ERROR_SUCCESS;
  861. // get the server
  862. spNode = GetHolder()->GetNode();
  863. // get it's parent
  864. spNode->GetParent(&spParentNode);
  865. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  866. UpdateData();
  867. UpdateConfig();
  868. // update persona non grata
  869. err = WriteToRegistry();
  870. if (err != ERROR_SUCCESS)
  871. {
  872. // something bad happened
  873. WinsMessageBox(err);
  874. goto Error;
  875. }
  876. // now write to server
  877. err = m_pConfig->Store();
  878. if (err != ERROR_SUCCESS)
  879. {
  880. // something bad happened
  881. WinsMessageBox(err);
  882. }
  883. else
  884. {
  885. // success update our local copy
  886. pServer->SetConfig(*m_pConfig);
  887. }
  888. Error:
  889. return HRESULT_FROM_WIN32(err);
  890. }
  891. HRESULT
  892. CRepNodePropAdvanced::GetConfig()
  893. {
  894. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  895. HRESULT hr = hrOK;
  896. m_pConfig = ((CRepNodeProperties *) GetHolder())->GetConfig();
  897. return hr;
  898. }
  899. void CRepNodePropAdvanced::OnCheckEnableAutoPartnerConfig()
  900. {
  901. SetDirty(TRUE);
  902. if (m_checkenableAutoConfig.GetCheck())
  903. {
  904. EnableControls();
  905. FillControls();
  906. }
  907. else
  908. {
  909. FillControls();
  910. EnableControls(FALSE);
  911. }
  912. SetRemoveButtonState();
  913. }
  914. void CRepNodePropAdvanced::OnChangeEditMulticastHour()
  915. {
  916. SetDirty(TRUE);
  917. }
  918. void CRepNodePropAdvanced::OnButtonAdd()
  919. {
  920. BOOL fDuplicate = FALSE;
  921. CNewPersonaNonGrata dlg;
  922. CStringArray *pPersonaList;
  923. // empty the strings
  924. m_strServerName.Empty();
  925. m_strIPAddress.Empty();
  926. dlg.m_pRepPropDlg = this;
  927. // show the dialog
  928. if (IDOK != dlg.DoModal())
  929. return;
  930. m_strServerName = dlg.m_strServerName;
  931. m_strIPAddress = dlg.m_strServerIp;
  932. pPersonaList = (m_dwPersonaMode == PERSMODE_NON_GRATA) ?
  933. &m_strPersonaNonGrata :
  934. &m_strPersonaGrata;
  935. // check to make sure it already isn't in the list
  936. for (int i = 0; i < pPersonaList->GetSize(); i++)
  937. {
  938. if ((*pPersonaList)[i] == m_strIPAddress)
  939. {
  940. // oh no, duplicate
  941. AfxMessageBox(IDS_ERR_WINS_EXISTS);
  942. fDuplicate = TRUE;
  943. }
  944. }
  945. if (!fDuplicate)
  946. {
  947. int nCount = m_listOwners.GetItemCount();
  948. // add to the list control
  949. int ntest = m_listOwners.InsertItem(nCount, m_strIPAddress, 0);
  950. CIpAddress ipaddr1(m_strIPAddress);
  951. m_listOwners.SetItemData(ntest, (LONG) ipaddr1);
  952. // add to the list of the IP address array too.
  953. pPersonaList->Add(m_strIPAddress);
  954. // set focus to the Add button
  955. m_buttonAdd.SetFocus();
  956. SetRemoveButtonState();
  957. // mark the page as dirty
  958. SetDirty(TRUE);
  959. }
  960. }
  961. void CRepNodePropAdvanced::OnButtonRemove()
  962. {
  963. int nSel;
  964. CString strSel;
  965. nSel = m_listOwners.GetNextItem(-1, LVNI_SELECTED);
  966. if (nSel == -1)
  967. return;
  968. strSel = m_listOwners.GetItemText(nSel, 0);
  969. // remove from the list of IP addresses
  970. RemoveFromArray(strSel);
  971. m_listOwners.DeleteItem(nSel);
  972. if (m_listOwners.GetItemCount() > 0)
  973. m_listOwners.SetItemState(0,LVIS_SELECTED,LVIS_SELECTED);
  974. // set focus to the owners list box
  975. m_listOwners.SetFocus();
  976. m_buttonAdd.SetFocus();
  977. SetRemoveButtonState();
  978. // mark the page dirty
  979. SetDirty(TRUE);
  980. }
  981. void
  982. CRepNodePropAdvanced::RemoveFromArray(CString &strSel)
  983. {
  984. int nCount;
  985. int i;
  986. CStringArray *pPersonaList;
  987. pPersonaList = (m_dwPersonaMode == PERSMODE_NON_GRATA) ?
  988. &m_strPersonaNonGrata :
  989. &m_strPersonaGrata;
  990. nCount = (int)pPersonaList->GetSize();
  991. for(i = 0 ; i < nCount; i++)
  992. {
  993. // get the string that matches with the one selected
  994. if (pPersonaList->GetAt(i).CompareNoCase(strSel) == 0)
  995. {
  996. pPersonaList->RemoveAt(i);
  997. break;
  998. }
  999. }
  1000. }
  1001. BOOL CRepNodePropAdvanced::IsDuplicate(CString &strServerName)
  1002. {
  1003. BOOL bFound = FALSE;
  1004. LV_FINDINFO lvFindInfo;
  1005. int nFound ;
  1006. lvFindInfo.flags = LVFI_STRING;
  1007. lvFindInfo.psz = strServerName;
  1008. lvFindInfo.lParam = NULL;
  1009. nFound = m_listOwners.FindItem(&lvFindInfo);
  1010. bFound = (nFound != -1) ? TRUE : FALSE;
  1011. return bFound;
  1012. }
  1013. BOOL CRepNodePropAdvanced::IsCurrentServer(CString &strServerName)
  1014. {
  1015. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1016. BOOL bCurrent = FALSE;
  1017. SPITFSNode spNode;
  1018. CWinsServerHandler *pServer;
  1019. SPITFSNode spParentNode;
  1020. // get the server
  1021. spNode = GetHolder()->GetNode();
  1022. // get it's parent
  1023. spNode->GetParent(&spParentNode);
  1024. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  1025. // check if the same server is being added
  1026. if (pServer->m_strServerAddress.CompareNoCase(m_strServerName) == 0)
  1027. {
  1028. return TRUE;
  1029. }
  1030. return FALSE;
  1031. }
  1032. DWORD CRepNodePropAdvanced::ReadFromRegistry()
  1033. {
  1034. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1035. DWORD err = ERROR_SUCCESS;
  1036. CString strServerName;
  1037. CString strTemp =_T("\\\\");
  1038. CString strName;
  1039. CStringList strList;
  1040. RegKey rk;
  1041. GetServerName(strServerName);
  1042. strServerName = strTemp + strServerName;
  1043. // clear the IP array first
  1044. m_strPersonaNonGrata.RemoveAll();
  1045. m_strPersonaGrata.RemoveAll();
  1046. err = rk.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPartnersRoot, KEY_READ, strServerName);
  1047. if (err)
  1048. {
  1049. err = rk.Create(HKEY_LOCAL_MACHINE,
  1050. (LPCTSTR) lpstrPartnersRoot,
  1051. REG_OPTION_NON_VOLATILE,
  1052. KEY_ALL_ACCESS,
  1053. NULL,
  1054. strServerName);
  1055. }
  1056. if (err == ERROR_SUCCESS)
  1057. {
  1058. err = rk.QueryValue(lpstrPersonaNonGrata, strList);
  1059. if (err == ERROR_SUCCESS)
  1060. {
  1061. POSITION pos = strList.GetHeadPosition();
  1062. while (pos)
  1063. {
  1064. strName = strList.GetNext(pos);
  1065. if (!strName.IsEmpty())
  1066. m_strPersonaNonGrata.Add(strName);
  1067. }
  1068. }
  1069. err = rk.QueryValue(lpstrPersonaGrata, strList);
  1070. if (err == ERROR_SUCCESS)
  1071. {
  1072. POSITION pos = strList.GetHeadPosition();
  1073. while (pos)
  1074. {
  1075. strName = strList.GetNext(pos);
  1076. if (!strName.IsEmpty())
  1077. m_strPersonaGrata.Add(strName);
  1078. }
  1079. }
  1080. // don't worry here about the return code. In case of failure (entry doesn't exist)
  1081. // rely on default which is 'NON_GRATA'
  1082. rk.QueryValue(lpstrPersonaMode, m_dwPersonaMode);
  1083. // normalize the value - if > 0 it is set to 1
  1084. if (m_dwPersonaMode > 0)
  1085. m_dwPersonaMode = PERSMODE_GRATA;
  1086. }
  1087. return ERROR_SUCCESS;
  1088. }
  1089. DWORD
  1090. CRepNodePropAdvanced::WriteToRegistry()
  1091. {
  1092. DWORD err = ERROR_SUCCESS;
  1093. RegKey rk;
  1094. CString strServerName;
  1095. CString strTemp =_T("\\\\");
  1096. int i = 0;
  1097. CStringList strList;
  1098. // get the servername
  1099. GetServerName(strServerName);
  1100. strServerName = strTemp + strServerName;
  1101. err = rk.Create(HKEY_LOCAL_MACHINE,
  1102. (LPCTSTR) lpstrPartnersRoot,
  1103. REG_OPTION_NON_VOLATILE,
  1104. KEY_ALL_ACCESS,
  1105. NULL,
  1106. strServerName);
  1107. if (err == ERROR_SUCCESS)
  1108. {
  1109. for (i = 0; i < m_strPersonaNonGrata.GetSize(); i++)
  1110. {
  1111. if (!m_strPersonaNonGrata[i].IsEmpty())
  1112. strList.AddTail(m_strPersonaNonGrata.GetAt(i));
  1113. }
  1114. err = rk.SetValue(lpstrPersonaNonGrata, strList);
  1115. strList.RemoveAll();
  1116. }
  1117. if (err == ERROR_SUCCESS)
  1118. {
  1119. for (i = 0; i < m_strPersonaGrata.GetSize(); i++)
  1120. {
  1121. if (!m_strPersonaGrata[i].IsEmpty())
  1122. strList.AddTail(m_strPersonaGrata.GetAt(i));
  1123. }
  1124. err = rk.SetValue(lpstrPersonaGrata, strList);
  1125. }
  1126. if (err == ERROR_SUCCESS)
  1127. {
  1128. err = rk.SetValue(lpstrPersonaMode, m_dwPersonaMode);
  1129. }
  1130. return err;
  1131. }
  1132. DWORD
  1133. CRepNodePropAdvanced::ResolveIPAddress(CString &strIP, CString &strServerName)
  1134. {
  1135. DWORD err = ERROR_SUCCESS;
  1136. DWORD dwIPDummy;
  1137. // check by resolving the name thro' WINS api
  1138. BEGIN_WAIT_CURSOR
  1139. err = ::VerifyWinsServer(strIP, strServerName, dwIPDummy);
  1140. END_WAIT_CURSOR
  1141. return err;
  1142. }
  1143. void
  1144. CRepNodePropAdvanced::FillServerInfo()
  1145. {
  1146. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1147. int nSize;
  1148. int i;
  1149. DWORD err;
  1150. CStringArray *pPersonaList;
  1151. // read from the registry
  1152. ReadFromRegistry();
  1153. if (m_dwPersonaMode == PERSMODE_NON_GRATA)
  1154. {
  1155. pPersonaList = &m_strPersonaNonGrata;
  1156. CheckRadioButton(IDC_RADIO_NON_GRATA,IDC_RADIO_GRATA, IDC_RADIO_NON_GRATA);
  1157. }
  1158. else
  1159. {
  1160. pPersonaList = &m_strPersonaGrata;
  1161. CheckRadioButton(IDC_RADIO_NON_GRATA,IDC_RADIO_GRATA, IDC_RADIO_GRATA);
  1162. }
  1163. // now for each of the IP addresses, get the server name
  1164. nSize = (int)pPersonaList->GetSize();
  1165. for (i = 0; i < nSize; i++)
  1166. {
  1167. int nPos = m_listOwners.InsertItem(i, pPersonaList->GetAt(i));
  1168. CIpAddress ipaddr1(pPersonaList->GetAt(i));
  1169. m_listOwners.SetItemData(nPos, (LONG) ipaddr1);
  1170. }
  1171. Sort(COLUMN_IP);
  1172. }
  1173. void
  1174. CRepNodePropAdvanced::GetServerName(CString &ServerName)
  1175. {
  1176. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1177. DWORD err = ERROR_SUCCESS;
  1178. HKEY hkeyMachine = HKEY_LOCAL_MACHINE;
  1179. SPITFSNode spNode;
  1180. CWinsServerHandler *pServer;
  1181. HRESULT hr = hrOK;
  1182. SPITFSNode spParentNode;
  1183. // get the server
  1184. spNode = GetHolder()->GetNode();
  1185. // get it's parent
  1186. spNode->GetParent(&spParentNode);
  1187. pServer = GETHANDLER(CWinsServerHandler, spParentNode);
  1188. ServerName = pServer->GetServerAddress();
  1189. }
  1190. void CRepNodePropAdvanced::SetRemoveButtonState()
  1191. {
  1192. int nSel;
  1193. // check if any item is seleted in the list ctrl.
  1194. nSel = m_listOwners.GetNextItem(-1, LVNI_SELECTED);
  1195. if (nSel == -1)
  1196. m_buttonRemove.EnableWindow(FALSE);
  1197. else
  1198. m_buttonRemove.EnableWindow(TRUE);
  1199. }
  1200. void CRepNodePropAdvanced::OnItemchangedListOwners(NMHDR* pNMHDR, LRESULT* pResult)
  1201. {
  1202. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1203. SetRemoveButtonState();
  1204. *pResult = 0;
  1205. }
  1206. void CRepNodePropAdvanced::OnColumnclickListOwners(NMHDR* pNMHDR, LRESULT* pResult)
  1207. {
  1208. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1209. // sort depending on what column was clicked;
  1210. Sort(pNMListView->iSubItem);
  1211. *pResult = 0;
  1212. }
  1213. void CRepNodePropAdvanced::Sort(int nCol)
  1214. {
  1215. if (m_nSortColumn == nCol)
  1216. {
  1217. // if the user is clicking the same column again, reverse the sort order
  1218. m_aSortOrder[nCol] = m_aSortOrder[nCol] ? FALSE : TRUE;
  1219. }
  1220. else
  1221. {
  1222. m_nSortColumn = nCol;
  1223. }
  1224. m_listOwners.SortItems(RepNodeAdvancedPageCompareFunc, (LPARAM) this);
  1225. }
  1226. int CRepNodePropAdvanced::HandleSort(LPARAM lParam1, LPARAM lParam2)
  1227. {
  1228. int nCompare = 0;
  1229. switch (m_nSortColumn)
  1230. {
  1231. case COLUMN_IP:
  1232. {
  1233. CIpAddress ipaddr1((LONG) lParam1);
  1234. CIpAddress ipaddr2((LONG) lParam2);
  1235. UINT uIpAddr1 = (UINT) ((LONG) ipaddr1);
  1236. UINT uIpAddr2 = (UINT) ((LONG) ipaddr2);
  1237. if (uIpAddr1 > uIpAddr2)
  1238. nCompare = 1;
  1239. else
  1240. if (uIpAddr1 < uIpAddr2)
  1241. nCompare = -1;
  1242. }
  1243. break;
  1244. }
  1245. if (m_aSortOrder[m_nSortColumn] == FALSE)
  1246. {
  1247. // descending
  1248. return -nCompare;
  1249. }
  1250. else
  1251. {
  1252. // ascending
  1253. return nCompare;
  1254. }
  1255. }
  1256. void CRepNodePropAdvanced::OnRadioGrata()
  1257. {
  1258. if (m_dwPersonaMode != PERSMODE_GRATA)
  1259. {
  1260. INT i, nSize;
  1261. m_listOwners.DeleteAllItems();
  1262. nSize = (int)m_strPersonaGrata.GetSize();
  1263. for (i = 0; i < nSize; i++)
  1264. {
  1265. int nPos = m_listOwners.InsertItem(i, m_strPersonaGrata[i]);
  1266. }
  1267. m_dwPersonaMode = PERSMODE_GRATA;
  1268. SetDirty(TRUE);
  1269. }
  1270. }
  1271. void CRepNodePropAdvanced::OnRadioNonGrata()
  1272. {
  1273. if (m_dwPersonaMode != PERSMODE_NON_GRATA)
  1274. {
  1275. INT i, nSize;
  1276. m_listOwners.DeleteAllItems();
  1277. nSize = (int)m_strPersonaNonGrata.GetSize();
  1278. for (i = 0; i < nSize; i++)
  1279. {
  1280. int nPos = m_listOwners.InsertItem(i, m_strPersonaNonGrata[i]);
  1281. }
  1282. m_dwPersonaMode = PERSMODE_NON_GRATA;
  1283. SetDirty(TRUE);
  1284. }
  1285. }
  1286. /////////////////////////////////////////////////////////////////////////////
  1287. // CRepNodeProperties Handlers
  1288. /////////////////////////////////////////////////////////////////////////////
  1289. CRepNodeProperties::CRepNodeProperties
  1290. (
  1291. ITFSNode * pNode,
  1292. IComponentData * pComponentData,
  1293. ITFSComponentData * pTFSCompData,
  1294. LPCTSTR pszSheetName
  1295. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  1296. {
  1297. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  1298. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  1299. AddPageToList((CPropertyPageBase*) &m_pagePush);
  1300. AddPageToList((CPropertyPageBase*) &m_pagePull);
  1301. AddPageToList((CPropertyPageBase*) &m_pageAdvanced);
  1302. Assert(pTFSCompData != NULL);
  1303. m_spTFSCompData.Set(pTFSCompData);
  1304. }
  1305. CRepNodeProperties::~CRepNodeProperties()
  1306. {
  1307. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  1308. RemovePageFromList((CPropertyPageBase*) &m_pagePush, FALSE);
  1309. RemovePageFromList((CPropertyPageBase*) &m_pagePull, FALSE);
  1310. RemovePageFromList((CPropertyPageBase*) &m_pageAdvanced, FALSE);
  1311. }