mrDarker
2025-09-05 2cd08ebfa438de28261f35f13527d23e8e469dee
SourceCode/Bond/Servo/PageLog.cpp
@@ -20,8 +20,9 @@
   m_hbrBkgnd = nullptr;
   m_pObserver = nullptr;
   m_nLevel = 0;
   m_strIncludeText = _T("");
   m_bIncludeRegex = FALSE;
   m_strFilterText = _T("");
   m_bRegex = FALSE;
   m_filterMode = FilterMode::Include;
}
CPageLog::~CPageLog()
@@ -40,7 +41,6 @@
BEGIN_MESSAGE_MAP(CPageLog, CDialogEx)
   ON_WM_CTLCOLOR()
   ON_WM_SIZE()
   ON_WM_TIMER()
   ON_WM_DESTROY()
   ON_WM_CLOSE()
   ON_NOTIFY(BLBUTTON_MENU_ITEM_CLICKED, IDC_BUTTON_LEVEL, &CPageLog::OnButtonLevelMenuClicked)
@@ -71,19 +71,29 @@
               && pAny->getIntValue("exCode", level)) {
               if (level >= m_nLevel) {
                  CString strText = pszLogMsg;
                  BOOL bInclude = TRUE;
                  if (!m_strIncludeText.IsEmpty()) {
                     if (!m_bIncludeRegex) {
                        bInclude = (strText.Find(m_strIncludeText) >= 0);
                  BOOL bMatch = TRUE;
                  if (!m_strFilterText.IsEmpty()) {
                     if (!m_bRegex) {
                        bMatch = (strText.Find(m_strFilterText) >= 0);
                     }
                     else {
                        bInclude = std::regex_search((LPTSTR)(LPCTSTR)strText,
                           std::regex((LPTSTR)(LPCTSTR)m_strIncludeText));
                        CString strTemp = strText;
                        strTemp.TrimRight();
                        try {
                           bMatch = std::regex_match((LPTSTR)(LPCTSTR)strTemp,
                              std::regex((LPTSTR)(LPCTSTR)m_strFilterText));
                        }
                        catch (const std::regex_error& e) {
                        }
                     }
                     if (m_filterMode == FilterMode::Exclude) {
                        bMatch = !bMatch;
                     }
                  }
                  if (bInclude) {
                  if (bMatch) {
                     strText.Replace("\n", "\r\n");
                     AppendLog(level, (LPTSTR)(LPCTSTR)strText);
                  }
@@ -106,14 +116,17 @@
BOOL CPageLog::OnInitDialog()
{
   CDialogEx::OnInitDialog();
   SetTimer(1, 3000, nullptr);
   InitRxWindow();
   // 缓存
   m_nLevel = theApp.m_model.m_configuration.getLogcatLevel();
   theApp.m_model.m_configuration.getLogcatIncludeText(m_strIncludeText);
   m_bIncludeRegex = theApp.m_model.m_configuration.isLogcatIncludeRegex();
   theApp.m_model.m_configuration.getLogcatIncludeText(m_strFilterText);
   m_bRegex = theApp.m_model.m_configuration.isLogcatIncludeRegex();
   theApp.m_model.m_configuration.getCustomLogcatIncludeTexts(m_customIncludeTexts);
   m_customIncludeTexts.clear();
   m_customIncludeTexts.push_back("包含");
   m_customIncludeTexts.push_back("排除");
   // Level
@@ -136,6 +149,9 @@
      strIcon1, IMAGE_ICON, 24, 24,
      LR_LOADFROMFILE | LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
   m_btnInclude.SetIcon(hIcon, hIcon, 24);
   m_filterMode = (FilterMode)theApp.m_model.m_configuration.getFilterMode();
   m_btnInclude.SetTextRight();
   m_btnInclude.SetWindowText(m_filterMode == FilterMode::Include ? "包含" : "排除");
   {
      HMENU hMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCEA(IDR_MENU_INCLUDE));
@@ -144,22 +160,20 @@
      int i = 0;
      for (auto& item : m_customIncludeTexts) {
         i++;
         InsertMenu(hSubMenu, 0, MF_BYPOSITION, 0x1998 + i, item.c_str());
         InsertMenu(hSubMenu, i, MF_BYPOSITION, 0x1998 + i, item.c_str());
         m_btnInclude.SetMenu(hMenu);
      }
   }
   SetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
   SetDlgItemText(IDC_EDIT_INCLUDE, m_strFilterText);
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   pCheckBox->SetCheck(m_bIncludeRegex ? BST_CHECKED : BST_UNCHECKED);
   pCheckBox->SetCheck(m_bRegex ? BST_CHECKED : BST_UNCHECKED);
   // 内容
   m_logEdit.SetMaxLineCount(500);
   m_logEdit.SetMaxLineCount(6000);
   m_logEdit.SetLimitText(-1);
   Resize();
@@ -172,14 +186,6 @@
   CDialogEx::OnSize(nType, cx, cy);
   if (GetDlgItem(IDC_EDIT_LOG) == nullptr) return;
   Resize();
}
void CPageLog::OnTimer(UINT_PTR nIDEvent)
{
   if (1 == nIDEvent) {
      KillTimer(1);
      InitRxWindow();
   }
}
void CPageLog::Resize()
@@ -301,28 +307,22 @@
void CPageLog::OnButtonIncludeMenuClicked(NMHDR* pNMHDR, LRESULT* pResult)
{
   BLBUTTON_NMHDR* pblbNmhdr = reinterpret_cast<BLBUTTON_NMHDR*>(pNMHDR);
   int position = (int)pblbNmhdr->dwData;
   std::string& strInclude = m_customIncludeTexts.at(position);
   SetDlgItemText(IDC_EDIT_INCLUDE, strInclude.c_str());
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   m_bIncludeRegex = FALSE;
   pCheckBox->SetCheck(BST_UNCHECKED);
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
   m_filterMode = (FilterMode)pblbNmhdr->dwData;
   theApp.m_model.m_configuration.setFilterMode((int)m_filterMode);
   m_btnInclude.SetWindowText(m_filterMode == FilterMode::Include ? "包含" : "排除");
   *pResult = 0;
}
void CPageLog::OnEnChangeEditInclude()
{
   GetDlgItemText(IDC_EDIT_INCLUDE, m_strIncludeText);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strIncludeText);
   GetDlgItemText(IDC_EDIT_INCLUDE, m_strFilterText);
   theApp.m_model.m_configuration.setLogcatIncludeText(m_strFilterText);
}
void CPageLog::OnBnClickedCheckRegex()
{
   CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_REGEX);
   m_bIncludeRegex = pCheckBox->GetCheck();
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bIncludeRegex);
   m_bRegex = pCheckBox->GetCheck();
   theApp.m_model.m_configuration.setLogcatIncludeRegex(m_bRegex);
}