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.

517 lines
12 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. wfile.cpp
  5. Abstract:
  6. WWW File Properties Page
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. 27/02/2001 sergeia Created from wvdir.cpp
  13. --*/
  14. //
  15. // Include Files
  16. //
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "common.h"
  20. #include "inetprop.h"
  21. #include "InetMgrApp.h"
  22. #include "supdlgs.h"
  23. #include "shts.h"
  24. #include "w3sht.h"
  25. #include "wfile.h"
  26. #include "dirbrows.h"
  27. #include "iisobj.h"
  28. #include <lmcons.h>
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. LPCTSTR CvtPathToDosStyle(CString & strPath);
  35. IMPLEMENT_DYNCREATE(CW3FilePage, CInetPropertyPage)
  36. CW3FilePage::CW3FilePage(CInetPropertySheet * pSheet)
  37. : CInetPropertyPage(CW3FilePage::IDD, pSheet, IDS_TAB_FILE),
  38. //
  39. // Assign the range of bits in m_dwAccessPermissions that
  40. // we manage. This is important, because another page
  41. // manages other bits, and we don't want to screw up
  42. // the master value bits when our changes collide (it
  43. // will mark the original bits as dirty, because we're not
  44. // notified when the change is made...
  45. //
  46. m_dwBitRangePermissions(MD_ACCESS_EXECUTE |
  47. MD_ACCESS_SCRIPT |
  48. MD_ACCESS_WRITE |
  49. MD_ACCESS_SOURCE |
  50. MD_ACCESS_READ)
  51. {
  52. VERIFY(m_strPrompt[RADIO_DIRECTORY].LoadString(IDS_PROMPT_DIR));
  53. VERIFY(m_strPrompt[RADIO_REDIRECT].LoadString(IDS_PROMPT_REDIRECT));
  54. }
  55. CW3FilePage::~CW3FilePage()
  56. {
  57. }
  58. void
  59. CW3FilePage::DoDataExchange(CDataExchange * pDX)
  60. {
  61. CInetPropertyPage::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CW3FilePage)
  63. // DDX_Radio(pDX, IDC_RADIO_DIR, m_nPathType);
  64. DDX_Control(pDX, IDC_RADIO_DIR, m_radio_Dir);
  65. DDX_Control(pDX, IDC_RADIO_REDIRECT, m_radio_Redirect);
  66. DDX_Check(pDX, IDC_CHECK_AUTHOR, m_fAuthor);
  67. DDX_Control(pDX, IDC_CHECK_AUTHOR, m_check_Author);
  68. DDX_Check(pDX, IDC_CHECK_READ, m_fRead);
  69. DDX_Control(pDX, IDC_CHECK_READ, m_check_Read);
  70. DDX_Check(pDX, IDC_CHECK_WRITE, m_fWrite);
  71. DDX_Control(pDX, IDC_CHECK_WRITE, m_check_Write);
  72. DDX_Check(pDX, IDC_CHECK_LOG_ACCESS, m_fLogAccess);
  73. DDX_Control(pDX, IDC_EDIT_PATH, m_edit_Path);
  74. DDX_Control(pDX, IDC_EDIT_REDIRECT, m_edit_Redirect);
  75. DDX_Control(pDX, IDC_STATIC_PATH_PROMPT, m_static_PathPrompt);
  76. // DDX_Control(pDX, IDC_CHECK_CHILD, m_check_Child);
  77. //}}AFX_DATA_MAP
  78. // DDX_Check(pDX, IDC_CHECK_CHILD, m_fChild);
  79. DDX_Check(pDX, IDC_CHECK_EXACT, m_fExact);
  80. DDX_Check(pDX, IDC_CHECK_PERMANENT, m_fPermanent);
  81. if (pDX->m_bSaveAndValidate)
  82. {
  83. if (m_nPathType == RADIO_REDIRECT)
  84. {
  85. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  86. m_strRedirectPath.TrimLeft();
  87. DDV_MinMaxChars(pDX, m_strRedirectPath, 0, 2 * MAX_PATH);
  88. if (!IsRelURLPath(m_strRedirectPath)
  89. && !IsWildcardedRedirectPath(m_strRedirectPath)
  90. && !IsURLName(m_strRedirectPath))
  91. {
  92. ::AfxMessageBox(IDS_BAD_URL_PATH);
  93. pDX->Fail();
  94. }
  95. }
  96. else // Local directory
  97. {
  98. m_strRedirectPath.Empty();
  99. }
  100. }
  101. else
  102. {
  103. DDX_Text(pDX, IDC_EDIT_REDIRECT, m_strRedirectPath);
  104. }
  105. }
  106. //
  107. // Message Map
  108. //
  109. BEGIN_MESSAGE_MAP(CW3FilePage, CInetPropertyPage)
  110. //{{AFX_MSG_MAP(CW3FilePage)
  111. ON_BN_CLICKED(IDC_CHECK_READ, OnCheckRead)
  112. ON_BN_CLICKED(IDC_CHECK_WRITE, OnCheckWrite)
  113. ON_BN_CLICKED(IDC_CHECK_AUTHOR, OnCheckAuthor)
  114. ON_BN_CLICKED(IDC_RADIO_DIR, OnRadioDir)
  115. ON_BN_CLICKED(IDC_RADIO_REDIRECT, OnRadioRedirect)
  116. //}}AFX_MSG_MAP
  117. ON_EN_CHANGE(IDC_EDIT_REDIRECT, OnItemChanged)
  118. ON_BN_CLICKED(IDC_CHECK_LOG_ACCESS, OnItemChanged)
  119. // ON_BN_CLICKED(IDC_CHECK_CHILD, OnItemChanged)
  120. ON_BN_CLICKED(IDC_CHECK_EXACT, OnItemChanged)
  121. ON_BN_CLICKED(IDC_CHECK_PERMANENT, OnItemChanged)
  122. END_MESSAGE_MAP()
  123. void
  124. CW3FilePage::ChangeTypeTo(int nNewType)
  125. {
  126. int nOldType = m_nPathType;
  127. m_nPathType = nNewType;
  128. if (nOldType == m_nPathType)
  129. {
  130. return;
  131. }
  132. OnItemChanged();
  133. SetStateByType();
  134. int nID = -1;
  135. CEdit * pPath = NULL;
  136. LPCTSTR lpKeepPath = NULL;
  137. switch(m_nPathType)
  138. {
  139. case RADIO_DIRECTORY:
  140. break;
  141. case RADIO_REDIRECT:
  142. if (!m_strRedirectPath.IsEmpty())
  143. {
  144. //
  145. // The old path info is acceptable, propose it
  146. // as a default
  147. //
  148. lpKeepPath = m_strRedirectPath;
  149. }
  150. nID = IDS_REDIRECT_MASK;
  151. pPath = &m_edit_Redirect;
  152. break;
  153. default:
  154. ASSERT(FALSE);
  155. return;
  156. }
  157. //
  158. // Load mask resource, and display
  159. // this in the directory
  160. //
  161. if (pPath != NULL)
  162. {
  163. if (lpKeepPath != NULL)
  164. {
  165. pPath->SetWindowText(lpKeepPath);
  166. }
  167. else
  168. {
  169. CString str;
  170. VERIFY(str.LoadString(nID));
  171. pPath->SetWindowText(str);
  172. }
  173. pPath->SetSel(0,-1);
  174. pPath->SetFocus();
  175. }
  176. }
  177. void
  178. CW3FilePage::ShowControl(CWnd * pWnd, BOOL fShow)
  179. {
  180. ASSERT(pWnd != NULL);
  181. pWnd->EnableWindow(fShow);
  182. pWnd->ShowWindow(fShow ? SW_SHOW : SW_HIDE);
  183. }
  184. void
  185. CW3FilePage::SetStateByType()
  186. /*++
  187. Routine Description:
  188. Set the state of the dialog by the path type currently selected
  189. Arguments:
  190. None
  191. Return Value:
  192. None
  193. --*/
  194. {
  195. BOOL fShowDirFlags;
  196. BOOL fShowRedirectFlags;
  197. BOOL fShowDAV;
  198. switch(m_nPathType)
  199. {
  200. case RADIO_DIRECTORY:
  201. ShowControl(&m_edit_Path, fShowDirFlags = TRUE);
  202. m_edit_Path.EnableWindow(FALSE);
  203. ShowControl(&m_edit_Redirect, fShowRedirectFlags = FALSE);
  204. fShowDAV = TRUE;
  205. break;
  206. case RADIO_REDIRECT:
  207. ShowControl(&m_edit_Path, fShowDirFlags = FALSE);
  208. ShowControl(&m_edit_Redirect, fShowRedirectFlags = TRUE);
  209. fShowDAV = FALSE;
  210. break;
  211. default:
  212. ASSERT(FALSE && "Invalid Selection");
  213. return;
  214. }
  215. ShowControl(GetDlgItem(IDC_CHECK_READ), fShowDirFlags);
  216. ShowControl(GetDlgItem(IDC_CHECK_WRITE), fShowDirFlags);
  217. ShowControl(GetDlgItem(IDC_CHECK_LOG_ACCESS), fShowDirFlags);
  218. ShowControl(GetDlgItem(IDC_CHECK_AUTHOR), fShowDirFlags);
  219. ShowControl(GetDlgItem(IDC_STATIC_DIRFLAGS_SMALL), fShowDirFlags);
  220. ShowControl(IDC_CHECK_EXACT, fShowRedirectFlags);
  221. ShowControl(IDC_CHECK_CHILD, fShowRedirectFlags);
  222. if (fShowRedirectFlags)
  223. {
  224. GetDlgItem(IDC_CHECK_CHILD)->EnableWindow(FALSE);
  225. }
  226. ShowControl(IDC_CHECK_PERMANENT, fShowRedirectFlags);
  227. ShowControl(IDC_STATIC_REDIRECT_PROMPT, fShowRedirectFlags);
  228. ShowControl(IDC_STATIC_REDIRFLAGS, fShowRedirectFlags);
  229. ShowControl(&m_check_Author, fShowDAV);
  230. //
  231. // Enable/Disable must come after the showcontrols
  232. //
  233. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  234. }
  235. void
  236. CW3FilePage::SaveAuthoringState()
  237. {
  238. if (m_check_Write.m_hWnd)
  239. {
  240. //
  241. // Controls initialized -- store live data
  242. //
  243. m_fOriginalWrite = m_check_Write.GetCheck() > 0;
  244. m_fOriginalRead = m_check_Read.GetCheck() > 0;
  245. }
  246. else
  247. {
  248. //
  249. // Controls not yet initialized, store original data
  250. //
  251. m_fOriginalWrite = m_fWrite;
  252. m_fOriginalRead = m_fRead;
  253. }
  254. }
  255. void
  256. CW3FilePage::RestoreAuthoringState()
  257. {
  258. m_fWrite = m_fOriginalWrite;
  259. m_fRead = m_fOriginalRead;
  260. }
  261. void
  262. CW3FilePage::SetAuthoringState(BOOL fAlterReadAndWrite)
  263. {
  264. if (fAlterReadAndWrite)
  265. {
  266. if (m_fAuthor)
  267. {
  268. //
  269. // Remember previous setting to undo
  270. // this thing.
  271. //
  272. SaveAuthoringState();
  273. m_fRead = m_fWrite = TRUE;
  274. }
  275. else
  276. {
  277. //
  278. // Restore previous defaults
  279. //
  280. RestoreAuthoringState();
  281. }
  282. m_check_Read.SetCheck(m_fRead);
  283. m_check_Write.SetCheck(m_fWrite);
  284. }
  285. m_check_Author.EnableWindow((m_fRead || m_fWrite)
  286. && HasAdminAccess()
  287. && HasDAV()
  288. );
  289. // m_check_Read.EnableWindow(!m_fAuthor && HasAdminAccess());
  290. // m_check_Write.EnableWindow(!m_fAuthor && HasAdminAccess());
  291. }
  292. void
  293. CW3FilePage::SetPathType()
  294. {
  295. if (!m_strRedirectPath.IsEmpty())
  296. {
  297. m_nPathType = RADIO_REDIRECT;
  298. m_radio_Dir.SetCheck(0);
  299. m_radio_Redirect.SetCheck(1);
  300. }
  301. else
  302. {
  303. m_nPathType = RADIO_DIRECTORY;
  304. m_radio_Redirect.SetCheck(0);
  305. m_radio_Dir.SetCheck(1);
  306. }
  307. m_static_PathPrompt.SetWindowText(m_strPrompt[m_nPathType]);
  308. }
  309. //
  310. // Message Handlers
  311. //
  312. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  313. void
  314. CW3FilePage::OnItemChanged()
  315. {
  316. SetModified(TRUE);
  317. }
  318. BOOL
  319. CW3FilePage::OnInitDialog()
  320. {
  321. CInetPropertyPage::OnInitDialog();
  322. SetPathType();
  323. SetStateByType();
  324. SetAuthoringState(FALSE);
  325. // It is enough to set file alias once -- we cannot change it here
  326. CString buf1, buf2, strAlias;
  327. CMetabasePath::GetRootPath(m_strFullMetaPath, buf1, &buf2);
  328. strAlias += _T("\\");
  329. strAlias += buf2;
  330. CvtPathToDosStyle(strAlias);
  331. m_edit_Path.SetWindowText(strAlias);
  332. return TRUE;
  333. }
  334. /* virtual */
  335. HRESULT
  336. CW3FilePage::FetchLoadedValues()
  337. {
  338. CError err;
  339. BEGIN_META_DIR_READ(CW3Sheet)
  340. //
  341. // Use m_ notation because the message crackers require it
  342. //
  343. BOOL m_fDontLog;
  344. FETCH_DIR_DATA_FROM_SHEET(m_strFullMetaPath);
  345. FETCH_DIR_DATA_FROM_SHEET(m_strRedirectPath);
  346. FETCH_DIR_DATA_FROM_SHEET(m_dwAccessPerms);
  347. FETCH_DIR_DATA_FROM_SHEET(m_fDontLog);
  348. FETCH_DIR_DATA_FROM_SHEET(m_fExact);
  349. FETCH_DIR_DATA_FROM_SHEET(m_fPermanent);
  350. m_fRead = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_READ);
  351. m_fWrite = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_WRITE);
  352. m_fAuthor = IS_FLAG_SET(m_dwAccessPerms, MD_ACCESS_SOURCE);
  353. m_fLogAccess = !m_fDontLog;
  354. SaveAuthoringState();
  355. END_META_DIR_READ(err)
  356. return err;
  357. }
  358. /* virtual */
  359. HRESULT
  360. CW3FilePage::SaveInfo()
  361. {
  362. ASSERT(IsDirty());
  363. CError err;
  364. SET_FLAG_IF(m_fRead, m_dwAccessPerms, MD_ACCESS_READ);
  365. SET_FLAG_IF(m_fWrite, m_dwAccessPerms, MD_ACCESS_WRITE);
  366. SET_FLAG_IF(m_fAuthor, m_dwAccessPerms, MD_ACCESS_SOURCE);
  367. BOOL m_fDontLog = !m_fLogAccess;
  368. BeginWaitCursor();
  369. BEGIN_META_DIR_WRITE(CW3Sheet)
  370. INIT_DIR_DATA_MASK(m_dwAccessPerms, m_dwBitRangePermissions)
  371. STORE_DIR_DATA_ON_SHEET(m_fDontLog)
  372. STORE_DIR_DATA_ON_SHEET(m_fExact);
  373. STORE_DIR_DATA_ON_SHEET(m_fPermanent);
  374. //
  375. // CODEWORK: Not an elegant solution
  376. //
  377. // pSheet->GetDirectoryProperties().MarkRedirAsInherit(!m_fChild);
  378. STORE_DIR_DATA_ON_SHEET(m_strRedirectPath)
  379. STORE_DIR_DATA_ON_SHEET(m_dwAccessPerms)
  380. END_META_DIR_WRITE(err)
  381. if (err.Succeeded())
  382. {
  383. SaveAuthoringState();
  384. err = ((CW3Sheet *)GetSheet())->SetKeyType();
  385. }
  386. EndWaitCursor();
  387. return err;
  388. }
  389. void
  390. CW3FilePage::OnCheckRead()
  391. {
  392. m_fRead = !m_fRead;
  393. SetAuthoringState(FALSE);
  394. OnItemChanged();
  395. }
  396. void
  397. CW3FilePage::OnCheckWrite()
  398. {
  399. m_fWrite = !m_fWrite;
  400. SetAuthoringState(FALSE);
  401. OnItemChanged();
  402. }
  403. void
  404. CW3FilePage::OnCheckAuthor()
  405. {
  406. m_fAuthor = !m_fAuthor;
  407. SetAuthoringState(FALSE);
  408. OnItemChanged();
  409. }
  410. void
  411. CW3FilePage::OnRadioDir()
  412. {
  413. ChangeTypeTo(RADIO_DIRECTORY);
  414. }
  415. void
  416. CW3FilePage::OnRadioRedirect()
  417. {
  418. ChangeTypeTo(RADIO_REDIRECT);
  419. }