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.

368 lines
10 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999 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. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  144. CBasePropertyPage::OnInitDialog();
  145. // Limit the size of the text that can be entered in edit controls.
  146. m_editDatabasePath.SetLimitText( _MAX_PATH );
  147. m_editBackupPath.SetLimitText( _MAX_PATH );
  148. // If this is a wizard, make sure the default values are something legal.
  149. if ( BWizard( ) )
  150. {
  151. DWORD status;
  152. WCHAR szValidDevice[ 3 ]; // "X:" + NULL
  153. DWORD dwSize = sizeof(szValidDevice) / sizeof(szValidDevice[0]);
  154. szValidDevice[ 0 ] = L'\0';
  155. status = ResUtilFindDependentDiskResourceDriveLetter( Peo( )->Hcluster( ),
  156. Peo( )->PrdResData( )->m_hresource,
  157. szValidDevice,
  158. &dwSize
  159. );
  160. // Did we find a disk resource in the the dependency list?
  161. if ( status == ERROR_SUCCESS
  162. && szValidDevice[ 0 ] != L'\0' )
  163. {
  164. WCHAR szFilePath[ MAX_PATH ];
  165. // If the default is "%SystemRoot%\<something>" then change it to match the
  166. // dependent resource
  167. if ( m_editDatabasePath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  168. && _wcsnicmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  169. {
  170. // Start with the new drive letter
  171. wcscpy( szFilePath, szValidDevice );
  172. // Is the expanded string really expanded?
  173. if ( m_strDatabaseExpandedPath[0] != L'%' )
  174. { // yes, then just copy the expanded string minus the drive letter.
  175. LPCWSTR psz = m_strDatabaseExpandedPath;
  176. psz = wcschr( psz, L':' );
  177. if ( psz )
  178. {
  179. psz++; // move to next character
  180. }
  181. else // if: psz
  182. {
  183. psz = m_strDatabaseExpandedPath;
  184. } // else: just cat the whole thing, let the user figure it out.
  185. wcscat( szFilePath, psz );
  186. }
  187. else
  188. { // no, then strip the %SystemRoot%
  189. // find the ending '%'... this must be there because of the strcmp above!
  190. LPCWSTR psz = m_strBackupExpandedPath;
  191. psz = wcschr( psz + 1, L'%' );
  192. ASSERT( psz );
  193. psz++; // move past the '%'
  194. wcscat( szFilePath, psz );
  195. }
  196. m_editDatabasePath.SetWindowText( szFilePath );
  197. } // if: m_editDatabasePath == %SystemRoot%
  198. // If the default is "%SystemRoot%\<something>" then change it to match the
  199. // dependent resource
  200. if ( m_editBackupPath.GetWindowText( szFilePath, MAX_PATH ) >= sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1
  201. && _wcsnicmp( szFilePath, L"%SystemRoot%", sizeof(L"%SystemRoot%")/sizeof(WCHAR) - 1 ) == 0 )
  202. {
  203. // Start with the new drive letter
  204. wcscpy( szFilePath, szValidDevice );
  205. // Is the expanded string really expanded?
  206. if ( m_strBackupExpandedPath[0] != L'%' )
  207. { // yes, then just copy the expanded string minus the drive letter. minus the drive letter.
  208. LPCWSTR psz = m_strBackupExpandedPath;
  209. psz = wcschr( psz, L':' );
  210. if ( psz )
  211. {
  212. psz++; // move to next character
  213. }
  214. else // if: psz
  215. {
  216. psz = m_strBackupExpandedPath;
  217. } // else: just cat the whole thing, let the user figure it out.
  218. wcscat( szFilePath, psz );
  219. }
  220. else
  221. { // no, then strip the %SystemRoot%
  222. // find the ending '%'... this must be there because of the strcmp above!
  223. LPCWSTR psz = m_strBackupExpandedPath;
  224. psz = wcschr( psz + 1, L'%' );
  225. ASSERT( psz );
  226. psz++; // move past the '%'
  227. wcscat( szFilePath, psz );
  228. }
  229. m_editBackupPath.SetWindowText( szFilePath );
  230. } // if: m_editBackupPath == %SystemRoot%
  231. } // if: found a disk resource
  232. } // if: in a wizard
  233. return TRUE; // return TRUE unless you set the focus to a control
  234. // EXCEPTION: OCX Property Pages should return FALSE
  235. } //*** CWinsParamsPage::OnInitDialog()
  236. /////////////////////////////////////////////////////////////////////////////
  237. //++
  238. //
  239. // CWinsParamsPage::OnSetActive
  240. //
  241. // Description:
  242. // Handler for the PSN_SETACTIVE message.
  243. //
  244. // Arguments:
  245. // None.
  246. //
  247. // Return Value:
  248. // TRUE Page successfully initialized.
  249. // FALSE Page not initialized.
  250. //
  251. //--
  252. /////////////////////////////////////////////////////////////////////////////
  253. BOOL CWinsParamsPage::OnSetActive( void )
  254. {
  255. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  256. // Enable/disable the Next/Finish button.
  257. if ( BWizard() )
  258. {
  259. EnableNext( BAllRequiredFieldsPresent() );
  260. } // if: displaying a wizard
  261. return CBasePropertyPage::OnSetActive();
  262. } //*** CWinsParamsPage::OnSetActive()
  263. /////////////////////////////////////////////////////////////////////////////
  264. //++
  265. //
  266. // CWinsParamsPage::OnChangeRequiredField
  267. //
  268. // Description:
  269. // Handler for the EN_CHANGE message on the Share name or Path edit
  270. // controls.
  271. //
  272. // Arguments:
  273. // None.
  274. //
  275. // Return Value:
  276. // None.
  277. //
  278. //--
  279. /////////////////////////////////////////////////////////////////////////////
  280. void CWinsParamsPage::OnChangeRequiredField( void )
  281. {
  282. AFX_MANAGE_STATE( AfxGetStaticModuleState() );
  283. OnChangeCtrl();
  284. if ( BWizard() )
  285. {
  286. EnableNext( BAllRequiredFieldsPresent() );
  287. } // if: displaying a wizard
  288. } //*** CWinsParamsPage::OnChangeRequiredField()
  289. /////////////////////////////////////////////////////////////////////////////
  290. //++
  291. //
  292. // CWinsParamsPage::BAllRequiredFieldsPresent
  293. //
  294. // Description:
  295. // Handler for the EN_CHANGE message on the Share name or Path edit
  296. // controls.
  297. //
  298. // Arguments:
  299. // None.
  300. //
  301. // Return Value:
  302. // None.
  303. //
  304. //--
  305. /////////////////////////////////////////////////////////////////////////////
  306. BOOL CWinsParamsPage::BAllRequiredFieldsPresent( void ) const
  307. {
  308. BOOL _bPresent;
  309. if ( 0
  310. || (m_editDatabasePath.GetWindowTextLength() == 0)
  311. || (m_editBackupPath.GetWindowTextLength() == 0)
  312. )
  313. {
  314. _bPresent = FALSE;
  315. } // if: required field not present
  316. else
  317. {
  318. _bPresent = TRUE;
  319. } // else: all required fields are present
  320. return _bPresent;
  321. } //*** CWinsParamsPage::BAllRequiredFieldsPresent()