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.

669 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. defws.cpp
  5. Abstract:
  6. Default Web Site Dialog
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "w3scfg.h"
  18. #include "defws.h"
  19. #include "dirbrows.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. //
  26. // Directory Size Units
  27. //
  28. #define DS_UNITS MEGABYTE
  29. //
  30. // Default Web Site Property Page
  31. //
  32. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  33. IMPLEMENT_DYNCREATE(CDefWebSitePage, CInetPropertyPage)
  34. CDefWebSitePage::CDefWebSitePage(
  35. IN CInetPropertySheet * pSheet
  36. )
  37. /*++
  38. Routine Description:
  39. Constructor for WWW Default Web Site page
  40. Arguments:
  41. CInetPropertySheet * pSheet : Sheet object
  42. Return Value:
  43. N/A
  44. --*/
  45. : CInetPropertyPage(CDefWebSitePage::IDD, pSheet),
  46. m_ppropCompression(NULL),
  47. m_fFilterPathFound(FALSE),
  48. m_fCompressionDirectoryChanged(FALSE)
  49. {
  50. #if 0 // Keep Class Wizard happy
  51. //{{AFX_DATA_INIT(CDefWebSitePage)
  52. m_fEnableDynamic = FALSE;
  53. m_fEnableStatic = FALSE;
  54. m_strDirectory = _T("");
  55. m_nUnlimited = -1;
  56. m_ilSize = 0L;
  57. //}}AFX_DATA_INIT
  58. #endif // 0
  59. }
  60. CDefWebSitePage::~CDefWebSitePage()
  61. /*++
  62. Routine Description:
  63. Destructor
  64. Arguments:
  65. N/A
  66. Return Value:
  67. N/A
  68. --*/
  69. {
  70. }
  71. void
  72. CDefWebSitePage::DoDataExchange(
  73. IN CDataExchange * pDX
  74. )
  75. /*++
  76. Routine Description:
  77. Initialise/Store control data
  78. Arguments:
  79. CDataExchange * pDX - DDX/DDV control structure
  80. Return Value:
  81. None
  82. --*/
  83. {
  84. CInetPropertyPage::DoDataExchange(pDX);
  85. //{{AFX_DATA_MAP(CDefWebSitePage)
  86. DDX_Control(pDX, IDC_EDIT_COMPRESS_DIRECTORY, m_edit_Directory);
  87. DDX_Control(pDX, IDC_BUTTON_BROWSE, m_button_Browse);
  88. DDX_Control(pDX, IDC_STATIC_COMPRESS_MB, m_static_MB);
  89. DDX_Control(pDX, IDC_EDIT_COMPRESS_DIRECTORY_SIZE, m_edit_DirectorySize);
  90. DDX_Check(pDX, IDC_CHECK_DYNAMIC_COMPRESSION, m_fEnableDynamic);
  91. DDX_Check(pDX, IDC_CHECK_STATIC_COMPRESSION, m_fEnableStatic);
  92. DDX_Radio(pDX, IDC_RADIO_COMPRESS_UNLIMITED, m_nUnlimited);
  93. //}}AFX_DATA_MAP
  94. if (HasCompression())
  95. {
  96. if (!pDX->m_bSaveAndValidate || m_fEnableStatic)
  97. {
  98. DDX_Text(pDX, IDC_EDIT_COMPRESS_DIRECTORY, m_strDirectory);
  99. DDV_MaxChars(pDX, m_strDirectory, _MAX_PATH);
  100. }
  101. if (pDX->m_bSaveAndValidate && m_fEnableStatic)
  102. {
  103. if (!IsFullyQualifiedPath(m_strDirectory))
  104. {
  105. ::AfxMessageBox(IDS_ERR_INVALID_PATH);
  106. pDX->Fail();
  107. }
  108. //
  109. // Perform some additional smart checking on the compression
  110. // directory if the current machine is local, and the
  111. // directory has changed
  112. //
  113. if (IsLocal() && m_fCompressionDirectoryChanged)
  114. {
  115. //
  116. // Should exist on the local machine.
  117. //
  118. DWORD dwAttr = GetFileAttributes(m_strDirectory);
  119. if (dwAttr == 0xffffffff
  120. || (dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0
  121. || IsNetworkPath(m_strDirectory)
  122. )
  123. {
  124. ::AfxMessageBox(IDS_ERR_COMPRESS_DIRECTORY);
  125. pDX->Fail();
  126. }
  127. //
  128. // Now check to make sure the volume is of the correct
  129. // type.
  130. //
  131. DWORD dwFileSystemFlags;
  132. if (::GetVolumeInformationSystemFlags(
  133. m_strDirectory,
  134. &dwFileSystemFlags
  135. ))
  136. {
  137. if (!(dwFileSystemFlags & FS_PERSISTENT_ACLS))
  138. {
  139. //
  140. // No ACLS
  141. //
  142. if (!NoYesMessageBox(IDS_NO_ACL_WARNING))
  143. {
  144. pDX->Fail();
  145. }
  146. }
  147. if (dwFileSystemFlags & FS_VOL_IS_COMPRESSED
  148. || dwAttr & FILE_ATTRIBUTE_COMPRESSED)
  149. {
  150. //
  151. // Compression cache directory is itself compressed
  152. //
  153. if (!NoYesMessageBox(IDS_COMPRESS_WARNING))
  154. {
  155. pDX->Fail();
  156. }
  157. }
  158. }
  159. }
  160. }
  161. if (!pDX->m_bSaveAndValidate || (m_fEnableLimiting && m_fEnableStatic))
  162. {
  163. DDX_Text(pDX, IDC_EDIT_COMPRESS_DIRECTORY_SIZE, m_ilSize);
  164. DDV_MinMaxLong(pDX, m_ilSize, 1, 1024L);
  165. }
  166. }
  167. }
  168. //
  169. // Message Map
  170. //
  171. BEGIN_MESSAGE_MAP(CDefWebSitePage, CInetPropertyPage)
  172. //{{AFX_MSG_MAP(CDefWebSitePage)
  173. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  174. ON_BN_CLICKED(IDC_RADIO_COMPRESS_LIMITED, OnRadioLimited)
  175. ON_BN_CLICKED(IDC_RADIO_COMPRESS_UNLIMITED, OnRadioUnlimited)
  176. ON_BN_CLICKED(IDC_CHECK_DYNAMIC_COMPRESSION, OnCheckDynamicCompression)
  177. ON_BN_CLICKED(IDC_CHECK_STATIC_COMPRESSION, OnCheckStaticCompression)
  178. ON_EN_CHANGE(IDC_EDIT_COMPRESS_DIRECTORY, OnChangeEditCompressDirectory)
  179. ON_WM_DESTROY()
  180. //}}AFX_MSG_MAP
  181. ON_EN_CHANGE(IDC_EDIT_COMPRESS_DIRECTORY, OnItemChanged)
  182. ON_EN_CHANGE(IDC_EDIT_COMPRESS_DIRECTORY_SIZE, OnItemChanged)
  183. END_MESSAGE_MAP()
  184. void
  185. CDefWebSitePage::SetControlStates()
  186. /*++
  187. Routine Description:
  188. Enable/disable control states depending on the state of
  189. the dialog.
  190. Arguments:
  191. None
  192. Return Value:
  193. None
  194. --*/
  195. {
  196. GetDlgItem(IDC_STATIC_COMPRESS_DIRECTORY)->EnableWindow(m_fEnableStatic);
  197. m_edit_Directory.EnableWindow(m_fEnableStatic);
  198. m_edit_DirectorySize.EnableWindow(m_fEnableStatic && m_fEnableLimiting);
  199. m_static_MB.EnableWindow(m_fEnableStatic&& m_fEnableLimiting);
  200. GetDlgItem(IDC_RADIO_COMPRESS_LIMITED)->EnableWindow(m_fEnableStatic);
  201. GetDlgItem(IDC_RADIO_COMPRESS_UNLIMITED)->EnableWindow(m_fEnableStatic);
  202. GetDlgItem(IDC_STATIC_MAX_COMPRESS_SIZE)->EnableWindow(m_fEnableStatic);
  203. //
  204. // Browse on the local machine only
  205. //
  206. m_button_Browse.EnableWindow(IsLocal() && m_fEnableStatic);
  207. }
  208. /* virtual */
  209. HRESULT
  210. CDefWebSitePage::FetchLoadedValues()
  211. /*++
  212. Routine Description:
  213. Move configuration data from sheet to dialog controls
  214. Arguments:
  215. None
  216. Return Value:
  217. HRESULT
  218. --*/
  219. {
  220. CError err;
  221. ASSERT(m_ppropCompression == NULL);
  222. m_ppropCompression = new CIISCompressionProps(GetServerName());
  223. if (m_ppropCompression)
  224. {
  225. err = m_ppropCompression->LoadData();
  226. m_fFilterPathFound = err.Succeeded();
  227. if (err.Succeeded())
  228. {
  229. m_fEnableDynamic = m_ppropCompression->m_fEnableDynamicCompression;
  230. m_fEnableStatic = m_ppropCompression->m_fEnableStaticCompression;
  231. m_fEnableLimiting = m_ppropCompression->m_fLimitDirectorySize;
  232. m_strDirectory = m_ppropCompression->m_strDirectory;
  233. m_nUnlimited = m_fEnableLimiting ? RADIO_LIMITED : RADIO_UNLIMITED;
  234. if (m_ppropCompression->m_dwDirectorySize == 0xffffffff)
  235. {
  236. m_ilSize = DEF_MAX_COMPDIR_SIZE / DS_UNITS;
  237. }
  238. else
  239. {
  240. m_ilSize = m_ppropCompression->m_dwDirectorySize / DS_UNITS;
  241. }
  242. }
  243. else if (err.Win32Error() == ERROR_PATH_NOT_FOUND)
  244. {
  245. //
  246. // Fail quietly
  247. //
  248. TRACEEOLID("No compression filters installed");
  249. err.Reset();
  250. }
  251. }
  252. else
  253. {
  254. err = ERROR_NOT_ENOUGH_MEMORY;
  255. }
  256. return err;
  257. }
  258. HRESULT
  259. CDefWebSitePage::SaveInfo()
  260. /*++
  261. Routine Description:
  262. Save the information on this property page
  263. Arguments:
  264. None
  265. Return Value:
  266. Error return code
  267. --*/
  268. {
  269. ASSERT(IsDirty());
  270. TRACEEOLID("Saving W3 default web site page now...");
  271. CError err;
  272. BeginWaitCursor();
  273. //
  274. // Write Compression parms as well.
  275. //
  276. if (err.Succeeded() && HasCompression())
  277. {
  278. ASSERT(m_ppropCompression);
  279. DWORD dwSize = m_ilSize * DS_UNITS;
  280. m_ppropCompression->m_fEnableDynamicCompression = m_fEnableDynamic;
  281. m_ppropCompression->m_fEnableStaticCompression = m_fEnableStatic;
  282. m_ppropCompression->m_fLimitDirectorySize = m_fEnableLimiting;
  283. m_ppropCompression->m_strDirectory = m_strDirectory;
  284. m_ppropCompression->m_dwDirectorySize = dwSize;
  285. err = m_ppropCompression->WriteDirtyProps();
  286. }
  287. EndWaitCursor();
  288. if (err.Succeeded())
  289. {
  290. m_fCompressionDirectoryChanged = FALSE;
  291. }
  292. return err;
  293. }
  294. //
  295. // Message Handlers
  296. //
  297. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  298. BOOL
  299. CDefWebSitePage::OnInitDialog()
  300. /*++
  301. Routine Description:
  302. WM_INITDIALOG handler. Initialize the dialog.
  303. Arguments:
  304. None.
  305. Return Value:
  306. TRUE if focus is to be set automatically, FALSE if the focus
  307. is already set.
  308. --*/
  309. {
  310. CInetPropertyPage::OnInitDialog();
  311. //
  312. // Check to make sure compression is supported
  313. //
  314. for (UINT n = IDC_COMPRESS_FLAGS_FIRST; n <= IDC_COMPRESS_FLAGS_LAST; ++n)
  315. {
  316. GetDlgItem(n)->EnableWindow(HasCompression());
  317. }
  318. SetControlStates();
  319. return TRUE;
  320. }
  321. void
  322. CDefWebSitePage::OnItemChanged()
  323. /*++
  324. Routine Description:
  325. Handle change in control data
  326. Arguments:
  327. None
  328. Return Value:
  329. None
  330. --*/
  331. {
  332. SetModified(TRUE);
  333. SetControlStates();
  334. }
  335. void
  336. CDefWebSitePage::OnButtonBrowse()
  337. /*++
  338. Routine Description:
  339. "Browse" button handler
  340. Arguments:
  341. None
  342. Return Value:
  343. None
  344. --*/
  345. {
  346. ASSERT(IsLocal());
  347. CString str;
  348. m_edit_Directory.GetWindowText(str);
  349. CDirBrowseDlg dlgBrowse(this, str);
  350. if (dlgBrowse.DoModal() == IDOK)
  351. {
  352. m_edit_Directory.SetWindowText(dlgBrowse.GetFullPath(str));
  353. OnItemChanged();
  354. }
  355. }
  356. void
  357. CDefWebSitePage::OnChangeEditCompressDirectory()
  358. /*++
  359. Routine Description:
  360. Handle change in compression directory edit box.
  361. Arguments:
  362. None
  363. Return Value:
  364. None
  365. --*/
  366. {
  367. m_fCompressionDirectoryChanged = TRUE;
  368. OnItemChanged();
  369. }
  370. void
  371. CDefWebSitePage::OnRadioLimited()
  372. /*++
  373. Routine Description:
  374. 'Limited' radio button handler
  375. Arguments:
  376. None
  377. Return Value:
  378. None
  379. --*/
  380. {
  381. if (!m_fEnableLimiting)
  382. {
  383. m_nUnlimited = RADIO_LIMITED;
  384. m_fEnableLimiting = TRUE;
  385. OnItemChanged();
  386. m_edit_DirectorySize.SetSel(0, -1);
  387. m_edit_DirectorySize.SetFocus();
  388. }
  389. }
  390. void
  391. CDefWebSitePage::OnRadioUnlimited()
  392. /*++
  393. Routine Description:
  394. 'Unlimited' radio button handler
  395. Arguments:
  396. None
  397. Return Value:
  398. None
  399. --*/
  400. {
  401. if (m_fEnableLimiting)
  402. {
  403. m_nUnlimited = RADIO_UNLIMITED;
  404. m_fEnableLimiting = FALSE;
  405. OnItemChanged();
  406. }
  407. }
  408. void
  409. CDefWebSitePage::OnCheckDynamicCompression()
  410. /*++
  411. Routine Description:
  412. "Enable Dynamic Compression' checkbox handler
  413. Arguments:
  414. None
  415. Return Value:
  416. None
  417. --*/
  418. {
  419. m_fEnableDynamic = !m_fEnableDynamic;
  420. OnItemChanged();
  421. }
  422. void
  423. CDefWebSitePage::OnCheckStaticCompression()
  424. /*++
  425. Routine Description:
  426. "Enable Dynamic Compression' checkbox handler
  427. Arguments:
  428. None
  429. Return Value:
  430. None
  431. --*/
  432. {
  433. m_fEnableStatic = !m_fEnableStatic;
  434. OnItemChanged();
  435. if (m_fEnableStatic)
  436. {
  437. m_edit_Directory.SetSel(0, -1);
  438. m_edit_Directory.SetFocus();
  439. }
  440. }
  441. void
  442. CDefWebSitePage::OnDestroy()
  443. /*++
  444. Routine Description:
  445. WM_DESTROY handler. Clean up internal data
  446. Arguments:
  447. None
  448. Return Value:
  449. None
  450. --*/
  451. {
  452. CInetPropertyPage::OnDestroy();
  453. SAFE_DELETE(m_ppropCompression);
  454. }