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.

416 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Dhcp.cpp
  7. //
  8. // Description:
  9. // Implementation of the DHCP Service resource extension property page classes.
  10. //
  11. // Author:
  12. // David Potter (DavidP) March 24, 1999
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ClNetResEx.h"
  21. #include "Dhcp.h"
  22. #include "BasePage.inl"
  23. #include "ExtObj.h"
  24. #include "DDxDDv.h"
  25. #include "HelpData.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CDhcpParamsPage property page
  33. /////////////////////////////////////////////////////////////////////////////
  34. IMPLEMENT_DYNCREATE( CDhcpParamsPage, CBasePropertyPage )
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Message Maps
  37. BEGIN_MESSAGE_MAP( CDhcpParamsPage, CBasePropertyPage )
  38. //{{AFX_MSG_MAP(CDhcpParamsPage)
  39. ON_EN_CHANGE( IDC_PP_DHCP_DATABASEPATH, OnChangeRequiredField )
  40. ON_EN_CHANGE( IDC_PP_DHCP_LOGFILEPATH, OnChangeRequiredField )
  41. ON_EN_CHANGE( IDC_PP_DHCP_BACKUPPATH, OnChangeRequiredField )
  42. //}}AFX_MSG_MAP
  43. // TODO: Modify the following lines to represent the data displayed on this page.
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. //++
  47. //
  48. // CDhcpParamsPage::CDhcpParamsPage
  49. //
  50. // Description:
  51. // Default constructor.
  52. //
  53. // Arguments:
  54. // None.
  55. //
  56. // Return Value:
  57. // None.
  58. //
  59. //--
  60. /////////////////////////////////////////////////////////////////////////////
  61. CDhcpParamsPage::CDhcpParamsPage( void )
  62. : CBasePropertyPage(
  63. CDhcpParamsPage::IDD,
  64. g_aHelpIDs_IDD_PP_DHCP_PARAMETERS,
  65. g_aHelpIDs_IDD_WIZ_DHCP_PARAMETERS
  66. )
  67. {
  68. // TODO: Modify the following lines to represent the data displayed on this page.
  69. //{{AFX_DATA_INIT(CDhcpParamsPage)
  70. m_strDatabasePath = _T("");
  71. m_strLogFilePath = _T("");
  72. m_strBackupPath = _T("");
  73. //}}AFX_DATA_INIT
  74. // Setup the property array.
  75. {
  76. m_rgProps[ epropDatabasePath ].Set( REGPARAM_DHCP_DATABASEPATH, m_strDatabasePath, m_strPrevDatabasePath, m_strDatabaseExpandedPath );
  77. m_rgProps[ epropLogFilePath ].Set( REGPARAM_DHCP_LOGFILEPATH, m_strLogFilePath, m_strPrevLogFilePath, m_strLogFileExpandedPath );
  78. m_rgProps[ epropBackupPath ].Set( REGPARAM_DHCP_BACKUPPATH, m_strBackupPath, m_strPrevBackupPath, m_strBackupExpandedPath );
  79. } // Setup the property array
  80. m_iddPropertyPage = IDD_PP_DHCP_PARAMETERS;
  81. m_iddWizardPage = IDD_WIZ_DHCP_PARAMETERS;
  82. } //*** CDhcpParamsPage::CDhcpParamsPage()
  83. /////////////////////////////////////////////////////////////////////////////
  84. //++
  85. //
  86. // CDhcpParamsPage::DoDataExchange
  87. //
  88. // Description:
  89. // Do data exchange between the dialog and the class.
  90. //
  91. // Arguments:
  92. // pDX [IN OUT] Data exchange object
  93. //
  94. // Return Value:
  95. // None.
  96. //
  97. //--
  98. /////////////////////////////////////////////////////////////////////////////
  99. void CDhcpParamsPage::DoDataExchange( CDataExchange * pDX )
  100. {
  101. if ( ! pDX->m_bSaveAndValidate || ! BSaved() )
  102. {
  103. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  104. // TODO: Modify the following lines to represent the data displayed on this page.
  105. //{{AFX_DATA_MAP(CDhcpParamsPage)
  106. DDX_Control( pDX, IDC_PP_DHCP_DATABASEPATH, m_editDatabasePath );
  107. DDX_Control( pDX, IDC_PP_DHCP_LOGFILEPATH, m_editLogFilePath );
  108. DDX_Control( pDX, IDC_PP_DHCP_BACKUPPATH, m_editBackupPath );
  109. DDX_Text( pDX, IDC_PP_DHCP_DATABASEPATH, m_strDatabasePath );
  110. DDX_Text( pDX, IDC_PP_DHCP_LOGFILEPATH, m_strLogFilePath );
  111. DDX_Text( pDX, IDC_PP_DHCP_BACKUPPATH, m_strBackupPath );
  112. //}}AFX_DATA_MAP
  113. // Handle numeric parameters.
  114. if ( ! BBackPressed() )
  115. {
  116. } // if: back button not pressed
  117. if ( pDX->m_bSaveAndValidate )
  118. {
  119. // Make sure all required fields are present.
  120. if ( ! BBackPressed() )
  121. {
  122. DDV_RequiredText( pDX, IDC_PP_DHCP_DATABASEPATH, IDC_PP_DHCP_DATABASEPATH_LABEL, m_strDatabasePath );
  123. DDV_RequiredText( pDX, IDC_PP_DHCP_LOGFILEPATH, IDC_PP_DHCP_LOGFILEPATH_LABEL, m_strLogFilePath );
  124. DDV_RequiredText( pDX, IDC_PP_DHCP_BACKUPPATH, IDC_PP_DHCP_BACKUPPATH_LABEL, m_strBackupPath );
  125. } // if: back button not pressed
  126. } // if: saving data from dialog
  127. } // if: not saving or haven't saved yet
  128. CBasePropertyPage::DoDataExchange( pDX );
  129. } //*** CDhcpParamsPage::DoDataExchange()
  130. /////////////////////////////////////////////////////////////////////////////
  131. //++
  132. //
  133. // CDhcpParamsPage::OnInitDialog
  134. //
  135. // Description:
  136. // Handler for the WM_INITDIALOG message.
  137. //
  138. // Arguments:
  139. // None.
  140. //
  141. // Return Value:
  142. // TRUE We need the focus to be set for us.
  143. // FALSE We already set the focus to the proper control.
  144. //
  145. //--
  146. /////////////////////////////////////////////////////////////////////////////
  147. BOOL CDhcpParamsPage::OnInitDialog( void )
  148. {
  149. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  150. CBasePropertyPage::OnInitDialog();
  151. // Limit the size of the text that can be entered in edit controls.
  152. m_editDatabasePath.SetLimitText( _MAX_PATH );
  153. m_editLogFilePath.SetLimitText( _MAX_PATH );
  154. m_editBackupPath.SetLimitText( _MAX_PATH );
  155. // If this is a wizard, make sure the default values are something legal.
  156. if ( BWizard( ) )
  157. {
  158. DWORD status;
  159. WCHAR szValidDevice[ 3 ]; // "X:" + NULL
  160. DWORD dwSize = sizeof(szValidDevice) / sizeof(szValidDevice[0]);
  161. szValidDevice[ 0 ] = L'\0';
  162. status = ResUtilFindDependentDiskResourceDriveLetter( Peo( )->Hcluster( ),
  163. Peo( )->PrdResData( )->m_hresource,
  164. szValidDevice,
  165. &dwSize
  166. );
  167. // Did we find a disk resource in the the dependency list?
  168. if ( status == ERROR_SUCCESS
  169. && szValidDevice[ 0 ] != L'\0' )
  170. {
  171. WCHAR szFilePath[ MAX_PATH ];
  172. // If the default is "%SystemRoot%\<something>" then change it to match the
  173. // dependent resource
  174. if ( m_editDatabasePath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  175. && _wcsnicmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  176. {
  177. // Start with the new drive letter
  178. wcscpy( szFilePath, szValidDevice );
  179. // Is the expanded string really expanded?
  180. if ( m_strDatabaseExpandedPath[0] != L'%' )
  181. { // yes, then just copy the expanded string minus the drive letter.
  182. LPCWSTR psz = m_strDatabaseExpandedPath;
  183. psz = wcschr( psz, L':' );
  184. if ( psz )
  185. {
  186. psz++; // move to next character
  187. }
  188. else // if: psz
  189. {
  190. psz = m_strDatabaseExpandedPath;
  191. } // else: just cat the whole thing, let the user figure it out.
  192. wcscat( szFilePath, psz );
  193. }
  194. else
  195. { // no, then strip the %SystemRoot%
  196. // find the ending '%'... this must be there because of the strcmp above!
  197. LPCWSTR psz = m_strDatabaseExpandedPath;
  198. psz = wcschr( psz + 1, L'%' );
  199. ASSERT( psz );
  200. psz++; // move past the '%'
  201. wcscat( szFilePath, psz );
  202. }
  203. m_editDatabasePath.SetWindowText( szFilePath );
  204. } // if: m_editDatabasePath == %SystemRoot%
  205. // If the default is "%SystemRoot%\<something>" then change it to match the
  206. // dependent resource
  207. if ( m_editLogFilePath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  208. && _wcsnicmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  209. {
  210. // Start with the new drive letter
  211. wcscpy( szFilePath, szValidDevice );
  212. // Is the expanded string really expanded?
  213. if ( m_strLogFileExpandedPath[0] != L'%' )
  214. { // yes, then just copy the expanded string minus the drive letter.
  215. LPCWSTR psz = m_strLogFileExpandedPath;
  216. psz = wcschr( psz, L':' );
  217. if ( psz )
  218. {
  219. psz++; // move to next character
  220. }
  221. else // if: psz
  222. {
  223. psz = m_strLogFileExpandedPath;
  224. } // else: just cat the whole thing, let the user figure it out.
  225. wcscat( szFilePath, psz );
  226. }
  227. else
  228. { // no, then strip the %SystemRoot%
  229. // find the ending '%'... this must be there because of the strcmp above!
  230. LPCWSTR psz = m_strLogFileExpandedPath;
  231. psz = wcschr( psz + 1, L'%' );
  232. ASSERT( psz );
  233. psz++; // move past the '%'
  234. wcscat( szFilePath, psz );
  235. }
  236. m_editLogFilePath.SetWindowText( szFilePath );
  237. } // if: m_editLogFilePath == %SystemRoot%
  238. else if ( szFilePath[0] == L'\0' )
  239. { // no path found - default to the same as the database path
  240. m_editDatabasePath.GetWindowText( szFilePath, MAX_PATH );
  241. m_editLogFilePath.SetWindowText( szFilePath );
  242. } // else: no log path found
  243. // If the default is "%SystemRoot%\<something>" then change it to match the
  244. // dependent resource
  245. if ( m_editBackupPath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  246. && _wcsnicmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  247. {
  248. // Start with the new drive letter
  249. wcscpy( szFilePath, szValidDevice );
  250. // Is the expanded string really expanded?
  251. if ( m_strBackupExpandedPath[0] != L'%' )
  252. { // yes, then just copy the expanded string minus the drive letter.
  253. LPCWSTR psz = m_strBackupExpandedPath;
  254. psz = wcschr( psz, L':' );
  255. if ( psz )
  256. {
  257. psz++; // move to next character
  258. }
  259. else // if: psz
  260. {
  261. psz = m_strBackupExpandedPath;
  262. } // else: just cat the whole thing, let the user figure it out.
  263. wcscat( szFilePath, psz );
  264. }
  265. else
  266. { // no, then strip the %SystemRoot%
  267. // find the ending '%'... this must be there because of the strcmp above!
  268. LPCWSTR psz = m_strBackupExpandedPath;
  269. psz = wcschr( psz + 1, L'%' );
  270. ASSERT( psz );
  271. psz++; // move past the '%'
  272. wcscat( szFilePath, psz );
  273. }
  274. m_editBackupPath.SetWindowText( szFilePath );
  275. } // if: m_editBackupPath == %SystemRoot%
  276. } // if: found a disk resource
  277. } // if: in a wizard
  278. return TRUE; // return TRUE unless you set the focus to a control
  279. // EXCEPTION: OCX Property Pages should return FALSE
  280. } //*** CDhcpParamsPage::OnInitDialog()
  281. /////////////////////////////////////////////////////////////////////////////
  282. //++
  283. //
  284. // CDhcpParamsPage::OnSetActive
  285. //
  286. // Description:
  287. // Handler for the PSN_SETACTIVE message.
  288. //
  289. // Arguments:
  290. // None.
  291. //
  292. // Return Value:
  293. // TRUE Page successfully initialized.
  294. // FALSE Page not initialized.
  295. //
  296. //--
  297. /////////////////////////////////////////////////////////////////////////////
  298. BOOL CDhcpParamsPage::OnSetActive( void )
  299. {
  300. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  301. // Enable/disable the Next/Finish button.
  302. if ( BWizard() )
  303. {
  304. EnableNext( BAllRequiredFieldsPresent() );
  305. } // if: displaying a wizard
  306. return CBasePropertyPage::OnSetActive();
  307. } //*** CDhcpParamsPage::OnSetActive()
  308. /////////////////////////////////////////////////////////////////////////////
  309. //++
  310. //
  311. // CDhcpParamsPage::OnChangeRequiredField
  312. //
  313. // Description:
  314. // Handler for the EN_CHANGE message on the Share name or Path edit
  315. // controls.
  316. //
  317. // Arguments:
  318. // None.
  319. //
  320. // Return Value:
  321. // None.
  322. //
  323. //--
  324. /////////////////////////////////////////////////////////////////////////////
  325. void CDhcpParamsPage::OnChangeRequiredField( void )
  326. {
  327. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  328. OnChangeCtrl();
  329. if ( BWizard() )
  330. {
  331. EnableNext( BAllRequiredFieldsPresent() );
  332. } // if: displaying a wizard
  333. } //*** CDhcpParamsPage::OnChangeRequiredField()
  334. /////////////////////////////////////////////////////////////////////////////
  335. //++
  336. //
  337. // CDhcpParamsPage::BAllRequiredFieldsPresent
  338. //
  339. // Description:
  340. // Handler for the EN_CHANGE message on the Share name or Path edit
  341. // controls.
  342. //
  343. // Arguments:
  344. // None.
  345. //
  346. // Return Value:
  347. // None.
  348. //
  349. //--
  350. /////////////////////////////////////////////////////////////////////////////
  351. BOOL CDhcpParamsPage::BAllRequiredFieldsPresent( void ) const
  352. {
  353. BOOL _bPresent;
  354. if ( 0
  355. || (m_editDatabasePath.GetWindowTextLength() == 0)
  356. || (m_editLogFilePath.GetWindowTextLength() == 0)
  357. || (m_editBackupPath.GetWindowTextLength() == 0)
  358. )
  359. {
  360. _bPresent = FALSE;
  361. } // if: required field not present
  362. else
  363. {
  364. _bPresent = TRUE;
  365. } // else: all required fields are present
  366. return _bPresent;
  367. } //*** CDhcpParamsPage::BAllRequiredFieldsPresent()