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.

401 lines
10 KiB

  1. // AppEdMpD.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cnfgprts.h"
  5. #include "AppEdMpD.h"
  6. #include <iiscnfg.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAppEditMapDlg dialog
  14. //----------------------------------------------------------------
  15. CAppEditMapDlg::CAppEditMapDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CAppEditMapDlg::IDD, pParent),
  17. m_pList( NULL ),
  18. m_fNewMapping( FALSE ),
  19. m_fLocalMachine( TRUE )
  20. {
  21. //{{AFX_DATA_INIT(CAppEditMapDlg)
  22. m_bool_file_exists = FALSE;
  23. m_bool_script_engine = FALSE;
  24. m_sz_executable = _T("");
  25. m_sz_extension = _T("");
  26. m_sz_exclusions = _T("");
  27. m_nAllLimited = RADIO_LIMITED_VERBS;
  28. //}}AFX_DATA_INIT
  29. }
  30. //----------------------------------------------------------------
  31. void CAppEditMapDlg::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CAppEditMapDlg)
  35. DDX_Control(pDX, IDC_RADIO_LIMIT_VERBS, m_radio_LimitedTo);
  36. DDX_Control(pDX, IDC_RADIO_ALL_VERBS, m_radio_All);
  37. DDX_Control(pDX, IDC_EDT_EXCLUSIONS, m_edit_Exclusions);
  38. DDX_Control(pDX, IDC_EDT_EXTENSION, m_cedit_extension);
  39. DDX_Control(pDX, IDC_EDT_EXECUTABLE, m_cedit_executable);
  40. DDX_Control(pDX, IDC_BROWSE, m_cbttn_browse);
  41. DDX_Check(pDX, IDC_CHK_FILE_EXISTS, m_bool_file_exists);
  42. DDX_Check(pDX, IDC_CHK_SCRIPT_ENGINE, m_bool_script_engine);
  43. DDX_Text(pDX, IDC_EDT_EXECUTABLE, m_sz_executable);
  44. DDX_Text(pDX, IDC_EDT_EXTENSION, m_sz_extension);
  45. DDX_Text(pDX, IDC_EDT_EXCLUSIONS, m_sz_exclusions);
  46. DDX_Radio(pDX, IDC_RADIO_ALL_VERBS, m_nAllLimited);
  47. //}}AFX_DATA_MAP
  48. }
  49. //----------------------------------------------------------------
  50. BEGIN_MESSAGE_MAP(CAppEditMapDlg, CDialog)
  51. //{{AFX_MSG_MAP(CAppEditMapDlg)
  52. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  53. ON_BN_CLICKED(ID_HELPBTN, OnHelpbtn)
  54. ON_BN_CLICKED(IDC_RADIO_ALL_VERBS, OnRadioAllVerbs)
  55. ON_BN_CLICKED(IDC_RADIO_LIMIT_VERBS, OnRadioLimitVerbs)
  56. //}}AFX_MSG_MAP
  57. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  58. ON_COMMAND(ID_HELP, DoHelp)
  59. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  60. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  61. END_MESSAGE_MAP()
  62. //---------------------------------------------------------------------------
  63. void CAppEditMapDlg::DoHelp()
  64. {
  65. WinHelp( HIDD_APPMAPS_EDIT_MAP );
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CAppEditMapDlg message handlers
  69. //---------------------------------------------------------------------------
  70. BOOL CAppEditMapDlg::OnInitDialog()
  71. {
  72. // we can deal with the flags right here
  73. if ( m_dwFlags & MD_SCRIPTMAPFLAG_SCRIPT ) m_bool_script_engine = TRUE;
  74. if ( m_dwFlags & MD_SCRIPTMAPFLAG_CHECK_PATH_INFO ) m_bool_file_exists = TRUE;
  75. m_sz_extensionOrig = m_sz_extension;
  76. //call the parental oninitdialog
  77. BOOL fAnswer = CDialog::OnInitDialog();
  78. // if this is not the local machine we are editing, then disable browsing
  79. if ( fAnswer && (!m_fLocalMachine) )
  80. {
  81. m_cbttn_browse.EnableWindow( FALSE );
  82. }
  83. //
  84. // Set All/Limited radio button
  85. //
  86. if (m_sz_exclusions.IsEmpty())
  87. {
  88. m_radio_All.SetCheck(1);
  89. m_radio_LimitedTo.SetCheck(0);
  90. OnRadioAllVerbs();
  91. }
  92. else
  93. {
  94. m_radio_All.SetCheck(0);
  95. m_radio_LimitedTo.SetCheck(1);
  96. OnRadioLimitVerbs();
  97. }
  98. // return the answer
  99. return fAnswer;
  100. }
  101. //---------------------------------------------------------------------------
  102. void CAppEditMapDlg::OnOK()
  103. {
  104. UpdateData( TRUE );
  105. CString szFile;
  106. CString sz;
  107. DWORD attrib;
  108. // clean up the strings
  109. m_sz_executable.TrimLeft();
  110. m_sz_extension.TrimLeft();
  111. m_sz_executable.TrimRight();
  112. m_sz_extension.TrimRight();
  113. //--------------------------------------------------
  114. //
  115. // RONALDM -- handle all/limited to verbs situations
  116. //
  117. m_sz_exclusions.TrimLeft();
  118. m_sz_exclusions.TrimRight();
  119. if (m_nAllLimited == RADIO_ALL_VERBS)
  120. {
  121. //
  122. // "All" supported, empty the list
  123. //
  124. m_sz_exclusions.Empty();
  125. }
  126. else if (m_sz_exclusions.IsEmpty())
  127. {
  128. //
  129. // Now, it CAN'T be empty, complain about it.
  130. //
  131. AfxMessageBox(IDS_ERR_NO_VERBS);
  132. m_edit_Exclusions.SetFocus();
  133. m_edit_Exclusions.SetSel(0, -1);
  134. //
  135. // Don't dismiss the dialog
  136. //
  137. return;
  138. }
  139. //--------------------------------------------------
  140. // the extension is a required field
  141. if ( m_sz_extension.IsEmpty() || m_sz_extension == _T(".") )
  142. {
  143. AfxMessageBox( IDS_APP_ERR_EXT_REQUIRED );
  144. m_cedit_extension.SetFocus();
  145. m_cedit_extension.SetSel( 0 , -1 );
  146. return;
  147. }
  148. // if the file starts with a quote then there may be spaces in the name.
  149. // Extract the file up to the second quote
  150. if ( m_sz_executable[0] == _T('\"') )
  151. {
  152. szFile = m_sz_executable.Right(m_sz_executable.GetLength()-1);
  153. szFile = szFile.Left(szFile.Find('\"'));
  154. }
  155. else if ( m_sz_executable.Find(' ') >= 0 )
  156. {
  157. // in case there are parameters after the file name, just take it to the first space
  158. szFile = m_sz_executable.Left( m_sz_executable.Find(' ') );
  159. }
  160. else
  161. szFile = m_sz_executable;
  162. // we do NOT allow UNC names in script mappings. Get the drive letter
  163. // first we test the drive to see if it is local or remote
  164. // but before that we need to get the drive letter
  165. _tsplitpath( (LPCTSTR)szFile, sz.GetBuffer(_MAX_DRIVE+1), NULL, NULL, NULL );
  166. sz.ReleaseBuffer();
  167. // it can't be a unc path
  168. if ( sz.IsEmpty() )
  169. {
  170. AfxMessageBox( IDS_APP_MAP_USE_VALID_DRIVE );
  171. m_cedit_executable.SetFocus();
  172. m_cedit_executable.SetSel( 0 , -1 );
  173. return;
  174. }
  175. // perform extra local-machine tests
  176. if ( m_fLocalMachine )
  177. {
  178. // if local, the drive can't be redirected
  179. // test the drive and only accept valid, non-remote drives
  180. attrib = GetDriveType( (LPCTSTR)sz );
  181. if ( (attrib == DRIVE_REMOTE) )
  182. {
  183. AfxMessageBox( IDS_APP_MAP_USE_VALID_DRIVE );
  184. m_cedit_executable.SetFocus();
  185. m_cedit_executable.SetSel( 0 , -1 );
  186. return;
  187. }
  188. // check that the file exists
  189. if ( ::GetFileAttributes(szFile) & FILE_ATTRIBUTE_DIRECTORY )
  190. {
  191. AfxMessageBox( IDS_APP_MAP_INVALID_PATH );
  192. m_cedit_executable.SetFocus();
  193. m_cedit_executable.SetSel( 0 , -1 );
  194. return;
  195. }
  196. }
  197. // make sure the extension is valid
  198. if ( m_sz_extension.ReverseFind('.') > 0 )
  199. {
  200. AfxMessageBox( IDS_APP_MAP_INVALID_EXT );
  201. m_cedit_extension.SetFocus();
  202. m_cedit_extension.SetSel( 0 , -1 );
  203. return;
  204. }
  205. const TCHAR szBadChars[] = _T(" ,:<>?*/\\");
  206. if (m_sz_extension != _T("*") && m_sz_extension != _T(".*"))
  207. {
  208. if (0 != m_sz_extension.SpanExcluding(szBadChars).Compare(m_sz_extension))
  209. {
  210. AfxMessageBox( IDS_APP_MAP_INVALID_EXT );
  211. m_cedit_extension.SetFocus();
  212. m_cedit_extension.SetSel( 0 , -1 );
  213. return;
  214. }
  215. }
  216. if (m_sz_extension[0] == '*')
  217. {
  218. m_sz_extension.SetAt(1, '\0');
  219. }
  220. else if (m_sz_extension == _T(".*"))
  221. {
  222. m_sz_extension = _T("*");
  223. }
  224. else
  225. {
  226. // clean up the extensions string
  227. if ( m_sz_extension[0] != '.' )
  228. m_sz_extension = '.' + m_sz_extension;
  229. }
  230. // there can be only one copy of an extension in the listbox
  231. // only check this if it is a new mapping, or if the mapping extension has changed
  232. if ( m_pList && ((m_sz_extensionOrig != m_sz_extension) || m_fNewMapping) )
  233. {
  234. DWORD nItems = m_pList->GetItemCount();
  235. for ( DWORD i = 0; i < nItems; i++ )
  236. {
  237. if ( m_pList->GetItemText(i,0) == m_sz_extension )
  238. {
  239. AfxMessageBox( IDS_APP_ONLY_ONE );
  240. m_cedit_extension.SetFocus();
  241. m_cedit_extension.SetSel( 0 , -1 );
  242. return;
  243. }
  244. }
  245. }
  246. // rebuild the flags
  247. m_dwFlags = 0;
  248. if ( m_bool_script_engine )
  249. {
  250. m_dwFlags |= MD_SCRIPTMAPFLAG_SCRIPT;
  251. }
  252. if ( m_bool_file_exists )
  253. {
  254. m_dwFlags |= MD_SCRIPTMAPFLAG_CHECK_PATH_INFO;
  255. }
  256. // make sure the data goes back
  257. UpdateData( FALSE );
  258. CDialog::OnOK();
  259. }
  260. //---------------------------------------------------------------------------
  261. void CAppEditMapDlg::OnBrowse()
  262. {
  263. // prepare the file dialog variables
  264. CFileDialog cfdlg(TRUE);
  265. CString szFilter;
  266. WORD i = 0;
  267. LPTSTR lpszBuffer;
  268. // prepare the filter string
  269. szFilter.LoadString( IDS_APP_MAP_FILTER );
  270. // replace the "!" characters with nulls
  271. lpszBuffer = szFilter.GetBuffer(MAX_PATH+1);
  272. while( lpszBuffer[i] )
  273. {
  274. if ( lpszBuffer[i] == _T('!') )
  275. lpszBuffer[i] = _T('\0'); // yes, set \0 on purpose
  276. i++;
  277. }
  278. // prep the dialog
  279. cfdlg.m_ofn.lpstrFilter = lpszBuffer;
  280. // run the dialog
  281. if ( cfdlg.DoModal() == IDOK )
  282. {
  283. UpdateData( TRUE );
  284. m_sz_executable = cfdlg.GetPathName();
  285. UpdateData( FALSE );
  286. }
  287. // release the buffer in the filter string
  288. szFilter.ReleaseBuffer(-1);
  289. }
  290. //---------------------------------------------------------------------------
  291. void CAppEditMapDlg::OnHelpbtn()
  292. {
  293. DoHelp();
  294. }
  295. void
  296. CAppEditMapDlg::OnRadioAllVerbs()
  297. /*++
  298. Routine Description:
  299. "All" radio button handler
  300. Arguments:
  301. None
  302. Return Value:
  303. None
  304. Notes:
  305. Routine by RonaldM
  306. --*/
  307. {
  308. //
  309. // No need for the exclusions to be specified by name.
  310. // Move focus elsewhere to prevent disabled control from
  311. // having focus.
  312. //
  313. m_edit_Exclusions.EnableWindow(FALSE);
  314. m_radio_All.SetFocus();
  315. }
  316. void
  317. CAppEditMapDlg::OnRadioLimitVerbs()
  318. /*++
  319. Routine Description:
  320. "Limited to" radio button handler
  321. Arguments:
  322. None
  323. Return Value:
  324. None
  325. Notes:
  326. Routine by RonaldM
  327. --*/
  328. {
  329. //
  330. // User wants to specify exclusions by name, so
  331. // focus on exclusions edit box.
  332. //
  333. m_edit_Exclusions.EnableWindow(TRUE);
  334. m_edit_Exclusions.SetFocus();
  335. }