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.

491 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // FSCache.cpp
  7. //
  8. // Description:
  9. // Implementation of the CFileShareCachingDlg classes.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 12-MAR-2001
  13. //
  14. // Notes:
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "FSCache.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CFileShareCachingDlg property page
  26. /////////////////////////////////////////////////////////////////////////////
  27. //const LPSTR CACHE_HELPFILENAME = "offlinefolders.chm";
  28. //const LPSTR CACHE_HELP_TOPIC = "csc_and_shares.htm";
  29. const LPSTR CACHE_HELPFILENAME = "mscsconcepts.chm";
  30. const LPSTR CACHE_HELP_TOPIC = "cluad_pr_100.htm";
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Message Maps
  33. BEGIN_MESSAGE_MAP( CFileShareCachingDlg, CDialog )
  34. //{{AFX_MSG_MAP(CFileShareCachingDlg)
  35. ON_CBN_SELCHANGE(IDC_FILESHR_CACHE_OPTIONS, OnCbnSelchangeCacheOptions)
  36. ON_BN_CLICKED(IDC_FILESHR_CACHE_ALLOW_CACHING, OnBnClickedAllowCaching)
  37. ON_BN_CLICKED(IDC_FILESHR_CACHE_CS_HELP, OnBnClickedHelp)
  38. ON_WM_HELPINFO()
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. //++
  43. //
  44. // CFileShareCachingDlg::CFileShareCachingDlg
  45. //
  46. // Description:
  47. // Constructor.
  48. //
  49. // Arguments:
  50. // dwFlagsIn -- Cache flags.
  51. // pParentIn -- Parent window.
  52. //
  53. // Return Values:
  54. // None.
  55. //
  56. //--
  57. /////////////////////////////////////////////////////////////////////////////
  58. CFileShareCachingDlg::CFileShareCachingDlg(
  59. DWORD dwFlagsIn
  60. , CWnd * pParentIn
  61. )
  62. : CDialog( CFileShareCachingDlg::IDD, pParentIn )
  63. , m_dwFlags( dwFlagsIn )
  64. {
  65. //{{AFX_DATA_INIT(CFileShareCachingDlg)
  66. m_fAllowCaching = FALSE;
  67. m_strHint = _T("");
  68. //}}AFX_DATA_INIT
  69. m_fAllowCaching = ! GetCachedFlag( m_dwFlags, CSC_CACHE_NONE );
  70. } //*** CFileShareCachingDlg::CFileShareCachingDlg()
  71. /////////////////////////////////////////////////////////////////////////////
  72. //++
  73. //
  74. // CFileShareCachingDlg::DoDataExchange
  75. //
  76. // Description:
  77. // Do data exchange between the dialog and the class.
  78. //
  79. // Arguments:
  80. // pDX [IN OUT] Data exchange object
  81. //
  82. // Return Values:
  83. // None.
  84. //
  85. //--
  86. /////////////////////////////////////////////////////////////////////////////
  87. void
  88. CFileShareCachingDlg::DoDataExchange(
  89. CDataExchange * pDX
  90. )
  91. {
  92. CDialog::DoDataExchange( pDX );
  93. //{{AFX_DATA_MAP(CFileShareCachingDlg)
  94. DDX_Control(pDX, IDC_FILESHR_CACHE_OPTIONS, m_cboCacheOptions);
  95. DDX_Control(pDX, IDC_FILESHR_CACHE_HINT, m_staticHint);
  96. DDX_Check(pDX, IDC_FILESHR_CACHE_ALLOW_CACHING, m_fAllowCaching);
  97. DDX_Text(pDX, IDC_FILESHR_CACHE_HINT, m_strHint);
  98. //}}AFX_DATA_MAP
  99. } //*** CFileShareCachingDlg::DoDataExchange()
  100. /////////////////////////////////////////////////////////////////////////////
  101. //++
  102. //
  103. // CFileShareCachingDlg::OnInitDialog
  104. //
  105. // Routine Description:
  106. // Handler for the WM_INITDIALOG message.
  107. //
  108. // Arguments:
  109. // None.
  110. //
  111. // Return Value:
  112. // TRUE We need the focus to be set for us.
  113. // FALSE We already set the focus to the proper control.
  114. //
  115. //--
  116. /////////////////////////////////////////////////////////////////////////////
  117. BOOL
  118. CFileShareCachingDlg::OnInitDialog( void )
  119. {
  120. CDialog::OnInitDialog();
  121. CString strText;
  122. int nIndex;
  123. //
  124. // Add the various caching options to the combo box.
  125. // Save the string ID in the item data for easy recognition of the
  126. // contents of the selected item.
  127. // If the given cache value is set, select the item and put its hint in
  128. // the hint field.
  129. //
  130. // Add the manual sharing string.
  131. VERIFY( strText.LoadString( IDS_CSC_MANUAL_WORKGROUP_SHARE ) );
  132. nIndex = m_cboCacheOptions.AddString( strText );
  133. ASSERT( ( nIndex != CB_ERR ) && ( nIndex != CB_ERRSPACE ) );
  134. if ( ( nIndex == CB_ERR ) || ( nIndex == CB_ERRSPACE ) )
  135. {
  136. goto Cleanup;
  137. }
  138. VERIFY( CB_ERR != m_cboCacheOptions.SetItemData( nIndex, IDS_CSC_MANUAL_WORKGROUP_SHARE ) );
  139. if ( GetCachedFlag( m_dwFlags, CSC_CACHE_MANUAL_REINT ) )
  140. {
  141. VERIFY( CB_ERR != m_cboCacheOptions.SetCurSel( nIndex ) );
  142. VERIFY( m_strHint.LoadString( IDS_CSC_MANUAL_WORKGROUP_SHARE_HINT ) );
  143. }
  144. // Add the automatic workgroup sharing string.
  145. VERIFY( strText.LoadString( IDS_CSC_AUTOMATIC_WORKGROUP_SHARE ) );
  146. nIndex = m_cboCacheOptions.AddString( strText );
  147. ASSERT( ( nIndex != CB_ERR ) && ( nIndex != CB_ERRSPACE ) );
  148. if ( ( nIndex == CB_ERR ) || ( nIndex == CB_ERRSPACE ) )
  149. {
  150. goto Cleanup;
  151. }
  152. VERIFY( CB_ERR != m_cboCacheOptions.SetItemData( nIndex, IDS_CSC_AUTOMATIC_WORKGROUP_SHARE ) );
  153. if ( GetCachedFlag( m_dwFlags, CSC_CACHE_AUTO_REINT ) )
  154. {
  155. VERIFY( CB_ERR != m_cboCacheOptions.SetCurSel (nIndex));
  156. VERIFY( m_strHint.LoadString( IDS_CSC_AUTOMATIC_WORKGROUP_SHARE_HINT ) );
  157. }
  158. // Add the automatic application sharing string.
  159. VERIFY( strText.LoadString( IDS_CSC_AUTOMATIC_APPLICATION_SHARE ) );
  160. nIndex = m_cboCacheOptions.AddString( strText );
  161. ASSERT( ( nIndex != CB_ERR ) && ( nIndex != CB_ERRSPACE ) );
  162. if ( ( nIndex == CB_ERR ) || ( nIndex == CB_ERRSPACE ) )
  163. {
  164. goto Cleanup;
  165. }
  166. VERIFY( CB_ERR != m_cboCacheOptions.SetItemData( nIndex, IDS_CSC_AUTOMATIC_APPLICATION_SHARE ) );
  167. if ( GetCachedFlag( m_dwFlags, CSC_CACHE_VDO ) )
  168. {
  169. VERIFY( CB_ERR != m_cboCacheOptions.SetCurSel( nIndex ) );
  170. VERIFY( m_strHint.LoadString( IDS_CSC_AUTOMATIC_APPLICATION_SHARE_HINT ) );
  171. }
  172. // Disable able the caching options combo box if caching is not allowed
  173. if ( ! m_fAllowCaching )
  174. {
  175. m_cboCacheOptions.EnableWindow( FALSE );
  176. m_strHint = L"";
  177. }
  178. Cleanup:
  179. UpdateData( FALSE );
  180. return TRUE; // return TRUE unless you set the focus to a control
  181. // EXCEPTION: OCX Property Pages should return FALSE
  182. } //*** CFileShareCachingDlg::OnInitDialog()
  183. /////////////////////////////////////////////////////////////////////////////
  184. //++
  185. //
  186. // CFileShareCachingDlg::OnOK
  187. //
  188. // Routine Description:
  189. // Handler for the BN_CLICKED message on the OK button.
  190. //
  191. // Arguments:
  192. // None.
  193. //
  194. // Return Value:
  195. // None.
  196. //
  197. //--
  198. /////////////////////////////////////////////////////////////////////////////
  199. void
  200. CFileShareCachingDlg::OnOK( void )
  201. {
  202. DWORD dwNewFlag = 0;
  203. if ( ! m_fAllowCaching )
  204. {
  205. dwNewFlag = CSC_CACHE_NONE;
  206. }
  207. else
  208. {
  209. int nIndex = m_cboCacheOptions.GetCurSel();
  210. ASSERT( nIndex != CB_ERR );
  211. if ( nIndex != CB_ERR )
  212. {
  213. DWORD dwData = (DWORD) m_cboCacheOptions.GetItemData( nIndex );
  214. switch ( dwData )
  215. {
  216. case IDS_CSC_MANUAL_WORKGROUP_SHARE:
  217. dwNewFlag = CSC_CACHE_MANUAL_REINT;
  218. break;
  219. case IDS_CSC_AUTOMATIC_WORKGROUP_SHARE:
  220. dwNewFlag = CSC_CACHE_AUTO_REINT;
  221. break;
  222. case IDS_CSC_AUTOMATIC_APPLICATION_SHARE:
  223. dwNewFlag = CSC_CACHE_VDO;
  224. break;
  225. default:
  226. ASSERT( 0 );
  227. break;
  228. } // switch: item data
  229. } // if: option is selected
  230. } // else: caching is allowed
  231. SetCachedFlag( &m_dwFlags, dwNewFlag );
  232. CDialog::OnOK();
  233. } //*** CFileShareCachingDlg::OnOK()
  234. /////////////////////////////////////////////////////////////////////////////
  235. //++
  236. //
  237. // CFileShareCachingDlg::OnCbnSelchangeCacheOptions
  238. //
  239. // Description:
  240. // Handler for the CBN_SELCHANGE message on the options combobox.
  241. // Change the hint control when the option has changed.
  242. //
  243. // Arguments:
  244. // None.
  245. //
  246. // Return Values:
  247. // None.
  248. //
  249. //--
  250. /////////////////////////////////////////////////////////////////////////////
  251. void
  252. CFileShareCachingDlg::OnCbnSelchangeCacheOptions( void )
  253. {
  254. int nIndex = m_cboCacheOptions.GetCurSel();
  255. ASSERT( nIndex != CB_ERR );
  256. if ( nIndex != CB_ERR )
  257. {
  258. DWORD dwData = (DWORD) m_cboCacheOptions.GetItemData( nIndex );
  259. switch ( dwData )
  260. {
  261. case IDS_CSC_MANUAL_WORKGROUP_SHARE:
  262. VERIFY( m_strHint.LoadString( IDS_CSC_MANUAL_WORKGROUP_SHARE_HINT ) );
  263. break;
  264. case IDS_CSC_AUTOMATIC_WORKGROUP_SHARE:
  265. VERIFY( m_strHint.LoadString( IDS_CSC_AUTOMATIC_WORKGROUP_SHARE_HINT ) );
  266. break;
  267. case IDS_CSC_AUTOMATIC_APPLICATION_SHARE:
  268. VERIFY( m_strHint.LoadString( IDS_CSC_AUTOMATIC_APPLICATION_SHARE_HINT ) );
  269. break;
  270. default:
  271. ASSERT( 0 );
  272. break;
  273. } // switch: item data
  274. UpdateData( FALSE );
  275. } // if: something is selected
  276. } //*** CFileShareCachingDlg::OnCbnSelchangeCacheOptions()
  277. /////////////////////////////////////////////////////////////////////////////
  278. //++
  279. //
  280. // CFileShareCachingDlg::OnBnClickedAllowCaching
  281. //
  282. // Description:
  283. // Handler for the BN_CLICKED message on the Allow Caching checkbox.
  284. // Enable or disable controls and load a hint if enabled.
  285. //
  286. // Arguments:
  287. // None.
  288. //
  289. // Return Values:
  290. // None.
  291. //
  292. //--
  293. /////////////////////////////////////////////////////////////////////////////
  294. void
  295. CFileShareCachingDlg::OnBnClickedAllowCaching( void )
  296. {
  297. UpdateData( TRUE );
  298. if ( m_fAllowCaching )
  299. {
  300. CString strText;
  301. int nIndex;
  302. m_staticHint.EnableWindow( TRUE );
  303. m_cboCacheOptions.EnableWindow (TRUE);
  304. VERIFY( strText.LoadString ( IDS_CSC_MANUAL_WORKGROUP_SHARE ) );
  305. nIndex = m_cboCacheOptions.SelectString( -1, strText );
  306. ASSERT( CB_ERR != nIndex );
  307. if ( CB_ERR != nIndex )
  308. {
  309. VERIFY( m_strHint.LoadString( IDS_CSC_MANUAL_WORKGROUP_SHARE_HINT ) );
  310. UpdateData( FALSE );
  311. }
  312. }
  313. else
  314. {
  315. m_staticHint.EnableWindow( FALSE );
  316. m_cboCacheOptions.SetCurSel( -1 );
  317. m_cboCacheOptions.EnableWindow( FALSE );
  318. m_strHint = L"";
  319. UpdateData( FALSE );
  320. }
  321. } //*** CFileShareCachingDlg::OnBnClickedAllowCaching()
  322. /////////////////////////////////////////////////////////////////////////////
  323. //++
  324. //
  325. // CFileShareCachingDlg::OnBnClickedHelp
  326. //
  327. // Description:
  328. // Handler for the BN_CLICKED message on the Help pushbutton.
  329. // Display HTML help.
  330. //
  331. // Arguments:
  332. // None.
  333. //
  334. // Return Values:
  335. // None.
  336. //
  337. //--
  338. /////////////////////////////////////////////////////////////////////////////
  339. void
  340. CFileShareCachingDlg::OnBnClickedHelp( void )
  341. {
  342. ::HtmlHelpA(
  343. m_hWnd
  344. , CACHE_HELPFILENAME
  345. , HH_DISPLAY_TOPIC
  346. , (ULONG_PTR) CACHE_HELP_TOPIC
  347. );
  348. } //*** CFileShareCachingDlg::OnBnClickedHelp()
  349. /////////////////////////////////////////////////////////////////////////////
  350. //++
  351. //
  352. // CFileShareCachingDlg::OnHelpInfo
  353. //
  354. // Description:
  355. // MFC message handler for help.
  356. // Display HTML help.
  357. //
  358. // Arguments:
  359. // pHelpInfoIn --
  360. //
  361. // Return Values:
  362. // None.
  363. //
  364. //--
  365. /////////////////////////////////////////////////////////////////////////////
  366. BOOL
  367. CFileShareCachingDlg::OnHelpInfo(
  368. HELPINFO * pHelpInfoIn
  369. )
  370. {
  371. ASSERT( pHelpInfoIn != NULL );
  372. if ( ( pHelpInfoIn != NULL )
  373. && ( pHelpInfoIn->iContextType == HELPINFO_WINDOW ) )
  374. {
  375. ::HtmlHelpA(
  376. m_hWnd
  377. , CACHE_HELPFILENAME
  378. , HH_DISPLAY_TOPIC
  379. , (ULONG_PTR) CACHE_HELP_TOPIC
  380. );
  381. }
  382. return CDialog::OnHelpInfo( pHelpInfoIn );
  383. } //*** CFileShareCachingDlg::OnHelpInfo()
  384. /////////////////////////////////////////////////////////////////////////////
  385. //++
  386. //
  387. // CFileShareCachingDlg::GetCachedFlag
  388. //
  389. // Description:
  390. // Get the current state of the specified flag in the specified flags mask.
  391. //
  392. // Arguments:
  393. // dwFlagsIn -- Flags to check.
  394. // dwFlagsToCheckIn -- Flag to look for.
  395. //
  396. //
  397. // Return Values:
  398. // TRUE -- Flag is set.
  399. // FALSE -- Flag is not set.
  400. //
  401. //--
  402. /////////////////////////////////////////////////////////////////////////////
  403. inline
  404. BOOL
  405. CFileShareCachingDlg::GetCachedFlag(
  406. DWORD dwFlagsIn
  407. , DWORD dwFlagToCheckIn
  408. )
  409. {
  410. return (dwFlagsIn & CSC_MASK) == dwFlagToCheckIn;
  411. } //*** CFileShareCachingDlg::GetCachedFlag()
  412. /////////////////////////////////////////////////////////////////////////////
  413. //++
  414. //
  415. // CFileShareCachingDlg::GetCachedFlag
  416. //
  417. // Description:
  418. // Set the specified flag in the specified flags mask.
  419. //
  420. // Arguments:
  421. // pdwFlagsInout -- Flags mask to modify.
  422. // dwNewFlagIn -- Flags to set.
  423. //
  424. // Return Values:
  425. // TRUE -- Flag is set.
  426. // FALSE -- Flag is not set.
  427. //
  428. //--
  429. /////////////////////////////////////////////////////////////////////////////
  430. inline
  431. void
  432. CFileShareCachingDlg::SetCachedFlag(
  433. DWORD * pdwFlagsInout
  434. , DWORD dwNewFlagIn
  435. )
  436. {
  437. *pdwFlagsInout &= ~CSC_MASK;
  438. *pdwFlagsInout |= dwNewFlagIn;
  439. } //*** CFileShareCachingDlg::SetCachedFlag()