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.

680 lines
19 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. cacheopt.cpp
  5. Abstract:
  6. ASP Cache options page
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include <aclapi.h>
  15. #include "CacheOpt.h"
  16. #define TOTAL_CACHE_DEFAULT 1000
  17. #define IIS5_CACHE_DEFAULT 250
  18. LRESULT
  19. CCacheOptPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  20. {
  21. if (NULL == m_pData)
  22. {
  23. ASSERT(FALSE);
  24. ::EndDialog(hDlg, 0);
  25. return -1;
  26. }
  27. m_bInitDone = FALSE;
  28. // Set defaults for disabled controls
  29. if (m_pData->m_NoCache)
  30. {
  31. m_pData->m_TotalCacheSize = TOTAL_CACHE_DEFAULT;
  32. m_pData->m_LimCacheInMemorySize = 250;
  33. m_pData->m_UnlimCacheInMemorySize = 250;
  34. }
  35. else if (m_pData->m_UnlimCache)
  36. {
  37. m_pData->m_TotalCacheSize = TOTAL_CACHE_DEFAULT;
  38. m_pData->m_LimCacheInMemorySize = 250;
  39. }
  40. else if (m_pData->m_LimCache)
  41. {
  42. m_pData->m_UnlimCacheInMemorySize = 250;
  43. }
  44. DoDataExchange();
  45. m_FileChooser.Init(this, m_pData->IsLocal() ? FC_DIRECTORY_ONLY | FC_FORWRITE : 0,
  46. IDC_CACHE_PATH, IDC_BROWSE);
  47. CString title;
  48. if (title.LoadString(_Module.GetResourceInstance(), IDS_SELECT_CACHE_PATH))
  49. m_FileChooser.SetDialogTitle(title);
  50. m_FileChooser.SetPath(m_pData->m_DiskCacheDir);
  51. ::EnableWindow(GetDlgItem(IDC_BROWSE), m_pData->IsLocal());
  52. UDACCEL toAcc[3] = {{1, 1}, {3, 5}, {6, 10}};
  53. m_eng_cache.SetRange32(SCRIPT_ENG_MIN, SCRIPT_ENG_MAX);
  54. m_eng_cache.SetPos32(m_pData->m_ScriptEngCacheMax);
  55. m_eng_cache.SetAccel(3, toAcc);
  56. m_cache_size.SetRange32(CACHE_SIZE_MIN, CACHE_SIZE_MAX);
  57. m_cache_size.SetPos32(m_pData->m_TotalCacheSize);
  58. m_cache_size.SetAccel(3, toAcc);
  59. m_inmem_unlim.SetRange32(0, m_pData->m_TotalCacheSize);
  60. m_inmem_unlim.SetPos32(m_pData->m_UnlimCacheInMemorySize);
  61. m_inmem_unlim.SetAccel(3, toAcc);
  62. m_inmem_lim.SetRange32(0, m_pData->m_TotalCacheSize);
  63. m_inmem_lim.SetPos32(m_pData->m_LimCacheInMemorySize);
  64. m_inmem_lim.SetAccel(3, toAcc);
  65. UINT id = IDC_UNLIMITED_CACHE;
  66. if (m_pData->m_NoCache)
  67. id = IDC_NO_CACHE;
  68. else if (m_pData->m_LimCache)
  69. id = IDC_LIMITED_CACHE;
  70. OnCacheSwitch(0, id, NULL);
  71. AdjustTracker();
  72. DoDataExchange();
  73. m_bInitDone = TRUE;
  74. return FALSE;
  75. };
  76. BOOL
  77. CCacheOptPage::OnKillActive()
  78. {
  79. HRESULT hr = S_OK;
  80. if (m_bInitDone)
  81. {
  82. if (!DoDataExchange(TRUE))
  83. return FALSE;
  84. hr = m_pData->Save();
  85. if (m_pData->m_LimCache)
  86. {
  87. if (m_pData->m_LimCacheInMemorySize > m_pData->m_TotalCacheSize)
  88. {
  89. ::SetFocus(GetDlgItem(IDC_INMEM_LIM_EDIT));
  90. return FALSE;
  91. }
  92. }
  93. CString buf;
  94. DWORD rc;
  95. if (FC_SUCCESS != (rc = m_FileChooser.GetFileName(buf)))
  96. {
  97. DWORD id;
  98. if (rc == FC_TEXT_IS_INVALID)
  99. {
  100. id = ERROR_DIRECTORY;
  101. }
  102. else if (m_pData->IsLocal() && FC_FILE_DOES_NOT_EXIST == rc)
  103. {
  104. id = ERROR_PATH_NOT_FOUND;
  105. }
  106. CError err(id);
  107. err.MessageBox(MB_OK);
  108. ::SetFocus(GetDlgItem(IDC_CACHE_PATH));
  109. SendDlgItemMessage(IDC_CACHE_PATH, EM_SETSEL, 0, -1);
  110. return FALSE;
  111. }
  112. if (m_pData->IsLocal())
  113. {
  114. TCHAR expanded[MAX_PATH];
  115. ExpandEnvironmentStrings(buf, expanded, MAX_PATH);
  116. buf = expanded;
  117. DWORD attr = ::GetFileAttributes(buf);
  118. if (-1 == (int)attr)
  119. {
  120. CError err(GetLastError());
  121. err.MessageBox(MB_OK);
  122. ::SetFocus(GetDlgItem(IDC_CACHE_PATH));
  123. SendDlgItemMessage(IDC_CACHE_PATH, EM_SETSEL, 0, -1);
  124. return FALSE;
  125. }
  126. if ( (attr & FILE_ATTRIBUTE_READONLY) != 0
  127. || (attr & FILE_ATTRIBUTE_DIRECTORY) == 0
  128. || PathIsNetworkPath(buf)
  129. )
  130. {
  131. CString cap, msg;
  132. cap.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  133. msg.LoadString(_Module.GetResourceInstance(), IDS_READ_ONLY_DIRECTORY);
  134. SendDlgItemMessage(IDC_CACHE_PATH, EM_SETSEL, 0, -1);
  135. MessageBox(msg, cap);
  136. ::SetFocus(GetDlgItem(IDC_CACHE_PATH));
  137. return FALSE;
  138. }
  139. }
  140. #if 0
  141. // Andy will do this during startup. It is impossible to do in remote case.
  142. // Setup access permissions for the directory
  143. CWaitCursor clock;
  144. EXPLICIT_ACCESS ea[3];
  145. PACL pNewDACL = NULL;
  146. CString strWamIdentity;
  147. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  148. // go get the IWAM account name from the metabase
  149. CMetabasePath w3svc(TRUE, SZ_MBN_WEB);
  150. CComAuthInfo auth(m_pData->m_ServerName,
  151. m_pData->m_UserName, m_pData->m_UserPassword);
  152. CMetaKey mk(&auth, w3svc, METADATA_PERMISSION_READ);
  153. if (!mk.Succeeded() || FAILED(hr = mk.QueryValue(MD_WAM_USER_NAME, strWamIdentity)))
  154. {
  155. return FALSE;
  156. }
  157. ZeroMemory(ea, sizeof(EXPLICIT_ACCESSA) * 3);
  158. ea[0].grfAccessPermissions = SYNCHRONIZE | GENERIC_ALL;
  159. ea[0].grfAccessMode = GRANT_ACCESS;
  160. ea[0].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  161. ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  162. ea[1].grfAccessPermissions = SYNCHRONIZE | GENERIC_ALL;
  163. ea[1].grfAccessMode = GRANT_ACCESS;
  164. ea[1].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  165. ea[1].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
  166. ea[1].Trustee.ptstrName = (LPTSTR)(LPCTSTR)strWamIdentity;
  167. ea[2].grfAccessPermissions = SYNCHRONIZE | GENERIC_ALL;
  168. ea[2].grfAccessMode = GRANT_ACCESS;
  169. ea[2].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;
  170. ea[2].Trustee.TrusteeForm = TRUSTEE_IS_SID;
  171. // build the new DACL with just these ACEs
  172. if (!AllocateAndInitializeSid(&NtAuthority,
  173. 1,
  174. SECURITY_LOCAL_SYSTEM_RID,
  175. 0,0,0,0,0,0,0,
  176. (PSID *)(&ea[0].Trustee.ptstrName)))
  177. hr = HRESULT_FROM_WIN32(GetLastError());
  178. else if (!AllocateAndInitializeSid(&NtAuthority,
  179. 2, // 2 sub-authorities
  180. SECURITY_BUILTIN_DOMAIN_RID,
  181. DOMAIN_ALIAS_RID_ADMINS,
  182. 0,0,0,0,0,0,
  183. (PSID *)(&ea[2].Trustee.ptstrName)))
  184. hr = HRESULT_FROM_WIN32(GetLastError());
  185. else if ((hr = SetEntriesInAcl(3, ea, NULL, &pNewDACL)) != ERROR_SUCCESS);
  186. // set the ACL on the directory
  187. else hr = SetNamedSecurityInfo((LPTSTR)(LPCTSTR)buf,
  188. SE_FILE_OBJECT,
  189. DACL_SECURITY_INFORMATION | PROTECTED_DACL_SECURITY_INFORMATION,
  190. NULL,
  191. NULL,
  192. pNewDACL,
  193. NULL);
  194. if (pNewDACL)
  195. LocalFree(pNewDACL);
  196. if (ea[0].Trustee.ptstrName)
  197. FreeSid(ea[0].Trustee.ptstrName);
  198. if (ea[2].Trustee.ptstrName)
  199. FreeSid(ea[2].Trustee.ptstrName);
  200. #endif
  201. if (SUCCEEDED(hr))
  202. {
  203. StrCpy(m_pData->m_DiskCacheDir, buf);
  204. }
  205. }
  206. return SUCCEEDED(hr);
  207. }
  208. void
  209. CCacheOptPage::OnCacheSwitch(UINT, UINT nID, HWND)
  210. {
  211. switch (nID)
  212. {
  213. case IDC_NO_CACHE:
  214. m_pData->m_NoCache = TRUE;
  215. m_pData->m_UnlimCache = FALSE;
  216. m_pData->m_LimCache = FALSE;
  217. break;
  218. case IDC_UNLIMITED_CACHE:
  219. m_pData->m_NoCache = FALSE;
  220. m_pData->m_UnlimCache = TRUE;
  221. m_pData->m_LimCache = FALSE;
  222. break;
  223. case IDC_LIMITED_CACHE:
  224. // When cache is unlimited or disabled, total size is set to -1,
  225. // reset it to reasonable default here
  226. // if (m_pData->m_TotalCacheSize >= CACHE_UNLIM_MAX)
  227. // {
  228. {
  229. // m_pData->m_TotalCacheSize =
  230. // __max(m_pData->m_LimCacheInMemorySize, TOTAL_CACHE_DEFAULT);
  231. // DoDataExchange(FALSE, IDC_CACHE_SIZE_EDIT);
  232. // }
  233. }
  234. m_pData->m_NoCache = FALSE;
  235. m_pData->m_UnlimCache = FALSE;
  236. m_pData->m_LimCache = TRUE;
  237. break;
  238. }
  239. m_NoCacheBtn.SetCheck(m_pData->m_NoCache);
  240. m_UnlimCacheBtn.SetCheck(m_pData->m_UnlimCache);
  241. m_LimCacheBtn.SetCheck(m_pData->m_LimCache);
  242. m_inmem_unlim.EnableWindow(m_pData->m_UnlimCache);
  243. ::EnableWindow(GetDlgItem(IDC_INMEM_UNLIM_EDIT), m_pData->m_UnlimCache);
  244. m_inmem_lim.EnableWindow(m_pData->m_LimCache);
  245. ::EnableWindow(GetDlgItem(IDC_INMEM_LIM_EDIT), m_pData->m_LimCache);
  246. m_cache_size.EnableWindow(m_pData->m_LimCache);
  247. ::EnableWindow(GetDlgItem(IDC_CACHE_SIZE_EDIT), m_pData->m_LimCache);
  248. m_cache_dist.EnableWindow(m_pData->m_LimCache);
  249. SET_MODIFIED(TRUE);
  250. }
  251. void
  252. CCacheOptPage::OnChangeCacheSize(UINT nCode, UINT nID, HWND)
  253. {
  254. if (::IsWindow(m_cache_dist.m_hWnd) && m_bInitDone)
  255. {
  256. // DoDataExchange(TRUE, IDC_CACHE_SIZE_EDIT);
  257. // DoDataExchange(TRUE, IDC_INMEM_LIM_EDIT);
  258. // DoDataExchange is not suitable here -- it will call OnDataExchange error internally
  259. // and will immediately produce annoying popup
  260. BOOL translated;
  261. m_pData->m_TotalCacheSize = GetDlgItemInt(IDC_CACHE_SIZE_EDIT, &translated, FALSE);
  262. m_pData->m_LimCacheInMemorySize = GetDlgItemInt(IDC_INMEM_LIM_EDIT, &translated, FALSE);
  263. m_inmem_lim.SetRange32(0, m_pData->m_TotalCacheSize);
  264. if (m_pData->m_LimCacheInMemorySize > m_pData->m_TotalCacheSize)
  265. {
  266. // If in-memory limit is currently higher than total, set it to total
  267. m_pData->m_LimCacheInMemorySize = m_pData->m_TotalCacheSize;
  268. DoDataExchange(FALSE, IDC_INMEM_LIM_EDIT);
  269. m_inmem_lim.SetPos32(m_pData->m_LimCacheInMemorySize);
  270. }
  271. AdjustTracker();
  272. // Here we could adjust in memory size to be less or equal to the total size,
  273. // but I decided that it could be annoying: what if user deleted last zero
  274. // in total size control, and in memory size turned to be larger than total size.
  275. // We immediately will cut it to total, and to fix this mistake user will need
  276. // to touch two places. It will be too bad.
  277. SET_MODIFIED(TRUE);
  278. }
  279. }
  280. void
  281. CCacheOptPage::OnChangeInmemCacheSize(UINT nCode, UINT nID, HWND)
  282. {
  283. if (::IsWindow(m_cache_dist.m_hWnd) && m_bInitDone)
  284. {
  285. // DoDataExchange(TRUE, nID);
  286. // DoDataExchange is not suitable here -- it will call OnDataExchange error internally
  287. // and will immediately produce annoying popup
  288. BOOL translated;
  289. m_pData->m_LimCacheInMemorySize = GetDlgItemInt(IDC_INMEM_LIM_EDIT, &translated, FALSE);
  290. AdjustTracker();
  291. SET_MODIFIED(TRUE);
  292. }
  293. }
  294. void
  295. CCacheOptPage::OnTrackBarScroll(UINT nSBCode, UINT nPos, HWND hwnd)
  296. {
  297. BOOL bChange = FALSE;
  298. int endval;
  299. switch (nSBCode)
  300. {
  301. case SB_THUMBPOSITION:
  302. if (nPos > m_pData->m_LimCacheInMemorySize)
  303. {
  304. m_pData->m_LimCacheInMemorySize = min(nPos, m_pData->m_TotalCacheSize);
  305. }
  306. else if (nPos < m_pData->m_LimCacheInMemorySize)
  307. {
  308. m_pData->m_LimCacheInMemorySize = max(nPos, 0);
  309. }
  310. else
  311. {
  312. m_pData->m_LimCacheInMemorySize = nPos;
  313. }
  314. bChange = TRUE;
  315. break;
  316. case SB_LINELEFT:
  317. endval = m_pData->m_LimCacheInMemorySize - m_cache_dist.GetLineSize();
  318. if (endval >= 0)
  319. {
  320. m_pData->m_LimCacheInMemorySize = endval;
  321. bChange = TRUE;
  322. }
  323. else
  324. {
  325. bChange = m_pData->m_LimCacheInMemorySize != 0;
  326. m_pData->m_LimCacheInMemorySize = 0;
  327. }
  328. break;
  329. case SB_LINERIGHT:
  330. endval = m_pData->m_LimCacheInMemorySize + m_cache_dist.GetLineSize();
  331. if (endval <= m_pData->m_TotalCacheSize)
  332. {
  333. m_pData->m_LimCacheInMemorySize = endval;
  334. bChange = TRUE;
  335. }
  336. else
  337. {
  338. bChange = m_pData->m_LimCacheInMemorySize != m_pData->m_TotalCacheSize;
  339. m_pData->m_LimCacheInMemorySize = m_pData->m_TotalCacheSize;
  340. }
  341. break;
  342. case SB_PAGELEFT:
  343. endval = m_pData->m_LimCacheInMemorySize - m_cache_dist.GetPageSize();
  344. if (endval >= 0)
  345. {
  346. m_pData->m_LimCacheInMemorySize = endval;
  347. bChange = TRUE;
  348. }
  349. else
  350. {
  351. bChange = m_pData->m_LimCacheInMemorySize != 0;
  352. m_pData->m_LimCacheInMemorySize = 0;
  353. }
  354. break;
  355. case SB_PAGERIGHT:
  356. endval = m_pData->m_LimCacheInMemorySize + m_cache_dist.GetPageSize();
  357. if (endval <= m_pData->m_TotalCacheSize)
  358. {
  359. m_pData->m_LimCacheInMemorySize = endval;
  360. bChange = TRUE;
  361. }
  362. else
  363. {
  364. bChange = m_pData->m_LimCacheInMemorySize != m_pData->m_TotalCacheSize;
  365. m_pData->m_LimCacheInMemorySize = m_pData->m_TotalCacheSize;
  366. }
  367. break;
  368. case SB_LEFT:
  369. bChange = m_pData->m_LimCacheInMemorySize != 0;
  370. m_pData->m_LimCacheInMemorySize = 0;
  371. break;
  372. case SB_RIGHT:
  373. bChange = m_pData->m_LimCacheInMemorySize != m_pData->m_TotalCacheSize;
  374. m_pData->m_LimCacheInMemorySize = m_pData->m_TotalCacheSize;
  375. break;
  376. case SB_THUMBTRACK:
  377. case SB_ENDSCROLL:
  378. break;
  379. }
  380. if (bChange)
  381. {
  382. DoDataExchange(FALSE, IDC_INMEM_LIM_EDIT);
  383. SET_MODIFIED(TRUE);
  384. }
  385. }
  386. void
  387. CCacheOptPage::AdjustTracker()
  388. {
  389. if (::IsWindow(m_cache_dist.m_hWnd))
  390. {
  391. m_cache_dist.SetRange(0, m_pData->m_TotalCacheSize, TRUE);
  392. m_cache_dist.SetPos(m_pData->m_LimCacheInMemorySize);
  393. m_cache_dist.SetPageSize(m_pData->m_TotalCacheSize / 10);
  394. m_cache_dist.SetLineSize(m_pData->m_TotalCacheSize / 25);
  395. m_cache_dist.SetTicFreq(m_pData->m_TotalCacheSize / 25);
  396. }
  397. }
  398. void
  399. CCacheOptPage::OnChangePath(UINT nCode, UINT nID, HWND hWnd)
  400. {
  401. m_FileChooser.OnEditChange();
  402. CString buf;
  403. DWORD rc;
  404. if (FC_SUCCESS != (rc = m_FileChooser.GetFileName(buf)))
  405. {
  406. ::EnableWindow(m_pData->m_pSheet->GetDlgItem(IDOK), FALSE);
  407. SET_MODIFIED(FALSE);
  408. }
  409. else
  410. {
  411. ::EnableWindow(m_pData->m_pSheet->GetDlgItem(IDOK), TRUE);
  412. OnChangeData(nCode, nID, hWnd);
  413. }
  414. }
  415. void
  416. CCacheOptPage::OnDataValidateError(UINT id, BOOL bSave,_XData& data)
  417. {
  418. if (bSave)
  419. {
  420. CString str, fmt, caption;
  421. caption.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  422. switch (data.nDataType)
  423. {
  424. case ddxDataText:
  425. break;
  426. case ddxDataNull:
  427. break;
  428. case ddxDataInt:
  429. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  430. str.Format(fmt, data.intData.nMin, data.intData.nMax);
  431. break;
  432. }
  433. if (!str.IsEmpty())
  434. {
  435. MessageBox(str, caption, MB_OK | MB_ICONEXCLAMATION);
  436. ::SetFocus(GetDlgItem(id));
  437. }
  438. }
  439. }
  440. void
  441. CCacheOptPage::OnDataExchangeError(UINT nCtrlID, BOOL bSave)
  442. {
  443. if (bSave)
  444. {
  445. CString str, fmt, caption;
  446. int min, max;
  447. caption.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  448. switch (nCtrlID)
  449. {
  450. case IDC_CACHE_SIZE_EDIT:
  451. case IDC_INMEM_UNLIM_EDIT:
  452. min = CACHE_SIZE_MIN;
  453. max = CACHE_SIZE_MAX;
  454. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  455. break;
  456. case IDC_INMEM_LIM_EDIT:
  457. min = CACHE_SIZE_MIN;
  458. max = m_pData->m_TotalCacheSize;
  459. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  460. break;
  461. case IDC_ENGINES:
  462. min = SCRIPT_ENG_MIN;
  463. max = SCRIPT_ENG_MAX;
  464. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  465. break;
  466. default:
  467. str.LoadString(_Module.GetResourceInstance(), IDS_ERR_INVALID_DATA);
  468. break;
  469. }
  470. if (!fmt.IsEmpty())
  471. {
  472. str.Format(fmt, min, max);
  473. }
  474. MessageBox(str, caption, MB_OK | MB_ICONEXCLAMATION);
  475. ::SetFocus(GetDlgItem(nCtrlID));
  476. }
  477. }
  478. void
  479. CCacheOptPage::OnHelp()
  480. {
  481. WinHelp(m_pData->m_HelpPath, HELP_CONTEXT, CCacheOptPage::IDD + WINHELP_NUMBER_BASE);
  482. }
  483. ////////////////////////////////////////////////////////////////////////////
  484. LRESULT
  485. CCacheOptPage_iis5::OnInitDialog(HWND hDlg, LPARAM lParam)
  486. {
  487. if (NULL == m_pData)
  488. {
  489. ASSERT(FALSE);
  490. ::EndDialog(hDlg, 0);
  491. return -1;
  492. }
  493. m_bInitDone = FALSE;
  494. DoDataExchange();
  495. UDACCEL toAcc[3] = {{1, 1}, {3, 5}, {6, 10}};
  496. m_eng_cache.SetRange32(SCRIPT_ENG_MIN, SCRIPT_ENG_MAX);
  497. m_eng_cache.SetPos32(m_pData->m_ScriptEngCacheMax);
  498. m_eng_cache.SetAccel(3, toAcc);
  499. m_inmem_lim.SetRange32(CACHE_SIZE_MIN, CACHE_SIZE_MAX);
  500. m_inmem_lim.SetPos32(m_pData->m_LimCacheInMemorySize);
  501. m_inmem_lim.SetAccel(3, toAcc);
  502. UINT id = IDC_UNLIMITED_CACHE;
  503. if (m_pData->m_NoCache)
  504. id = IDC_NO_CACHE;
  505. else if (m_pData->m_LimCache)
  506. id = IDC_LIMITED_CACHE;
  507. OnCacheSwitch(0, id, NULL);
  508. DoDataExchange();
  509. m_bInitDone = TRUE;
  510. return FALSE;
  511. };
  512. BOOL
  513. CCacheOptPage_iis5::OnKillActive()
  514. {
  515. HRESULT hr = S_OK;
  516. if (m_bInitDone)
  517. {
  518. if (!DoDataExchange(TRUE))
  519. return FALSE;
  520. hr = m_pData->Save();
  521. }
  522. return SUCCEEDED(hr);
  523. }
  524. void
  525. CCacheOptPage_iis5::OnCacheSwitch(UINT, UINT nID, HWND)
  526. {
  527. switch (nID)
  528. {
  529. case IDC_NO_CACHE:
  530. m_pData->m_NoCache = TRUE;
  531. m_pData->m_UnlimCache = FALSE;
  532. m_pData->m_LimCache = FALSE;
  533. break;
  534. case IDC_UNLIMITED_CACHE:
  535. m_pData->m_NoCache = FALSE;
  536. m_pData->m_UnlimCache = TRUE;
  537. m_pData->m_LimCache = FALSE;
  538. break;
  539. case IDC_LIMITED_CACHE:
  540. // When cache is unlimited or disabled, size is set to -1,
  541. // reset it to reasonable default here
  542. if (m_pData->m_LimCacheInMemorySize == -1)
  543. {
  544. m_pData->m_LimCacheInMemorySize = IIS5_CACHE_DEFAULT;
  545. DoDataExchange(FALSE, IDC_CACHE_SIZE_EDIT);
  546. }
  547. m_pData->m_NoCache = FALSE;
  548. m_pData->m_UnlimCache = FALSE;
  549. m_pData->m_LimCache = TRUE;
  550. break;
  551. }
  552. m_NoCacheBtn.SetCheck(m_pData->m_NoCache);
  553. m_UnlimCacheBtn.SetCheck(m_pData->m_UnlimCache);
  554. m_LimCacheBtn.SetCheck(m_pData->m_LimCache);
  555. m_inmem_lim.EnableWindow(m_pData->m_LimCache);
  556. ::EnableWindow(GetDlgItem(IDC_CACHE_SIZE_EDIT), m_pData->m_LimCache);
  557. SET_MODIFIED(TRUE);
  558. }
  559. void
  560. CCacheOptPage_iis5::OnDataValidateError(UINT id, BOOL bSave,_XData& data)
  561. {
  562. if (bSave)
  563. {
  564. CString str, fmt, caption;
  565. caption.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  566. switch (data.nDataType)
  567. {
  568. case ddxDataText:
  569. break;
  570. case ddxDataNull:
  571. break;
  572. case ddxDataInt:
  573. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  574. str.Format(fmt, data.intData.nMin, data.intData.nMax);
  575. break;
  576. }
  577. if (!str.IsEmpty())
  578. {
  579. MessageBox(str, caption, MB_OK | MB_ICONEXCLAMATION);
  580. ::SetFocus(GetDlgItem(id));
  581. }
  582. }
  583. }
  584. void
  585. CCacheOptPage_iis5::OnDataExchangeError(UINT nCtrlID, BOOL bSave)
  586. {
  587. if (bSave)
  588. {
  589. CString str, fmt, caption;
  590. int min, max;
  591. caption.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  592. fmt.LoadString(_Module.GetResourceInstance(), IDS_ERR_INT_RANGE);
  593. switch (nCtrlID)
  594. {
  595. case IDC_CACHE_SIZE_EDIT:
  596. min = CACHE_SIZE_MIN;
  597. max = CACHE_SIZE_MAX;
  598. break;
  599. case IDC_ENGINES:
  600. min = SCRIPT_ENG_MIN;
  601. max = SCRIPT_ENG_MAX;
  602. break;
  603. default:
  604. break;
  605. }
  606. str.Format(fmt, min, max);
  607. MessageBox(str, caption, MB_OK | MB_ICONEXCLAMATION);
  608. ::SetFocus(GetDlgItem(nCtrlID));
  609. }
  610. }
  611. void
  612. CCacheOptPage_iis5::OnHelp()
  613. {
  614. WinHelp(m_pData->m_HelpPath, HELP_CONTEXT, CCacheOptPage::IDD + WINHELP_NUMBER_BASE);
  615. }