Leaked source code of windows server 2003
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.

398 lines
13 KiB

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