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.

355 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name :
  4. W3PropPage.cpp
  5. Abstract:
  6. IIS Shell extension PropertyPage class implementation
  7. Author:
  8. Sergei Antonov (sergeia)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "W3PropPage.h"
  15. #include "w3ext.h"
  16. #include "PropShellExt.h"
  17. #include "EditAlias.h"
  18. #define SZ_SERVER_KEYTYPE _T("IIsWebServer")
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CW3PropPage
  21. LRESULT
  22. CW3PropPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  23. {
  24. // subclass dialog controls
  25. DoDataExchange();
  26. ASSERT(m_pParentExt != NULL);
  27. CMetaEnumerator en(LOCAL_KEY, CMetabasePath(SZ_MBN_WEB));
  28. ASSERT(en.Succeeded());
  29. if (en.Succeeded())
  30. {
  31. DWORD di;
  32. int i = -1;
  33. CString inst;
  34. HRESULT hr = S_OK;
  35. while (SUCCEEDED(hr))
  36. {
  37. if (SUCCEEDED(hr = en.Next(di, inst)))
  38. {
  39. CString cmt;
  40. if (SUCCEEDED(hr = en.QueryValue(MD_SERVER_COMMENT, cmt, NULL, inst)))
  41. {
  42. if (cmt.IsEmpty())
  43. {
  44. cmt.Format(_Module.GetResourceInstance(),
  45. IDS_DEFAULT_SERVER_COMMENT, di);
  46. }
  47. if (CB_ERR != (i = m_servers_list.AddString(cmt)))
  48. {
  49. m_servers_list.SetItemDataPtr(i, StrDup(inst));
  50. }
  51. }
  52. }
  53. }
  54. if (i >= 0)
  55. m_servers_list.SetCurSel(0);
  56. m_ShareThis = 0;
  57. // Fill shares list box for selected server
  58. OnServerChange(0, 0, NULL);
  59. }
  60. return 1;
  61. }
  62. void
  63. CW3PropPage::OnDestroy()
  64. {
  65. ATLTRACE("In OnDestroy handler\n");
  66. // DebugBreak();
  67. }
  68. HRESULT GetKeyNames(CMetaEnumerator& en, std::set<CString>& keys)
  69. {
  70. CString key;
  71. HRESULT hr;
  72. if (SUCCEEDED(hr = en.Next(key)))
  73. {
  74. keys.insert(key);
  75. }
  76. return hr;
  77. }
  78. void
  79. CW3PropPage::OnAdd(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  80. {
  81. CEditAlias dlg;
  82. int index = m_servers_list.GetCurSel();
  83. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  84. dlg.m_instance = p;
  85. p = m_pParentExt->GetPath();
  86. ::StrCpy(dlg.m_path, p);
  87. dlg.m_new = TRUE;
  88. if (p == PathFindFileName(p))
  89. {
  90. /* No file name -- could be root directory like c:\ */
  91. dlg.m_alias[0] = 0;
  92. }
  93. else
  94. {
  95. TCHAR buf[MAX_PATH];
  96. StrCpy(buf, PathFindFileName(p));
  97. PathMakePretty(buf);
  98. StrCpy(dlg.m_alias, buf);
  99. // Now we need to generate unique prompt for this new alias
  100. CMetaEnumerator en(LOCAL_KEY,
  101. CMetabasePath(TRUE, SZ_MBN_WEB, dlg.m_instance, SZ_MBN_ROOT));
  102. ASSERT(en.Succeeded());
  103. if (en.Succeeded())
  104. {
  105. std::set<CString> keys;
  106. if (SUCCEEDED(GetKeyNames(en, keys)) && !keys.empty())
  107. {
  108. int i = 0;
  109. while (keys.find(buf) != keys.end())
  110. {
  111. wsprintf(buf, _T("%s%d"), dlg.m_alias, ++i);
  112. }
  113. StrCpy(dlg.m_alias, buf);
  114. }
  115. }
  116. }
  117. if (IDOK == dlg.DoModal())
  118. {
  119. OnServerChange(0, 0, NULL);
  120. }
  121. }
  122. void
  123. CW3PropPage::OnRemove(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  124. {
  125. CString cap, msg;
  126. int index = m_servers_list.GetCurSel();
  127. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  128. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  129. index = m_share_list.GetCurSel();
  130. TCHAR buf[MAX_PATH];
  131. m_share_list.GetText(index, buf);
  132. msg.Format(_Module.GetResourceInstance(), IDS_CONFIRM_REMOVE, buf);
  133. CError err;
  134. if (IDYES == MessageBox(msg, cap, MB_YESNO))
  135. {
  136. CWaitCursor wait;
  137. do
  138. {
  139. CIISApplication app(NULL, CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT, buf));
  140. err = app.QueryResult();
  141. BREAK_ON_ERR_FAILURE(err)
  142. err = app.Delete(TRUE);
  143. } while (FALSE);
  144. if (err.Succeeded())
  145. {
  146. CMetaKey mk(LOCAL_KEY,
  147. CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT),
  148. METADATA_PERMISSION_WRITE);
  149. err = mk.DeleteKey(buf);
  150. }
  151. }
  152. if (err.Failed())
  153. {
  154. err.MessageBox();
  155. }
  156. else
  157. {
  158. m_share_list.DeleteString(index);
  159. int count = m_share_list.GetCount();
  160. m_ShareThis = count > 0 ? 1 : 0;
  161. if (m_ShareThis)
  162. {
  163. m_share_list.SetCurSel(index >= count ? count - 1 : index);
  164. }
  165. EnableOnShare();
  166. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  167. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  168. }
  169. }
  170. void
  171. CW3PropPage::OnEdit(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  172. {
  173. CEditAlias dlg;
  174. int index = m_servers_list.GetCurSel();
  175. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  176. dlg.m_instance = p;
  177. p = m_pParentExt->GetPath();
  178. ::StrCpy(dlg.m_path, p);
  179. index = m_share_list.GetCurSel();
  180. TCHAR buf[MAX_PATH];
  181. m_share_list.GetText(index, buf);
  182. ::StrCpy(dlg.m_alias, buf);
  183. dlg.m_new = FALSE;
  184. if (IDOK == dlg.DoModal())
  185. {
  186. OnServerChange(0, 0, NULL);
  187. }
  188. }
  189. void
  190. CW3PropPage::OnServerChange(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  191. {
  192. // get selected server instance number
  193. int index = m_servers_list.GetCurSel();
  194. if (LB_ERR != index)
  195. {
  196. LPTSTR p = (LPTSTR)m_servers_list.GetItemDataPtr(index);
  197. CMetabasePath path(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT);
  198. CMetaEnumerator en(LOCAL_KEY, path);
  199. ASSERT(en.Succeeded());
  200. m_share_list.ResetContent();
  201. if (en.Succeeded())
  202. {
  203. RecurseVDirs(en, NULL);
  204. }
  205. m_ShareThis = m_share_list.GetCount() > 0 ? 1 : 0;
  206. }
  207. if (m_ShareThis)
  208. {
  209. m_share_list.SetCurSel(0);
  210. }
  211. EnableOnShare();
  212. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  213. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  214. }
  215. void
  216. CW3PropPage::RecurseVDirs(CMetaEnumerator& en, LPCTSTR path)
  217. {
  218. CString vrpath;
  219. BOOL bInheritOverride = FALSE;
  220. if (SUCCEEDED(en.QueryValue(MD_VR_PATH, vrpath, &bInheritOverride, path)))
  221. {
  222. if (vrpath.CompareNoCase(m_pParentExt->GetPath()) == 0)
  223. {
  224. CMetabasePath mpath(FALSE, path);
  225. CMetabasePath::CleanMetaPath(mpath);
  226. m_share_list.AddString(path == NULL ?
  227. SZ_MBN_SEP_STR : mpath.QueryMetaPath());
  228. }
  229. }
  230. CString vdir;
  231. while (SUCCEEDED(en.Next(vdir, path)))
  232. {
  233. CString next_vdir;
  234. if (path != NULL)
  235. next_vdir += path;
  236. next_vdir += vdir;
  237. next_vdir += SZ_MBN_SEP_STR;
  238. en.Push();
  239. en.Reset();
  240. RecurseVDirs(en, next_vdir);
  241. en.Pop();
  242. }
  243. }
  244. void
  245. CW3PropPage::OnShareYesNo(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  246. {
  247. int count = m_share_list.GetCount();
  248. m_ShareThis = IsDlgButtonChecked(IDC_SHARE_ON);
  249. if (m_ShareThis)
  250. {
  251. if (count <= 0)
  252. {
  253. OnAdd(0, 0, NULL);
  254. if (!(m_ShareThis = (m_share_list.GetCount() > 0)))
  255. {
  256. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  257. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  258. }
  259. }
  260. }
  261. else
  262. {
  263. if (count > 0)
  264. {
  265. CString cap, msg;
  266. int index = m_servers_list.GetCurSel();
  267. LPCTSTR p = (LPCTSTR)m_servers_list.GetItemData(index);
  268. cap.LoadString(_Module.GetResourceInstance(), IDS_PAGE_TITLE);
  269. msg.LoadString(_Module.GetResourceInstance(), IDS_CONFIRM_REMOVE_ALL);
  270. CError err;
  271. if (IDYES == MessageBox(msg, cap, MB_YESNO))
  272. {
  273. CWaitCursor wait;
  274. TCHAR alias[MAX_PATH];
  275. for (index = 0; err.Succeeded() && index < count; index++)
  276. {
  277. m_share_list.GetText(0, alias);
  278. do
  279. {
  280. CIISApplication app(NULL, CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT, alias));
  281. err = app.QueryResult();
  282. BREAK_ON_ERR_FAILURE(err)
  283. err = app.Delete(TRUE);
  284. BREAK_ON_ERR_FAILURE(err)
  285. CMetaKey mk(LOCAL_KEY,
  286. CMetabasePath(TRUE, SZ_MBN_WEB, p, SZ_MBN_ROOT),
  287. METADATA_PERMISSION_WRITE);
  288. err = mk.DeleteKey(alias);
  289. BREAK_ON_ERR_FAILURE(err)
  290. } while (FALSE);
  291. BREAK_ON_ERR_FAILURE(err)
  292. m_share_list.DeleteString(0);
  293. }
  294. if (err.Failed())
  295. {
  296. // BUGBUG: we have AV when preparing message box text here
  297. // err.MessageBox();
  298. m_ShareThis = TRUE;
  299. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  300. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  301. }
  302. }
  303. else
  304. {
  305. m_ShareThis = TRUE;
  306. CheckDlgButton(IDC_SHARE_ON, m_ShareThis);
  307. CheckDlgButton(IDC_SHARE_OFF, !m_ShareThis);
  308. }
  309. }
  310. }
  311. EnableOnShare();
  312. }
  313. void
  314. CW3PropPage::EnableOnShare()
  315. {
  316. m_share_list.EnableWindow(m_ShareThis);
  317. ::EnableWindow(GetDlgItem(IDC_ADD), m_ShareThis);
  318. ::EnableWindow(GetDlgItem(IDC_EDIT), m_ShareThis
  319. && m_share_list.GetCurSel() != LB_ERR);
  320. ::EnableWindow(GetDlgItem(IDC_REMOVE), m_ShareThis
  321. && m_share_list.GetCurSel() != LB_ERR);
  322. }
  323. void
  324. CW3PropPage::OnVDirChange(WORD wNotifyCode, WORD wID, HWND hWndCtl)
  325. {
  326. BOOL bSel = m_share_list.GetCurSel() != LB_ERR;
  327. ::EnableWindow(GetDlgItem(IDC_EDIT), bSel);
  328. ::EnableWindow(GetDlgItem(IDC_REMOVE), bSel);
  329. }