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.

299 lines
5.1 KiB

  1. /*++
  2. Module Name:
  3. AddToDfs.cpp
  4. Abstract:
  5. This module contains the Implementation of CAddRep.
  6. This class displays the Add Replica Dialog,which is used to add new Replica.
  7. */
  8. #include "stdafx.h"
  9. #include "AddRep.h"
  10. #include "utils.h"
  11. #include <shlobj.h>
  12. #include <dsclient.h>
  13. #include "dfshelp.h"
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAddRep
  16. CAddRep::CAddRep() : m_RepType(REPLICATION_UNASSIGNED),
  17. m_DfsType(DFS_TYPE_UNASSIGNED)
  18. {
  19. }
  20. CAddRep::~CAddRep()
  21. {
  22. }
  23. HRESULT CAddRep::put_EntryPath
  24. (
  25. BSTR i_bstrEntryPath
  26. )
  27. {
  28. /*++
  29. Routine Description:
  30. Sets the path of the Junction point of this replica
  31. This is used to display in the edit text.
  32. Arguments:
  33. i_bstrEntryPath - The junction point entry path.
  34. */
  35. RETURN_INVALIDARG_IF_NULL(i_bstrEntryPath);
  36. m_bstrEntryPath = i_bstrEntryPath;
  37. RETURN_OUTOFMEMORY_IF_NULL((BSTR)m_bstrEntryPath);
  38. return S_OK;
  39. }
  40. HRESULT CAddRep::get_Server
  41. (
  42. BSTR *o_pbstrServer
  43. )
  44. {
  45. /*++
  46. Routine Description:
  47. Returns the server component of the share path.
  48. Arguments:
  49. o_pbstrServer - The server name is returned here.
  50. */
  51. GET_BSTR(m_bstrServer, o_pbstrServer);
  52. }
  53. HRESULT CAddRep::get_Share
  54. (
  55. BSTR *o_pbstrShare
  56. )
  57. {
  58. /*++
  59. Routine Description:
  60. Returns the share component of the share path.
  61. Arguments:
  62. o_pbstrShare - The share name is returned here.
  63. */
  64. GET_BSTR(m_bstrShare, o_pbstrShare);
  65. }
  66. HRESULT CAddRep::get_NetPath
  67. (
  68. BSTR *o_pbstrNetPath
  69. )
  70. {
  71. /*++
  72. Routine Description:
  73. Returns the complete share path typed in by the user in the edit box.
  74. Arguments:
  75. o_pbstrNetPath - The share path is returned here.
  76. */
  77. GET_BSTR(m_bstrNetPath, o_pbstrNetPath);
  78. }
  79. LRESULT CAddRep::OnInitDialog
  80. (
  81. UINT uMsg,
  82. WPARAM wParam,
  83. LPARAM lParam,
  84. BOOL& bHandled
  85. )
  86. {
  87. SetDlgItemText(IDC_EDIT_ADDREP_DFSLINK_PATH, m_bstrEntryPath);
  88. ::SendMessage(GetDlgItem(IDC_EDITNETPATH), EM_LIMITTEXT, MAX_PATH, 0);
  89. // Disable replication button for Std Dfs.
  90. if (DFS_TYPE_FTDFS != m_DfsType)
  91. {
  92. ::EnableWindow(GetDlgItem(IDC_ADDREP_REPLICATE), FALSE);
  93. } else
  94. {
  95. // Check "replication" as default
  96. CheckDlgButton(IDC_ADDREP_REPLICATE, BST_CHECKED);
  97. }
  98. return TRUE; // Let the system set the focus
  99. }
  100. /*++
  101. This function is called when a user clicks the ? in the top right of a property sheet
  102. and then clciks a control, or when they hit F1 in a control.
  103. --*/
  104. LRESULT CAddRep::OnCtxHelp(
  105. IN UINT i_uMsg,
  106. IN WPARAM i_wParam,
  107. IN LPARAM i_lParam,
  108. IN OUT BOOL& io_bHandled
  109. )
  110. {
  111. LPHELPINFO lphi = (LPHELPINFO) i_lParam;
  112. if (!lphi || lphi->iContextType != HELPINFO_WINDOW || lphi->iCtrlId < 0)
  113. return FALSE;
  114. ::WinHelp((HWND)(lphi->hItemHandle),
  115. DFS_CTX_HELP_FILE,
  116. HELP_WM_HELP,
  117. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_ADDREP);
  118. return TRUE;
  119. }
  120. /*++
  121. This function handles "What's This" help when a user right clicks the control
  122. --*/
  123. LRESULT CAddRep::OnCtxMenuHelp(
  124. IN UINT i_uMsg,
  125. IN WPARAM i_wParam,
  126. IN LPARAM i_lParam,
  127. IN OUT BOOL& io_bHandled
  128. )
  129. {
  130. ::WinHelp((HWND)i_wParam,
  131. DFS_CTX_HELP_FILE,
  132. HELP_CONTEXTMENU,
  133. (DWORD_PTR)(PVOID)g_aHelpIDs_IDD_ADDREP);
  134. return TRUE;
  135. }
  136. LRESULT CAddRep::OnNetBrowse
  137. (
  138. WORD wNotifyCode,
  139. WORD wID,
  140. HWND hWndCtl,
  141. BOOL& bHandled
  142. )
  143. {
  144. CComBSTR bstrPath;
  145. HRESULT hr = BrowseNetworkPath(hWndCtl, &bstrPath);
  146. if (S_OK == hr)
  147. {
  148. SetDlgItemText(IDC_EDITNETPATH, bstrPath);
  149. ::SetFocus(GetDlgItem(IDC_ADDREP_REPLICATE));
  150. }
  151. if (S_FALSE == hr)
  152. ::SetFocus(GetDlgItem(IDC_EDITNETPATH));
  153. return (SUCCEEDED(hr));
  154. }
  155. LRESULT CAddRep::OnOK
  156. (
  157. WORD wNotifyCode,
  158. WORD wID,
  159. HWND hWndCtl,
  160. BOOL& bHandled
  161. )
  162. {
  163. BOOL bValidInput = FALSE;
  164. int idString = 0;
  165. HRESULT hr = S_OK;
  166. do {
  167. CWaitCursor wait;
  168. DWORD dwTextLength = 0;
  169. m_bstrNetPath.Empty();
  170. hr = GetInputText(GetDlgItem(IDC_EDITNETPATH), &m_bstrNetPath, &dwTextLength);
  171. if (FAILED(hr))
  172. break;
  173. if (0 == dwTextLength)
  174. {
  175. idString = IDS_MSG_EMPTY_FIELD;
  176. break;
  177. }
  178. m_bstrServer.Empty();
  179. m_bstrShare.Empty();
  180. if (!ValidateNetPath(m_bstrNetPath, &m_bstrServer, &m_bstrShare))
  181. break;
  182. m_RepType = NO_REPLICATION;
  183. if (IsDlgButtonChecked(IDC_ADDREP_REPLICATE))
  184. m_RepType = NORMAL_REPLICATION;
  185. bValidInput = TRUE;
  186. } while (0);
  187. if (FAILED(hr))
  188. {
  189. DisplayMessageBoxForHR(hr);
  190. ::SetFocus(GetDlgItem(IDC_EDITNETPATH));
  191. return FALSE;
  192. } else if (bValidInput)
  193. {
  194. EndDialog(S_OK);
  195. return TRUE;
  196. }
  197. else
  198. {
  199. if (idString)
  200. DisplayMessageBoxWithOK(idString);
  201. ::SetFocus(GetDlgItem(IDC_EDITNETPATH));
  202. return FALSE;
  203. }
  204. }
  205. LRESULT CAddRep::OnCancel
  206. (
  207. WORD wNotifyCode,
  208. WORD wID,
  209. HWND hWndCtl,
  210. BOOL& bHandled
  211. )
  212. {
  213. /*++
  214. Routine Description:
  215. Called OnCancel. Ends the dialog with S_FALSE;
  216. */
  217. EndDialog(S_FALSE);
  218. return(true);
  219. }
  220. CAddRep::REPLICATION_TYPE CAddRep::get_ReplicationType(
  221. VOID
  222. )
  223. /*++
  224. Routine Description:
  225. This method gets the type of replication requested.
  226. This value is based on the radio button selected when OK is pressed.
  227. */
  228. {
  229. return m_RepType;
  230. }