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.

397 lines
10 KiB

  1. //
  2. //
  3. //
  4. #include "stdafx.h"
  5. #include "MappingPage.h"
  6. enum
  7. {
  8. COL_EXTENSION = 0,
  9. COL_PATH,
  10. COL_EXCLUSIONS
  11. };
  12. #define EXT_WIDTH 58
  13. #define PATH_WIDTH 204
  14. #define EXCLUSIONS_WIDTH 72
  15. LRESULT
  16. CAppMappingPage::OnInitDialog(HWND hDlg, LPARAM lParam)
  17. {
  18. CString str;
  19. CError err;
  20. DoDataExchange();
  21. DWORD dwStyle = m_list.GetExtendedListViewStyle();
  22. m_list.SetExtendedListViewStyle(
  23. dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);
  24. str.LoadString(_Module.GetResourceInstance(), IDS_EXTENSION);
  25. m_list.InsertColumn(COL_EXTENSION, str, LVCFMT_LEFT, EXT_WIDTH, 0);
  26. str.LoadString(_Module.GetResourceInstance(), IDS_EXECUTABLE_PATH);
  27. m_list.InsertColumn(COL_PATH, str, LVCFMT_LEFT, PATH_WIDTH, 1);
  28. str.LoadString(_Module.GetResourceInstance(), IDS_VERBS);
  29. m_list.InsertColumn(COL_EXCLUSIONS, str, LVCFMT_LEFT, EXCLUSIONS_WIDTH, 2);
  30. ASSERT(m_pData != NULL);
  31. CMappings::iterator it;
  32. int idx = 0;
  33. CString all_verbs;
  34. VERIFY(all_verbs.LoadString(_Module.GetResourceInstance(), IDS_ALL));
  35. for (it = m_pData->m_Mappings.begin(); it != m_pData->m_Mappings.end(); it++, idx++)
  36. {
  37. Mapping map = (*it).second;
  38. VERIFY(-1 != m_list.InsertItem(idx, map.ext));
  39. VERIFY(m_list.SetItemText(idx, COL_PATH, map.path));
  40. VERIFY(m_list.SetItemData(idx, map.flags));
  41. VERIFY(m_list.SetItemText(idx, COL_EXCLUSIONS,
  42. map.verbs.IsEmpty() ? all_verbs : map.verbs));
  43. }
  44. CString remainder;
  45. CMetabasePath::GetRootPath(m_pData->m_MetaPath, str, &remainder);
  46. ::EnableWindow(GetDlgItem(IDC_CACHE_ISAPI), remainder.IsEmpty());
  47. int count = m_list.GetItemCount();
  48. if (count > 0)
  49. {
  50. m_list.SelectItem(0);
  51. }
  52. ::EnableWindow(GetDlgItem(IDC_EDIT), count > 0);
  53. ::EnableWindow(GetDlgItem(IDC_REMOVE), count > 0);
  54. return 0;
  55. }
  56. void
  57. CAppMappingPage::OnAdd(UINT nCode, UINT nID, HWND hWnd)
  58. {
  59. CEditMap dlg;
  60. dlg.m_new = TRUE;
  61. dlg.m_flags = MD_SCRIPTMAPFLAG_SCRIPT;
  62. dlg.m_pData = m_pData;
  63. if (dlg.DoModal() == IDOK)
  64. {
  65. CString all_verbs;
  66. VERIFY(all_verbs.LoadString(_Module.GetResourceInstance(), IDS_ALL));
  67. Mapping map;
  68. map.ext = dlg.m_ext;
  69. map.path = dlg.m_exec;
  70. map.verbs = dlg.m_verbs;
  71. map.flags = dlg.m_flags;
  72. m_pData->m_Mappings.insert(CMappings::value_type(map.ext, map));
  73. int count = m_list.GetItemCount();
  74. VERIFY(-1 != m_list.InsertItem(count, map.ext));
  75. VERIFY(m_list.SetItemText(count, COL_PATH, dlg.m_exec));
  76. VERIFY(m_list.SetItemData(count, dlg.m_flags));
  77. VERIFY(m_list.SetItemText(count, COL_EXCLUSIONS,
  78. dlg.m_verbs[0] == 0 ? all_verbs : dlg.m_verbs));
  79. SET_MODIFIED(TRUE);
  80. }
  81. }
  82. void
  83. CAppMappingPage::OnEdit(UINT nCode, UINT nID, HWND hWnd)
  84. {
  85. CEditMap dlg;
  86. dlg.m_new = FALSE;
  87. dlg.m_pData = m_pData;
  88. int idx = m_list.GetSelectedIndex();
  89. TCHAR buf[MAX_PATH];
  90. VERIFY(0 != m_list.GetItemText(idx, 0, buf, MAX_PATH));
  91. CMappings::iterator it = m_pData->m_Mappings.find(buf);
  92. ASSERT(it != m_pData->m_Mappings.end());
  93. StrCpy(dlg.m_ext, buf);
  94. StrCpy(dlg.m_exec, (*it).second.path);
  95. StrCpy(dlg.m_verbs, (*it).second.verbs);
  96. dlg.m_flags = (*it).second.flags;
  97. if (dlg.DoModal() == IDOK)
  98. {
  99. CString all_verbs;
  100. VERIFY(all_verbs.LoadString(_Module.GetResourceInstance(), IDS_ALL));
  101. (*it).second.path = dlg.m_exec;
  102. (*it).second.verbs = dlg.m_verbs;
  103. (*it).second.flags = dlg.m_flags;
  104. VERIFY(m_list.SetItemText(idx, COL_PATH, dlg.m_exec));
  105. VERIFY(m_list.SetItemData(idx, dlg.m_flags));
  106. VERIFY(m_list.SetItemText(idx, COL_EXCLUSIONS,
  107. dlg.m_verbs[0] == 0 ? all_verbs : dlg.m_verbs));
  108. SET_MODIFIED(TRUE);
  109. }
  110. }
  111. void
  112. CAppMappingPage::OnRemove(UINT nCode, UINT nID, HWND hWnd)
  113. {
  114. CString msg;
  115. msg.LoadString(_Module.GetResourceInstance(), IDS_CONFIRM_REMOVE_MAP);
  116. if (MessageBox(msg, NULL, MB_YESNO) == IDYES)
  117. {
  118. int i = m_list.GetSelectedIndex();
  119. int count;
  120. m_list.DeleteItem(i);
  121. SET_MODIFIED(TRUE);
  122. if ((count = m_list.GetItemCount()) > 0)
  123. {
  124. if (i >= count)
  125. i = count - 1;
  126. m_list.SelectItem(i);
  127. }
  128. else
  129. {
  130. ::EnableWindow(GetDlgItem(IDC_REMOVE), FALSE);
  131. ::EnableWindow(GetDlgItem(IDC_EDIT), FALSE);
  132. }
  133. }
  134. }
  135. void
  136. CAppMappingPage::OnCacheISAPI(UINT nCode, UINT nID, HWND hWnd)
  137. {
  138. SET_MODIFIED(TRUE);
  139. }
  140. BOOL
  141. CAppMappingPage::OnKillActive()
  142. {
  143. DoDataExchange(TRUE);
  144. return TRUE;
  145. }
  146. //---------------- CEditMap dialog --------------------------
  147. #define CHECK_VERBS()\
  148. m_bVerbsValid = \
  149. (m_verbs_index > 0 && lstrlen(m_verbs) != 0) || (m_verbs_index == 0)
  150. #define CHECK_EXT()\
  151. m_bExtValid = (lstrlen(m_ext) != 0 && StrCmp(m_ext, _T(".")) != 0)
  152. #define CHECK_EXEC(buf)\
  153. m_bExecValid = (lstrlen((buf)) != 0 && !PathIsUNC((buf)))
  154. #define ENABLE_OK()\
  155. ::EnableWindow(GetDlgItem(IDOK), m_bExtValid && m_bExecValid && m_bVerbsValid)
  156. LRESULT
  157. CEditMap::OnInitDialog(HWND hDlg, LPARAM lParam)
  158. {
  159. DoDataExchange();
  160. m_prev_ext = m_ext;
  161. DWORD style = FC_DEFAULT_READ | FC_COMMANDLINE;
  162. if (!::IsServerLocal(m_pData->m_ServerName))
  163. {
  164. style &= ~(FC_AUTOCOMPLETION | FC_PATH_CHECK);
  165. ::EnableWindow(GetDlgItem(IDC_BROWSE), FALSE);
  166. }
  167. m_FileChooser.Init(this, style, IDC_EXECUTABLE, IDC_BROWSE);
  168. m_FileChooser.AddExtension(_Module.GetResourceInstance(),
  169. IDS_EXECUTABLE_FILES, IDS_EXECUTABLE_EXT);
  170. m_FileChooser.AddExtension(_Module.GetResourceInstance(),
  171. IDS_DLL_FILES, IDS_DLL_EXT);
  172. m_FileChooser.AddExtension(_Module.GetResourceInstance(),
  173. IDS_ALL_FILES, IDS_ALL_EXT);
  174. m_FileChooser.SetPath(m_exec);
  175. m_verbs_index = lstrlen(m_verbs) == 0 ? 0 : 1;
  176. ::EnableWindow(GetDlgItem(IDC_VERBS), m_verbs_index > 0);
  177. m_script_engine = ((m_flags & MD_SCRIPTMAPFLAG_SCRIPT) != 0);
  178. m_file_exists = ((m_flags & MD_SCRIPTMAPFLAG_CHECK_PATH_INFO) != 0);
  179. ::EnableWindow(GetDlgItem(IDC_EXTENSION), m_new);
  180. CHECK_EXT();
  181. CHECK_EXEC(m_exec);
  182. CHECK_VERBS();
  183. // ATLTRACE(_T("Enable OK OnInitDialog %s\n"),
  184. // m_bExtValid && m_bExecValid && m_bVerbsValid ?
  185. // _T("TRUE") : _T("FALSE"));
  186. ENABLE_OK();
  187. DoDataExchange();
  188. return FALSE;
  189. }
  190. void
  191. CEditMap::OnVerbs(UINT nCode, UINT nID, HWND hWnd)
  192. {
  193. DoDataExchange(TRUE);
  194. ::EnableWindow(GetDlgItem(IDC_VERBS), m_verbs_index > 0);
  195. CHECK_VERBS();
  196. // ATLTRACE(_T("Enable OK OnVerbs %s\n"),
  197. // m_bExtValid && m_bExecValid && m_bVerbsValid ?
  198. // _T("TRUE") : _T("FALSE"));
  199. ENABLE_OK();
  200. }
  201. void
  202. CEditMap::OnVerbsChanged(UINT nCode, UINT nID, HWND hWnd)
  203. {
  204. DoDataExchange(TRUE, IDC_VERBS);
  205. CHECK_VERBS();
  206. // ATLTRACE(_T("Enable OK OnVerbsChanged %s\n"),
  207. // m_bExtValid && m_bExecValid && m_bVerbsValid ?
  208. // _T("TRUE") : _T("FALSE"));
  209. ENABLE_OK();
  210. }
  211. void
  212. CEditMap::OnHelp(UINT nCode, UINT nID, HWND hWnd)
  213. {
  214. }
  215. #define BAIL_WITH_MESSAGE(msg, focus)\
  216. idmsg = msg;\
  217. idfocus = focus;\
  218. break
  219. void
  220. CEditMap::OnOK(UINT nCode, UINT nID, HWND hWnd)
  221. {
  222. UINT idmsg = 0, idfocus = 0;
  223. DoDataExchange(TRUE);
  224. // When All is selected, verbs string is empty
  225. do
  226. {
  227. if (m_verbs_index == 0)
  228. {
  229. m_verbs[0] = 0;
  230. }
  231. else if (m_verbs[0] == 0)
  232. {
  233. BAIL_WITH_MESSAGE(IDS_ERR_NOVERBS, IDC_VERBS);
  234. }
  235. CString ext = m_ext;
  236. if (ext.ReverseFind(_T('.')) > 0)
  237. {
  238. BAIL_WITH_MESSAGE(IDS_ERR_BADEXT, IDC_EXTENSION);
  239. }
  240. if (ext.GetAt(0) == _T('*'))
  241. ext.erase(1);
  242. else if (ext.Compare(_T(".*")) == 0)
  243. ext = _T("*");
  244. else if (ext.GetAt(0) != _T('.'))
  245. ext = _T('.') + ext;
  246. // Ext should be unique, if new or changed
  247. if ( (m_new || m_prev_ext.CompareNoCase(ext) != 0)
  248. && m_pData->m_Mappings.find(ext) != m_pData->m_Mappings.end()
  249. )
  250. {
  251. BAIL_WITH_MESSAGE(IDS_ERR_USEDEXT, IDC_EXTENSION);
  252. }
  253. StrCpy(m_ext, ext);
  254. CString buf;
  255. if (FC_SUCCESS != m_FileChooser.GetFileName(buf))
  256. {
  257. BAIL_WITH_MESSAGE(IDS_ERR_BADEXECFORMAT, IDC_EXECUTABLE);
  258. }
  259. int pos;
  260. CString path;
  261. if (buf[0] == _T('\"'))
  262. {
  263. if ((pos = buf.find_last_of(_T('\"'))) != CString::npos)
  264. {
  265. path = buf.substr(1, --pos);
  266. }
  267. else
  268. {
  269. BAIL_WITH_MESSAGE(IDS_ERR_BADEXECFORMAT, IDC_EXECUTABLE);
  270. }
  271. }
  272. else if (CString::npos != (pos = buf.find(_T(' '))))
  273. {
  274. // in case there are parameters after the file name, just take it to the first space
  275. path = buf.substr(0, --pos);
  276. }
  277. if (PathIsUNC(path))
  278. {
  279. BAIL_WITH_MESSAGE(IDS_ERR_NOUNC, IDC_EXECUTABLE);
  280. }
  281. // perform extra local-machine tests
  282. if (::IsServerLocal(m_pData->m_ServerName))
  283. {
  284. // if local, the drive can't be redirected
  285. // test the drive and only accept valid, non-remote drives
  286. if (PathIsNetworkPath(path))
  287. {
  288. BAIL_WITH_MESSAGE(IDS_ERR_NOREMOTE, IDC_EXECUTABLE);
  289. }
  290. // check that the file exists
  291. if (PathIsDirectory(path))
  292. {
  293. BAIL_WITH_MESSAGE(IDS_ERR_FILENOTEXISTS, IDC_EXECUTABLE);
  294. }
  295. }
  296. m_flags = 0;
  297. if (m_script_engine)
  298. m_flags |= MD_SCRIPTMAPFLAG_SCRIPT;
  299. if (m_file_exists)
  300. m_flags |= MD_SCRIPTMAPFLAG_CHECK_PATH_INFO;
  301. StrCpy(m_exec, buf);
  302. }
  303. while (FALSE);
  304. if (idmsg != 0)
  305. {
  306. CString msg;
  307. CString cap;
  308. msg.LoadString(_Module.GetResourceInstance(), idmsg);
  309. cap.LoadString(_Module.GetResourceInstance(), IDS_SHEET_TITLE);
  310. MessageBox(msg, cap);
  311. ::SetFocus(GetDlgItem(idfocus));
  312. SendDlgItemMessage(idfocus, EM_SETSEL, 0, -1);
  313. return;
  314. }
  315. EndDialog(nID);
  316. }
  317. void
  318. CEditMap::OnCancel(UINT nCode, UINT nID, HWND hWnd)
  319. {
  320. EndDialog(nID);
  321. }
  322. void
  323. CEditMap::OnExtChanged(UINT nCode, UINT nID, HWND hWnd)
  324. {
  325. DoDataExchange(TRUE, IDC_EXTENSION);
  326. CHECK_EXT();
  327. // ATLTRACE(_T("Enable OK OnExtChanged %s\n"),
  328. // m_bExtValid && m_bExecValid && m_bVerbsValid ?
  329. // _T("TRUE") : _T("FALSE"));
  330. ENABLE_OK();
  331. }
  332. void
  333. CEditMap::OnExecChanged(UINT nCode, UINT nID, HWND hWnd)
  334. {
  335. // HWND hwnd = GetDlgItem(IDC_EXECUTABLE);
  336. CString str;
  337. // if (::GetFocus() == hwnd)
  338. // {
  339. // DoDataExchange(TRUE, IDC_EXECUTABLE);
  340. // str = m_exec;
  341. // }
  342. // else
  343. // {
  344. m_FileChooser.GetFileName(str);
  345. // BUGBUG: clean it up
  346. TCHAR buff[MAX_PATH];
  347. StrCpyN(buff, str, str.GetLength());
  348. PathRemoveArgs(buff);
  349. // }
  350. CHECK_EXEC(buff);
  351. ENABLE_OK();
  352. }