Leaked source code of windows server 2003
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.

182 lines
4.2 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. Rule.cpp
  5. Abstract:
  6. Rule object for use in inclusion exclusion.
  7. Author:
  8. Art Bragg [abragg] 08-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "Rule.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CRule dialog
  15. static DWORD pHelpIds[] =
  16. {
  17. IDC_EDIT_RESOURCE_NAME, idh_rule_edit_name,
  18. IDC_EDIT_PATH, idh_rule_edit_path,
  19. IDC_EDIT_FILESPEC, idh_rule_edit_file_type,
  20. IDC_RADIO_EXCLUDE, idh_rule_edit_exclude,
  21. IDC_RADIO_INCLUDE, idh_rule_edit_include,
  22. IDC_CHECK_SUBDIRS, idh_rule_edit_apply_subfolders,
  23. 0, 0
  24. };
  25. CRule::CRule(CWnd* pParent /*=NULL*/)
  26. : CRsDialog(CRule::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CRule)
  29. m_subDirs = FALSE;
  30. m_fileSpec = _T("");
  31. m_path = _T("");
  32. m_includeExclude = -1;
  33. m_pResourceName = _T("");
  34. //}}AFX_DATA_INIT
  35. m_pHelpIds = pHelpIds;
  36. }
  37. void CRule::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CRsDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CRule)
  41. DDX_Check(pDX, IDC_CHECK_SUBDIRS, m_subDirs);
  42. DDX_Text(pDX, IDC_EDIT_FILESPEC, m_fileSpec);
  43. DDX_Text(pDX, IDC_EDIT_PATH, m_path);
  44. DDX_Radio(pDX, IDC_RADIO_EXCLUDE, m_includeExclude);
  45. DDX_Text(pDX, IDC_EDIT_RESOURCE_NAME, m_pResourceName);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CRule, CRsDialog)
  49. //{{AFX_MSG_MAP(CRule)
  50. ON_BN_CLICKED(IDC_RADIO_EXCLUDE, OnRadioExclude)
  51. ON_BN_CLICKED(IDC_RADIO_INCLUDE, OnRadioInclude)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CRule message handlers
  56. void CRule::OnRadioExclude()
  57. {
  58. // TODO: Add your control notification handler code here
  59. }
  60. void CRule::OnRadioInclude()
  61. {
  62. // TODO: Add your control notification handler code here
  63. }
  64. BOOL CRule::OnInitDialog()
  65. {
  66. CRsDialog::OnInitDialog();
  67. UpdateData (FALSE);
  68. return TRUE; // return TRUE unless you set the focus to a control
  69. // EXCEPTION: OCX Property Pages should return FALSE
  70. }
  71. //////////////////////////////////////////////////////////////////////////
  72. //
  73. // Returns: False if path is not legal
  74. //
  75. BOOL CRule::FixRulePath (CString& sPath)
  76. {
  77. BOOL fOk = TRUE;
  78. TCHAR c;
  79. int length = 0;
  80. int i;
  81. // Test for illegal characters
  82. length = sPath.GetLength();
  83. for (i = 0; i < length; i++)
  84. {
  85. c = sPath[i];
  86. if (c == ':') {
  87. fOk = FALSE;
  88. break;
  89. }
  90. }
  91. if (fOk) {
  92. // Convert all "/" to "\"
  93. length = sPath.GetLength();
  94. for (i = 0; i < length; i++)
  95. {
  96. c = sPath[i];
  97. if (c == '/') sPath.SetAt (i, '\\');
  98. }
  99. // Make sure path starts with a "\"
  100. c = sPath[0];
  101. if (c != '\\')
  102. {
  103. sPath = "\\" + sPath;
  104. }
  105. // If path has at least one dir, clean up final "\" if there is one
  106. length = sPath.GetLength();
  107. if (length > 1) {
  108. c = sPath[length - 1];
  109. if (c == '\\') {
  110. sPath = sPath.Left (length - 1);
  111. }
  112. }
  113. }
  114. return fOk;
  115. }
  116. void CRule::OnOK()
  117. {
  118. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  119. UpdateData (TRUE);
  120. // Verify the path and name fields
  121. if (m_path != "")
  122. {
  123. if (m_fileSpec != "")
  124. {
  125. // Fix up the path
  126. if (FixRulePath (m_path)) {
  127. // Show the new data - because when we call OnOK the variables
  128. // will get updated again.
  129. UpdateData (FALSE);
  130. CRsDialog::OnOK();
  131. } else {
  132. AfxMessageBox (IDS_ERR_RULE_ILLEGAL_PATH, RS_MB_ERROR);
  133. }
  134. }
  135. else {
  136. AfxMessageBox (IDS_ERR_RULE_NO_FILESPEC, RS_MB_ERROR);
  137. }
  138. }
  139. else {
  140. AfxMessageBox (IDS_ERR_RULE_NO_PATH, RS_MB_ERROR);
  141. }
  142. }