Просмотр исходного кода

implimented regex filter of clips to exclude clips from getting into ditto that match a regulare expression

Scott Brogden 8 лет назад
Родитель
Сommit
0383e2dc84
16 измененных файлов с 280 добавлено и 60 удалено
  1. 32 32
      AdvGeneral.cpp
  2. 0 1
      CP_Main.rc
  3. 2 0
      CP_Main.vcxproj
  4. 2 0
      CP_Main.vcxproj.filters
  5. 34 6
      Clip.cpp
  6. 1 1
      Clip.h
  7. 15 12
      ClipboardViewer.cpp
  8. 1 0
      ClipboardViewer.h
  9. 5 5
      CopyThread.cpp
  10. 1 1
      CopyThread.h
  11. 1 1
      MainFrm.cpp
  12. 13 0
      Options.cpp
  13. 2 0
      Options.h
  14. 0 1
      OptionsSheet.h
  15. 123 0
      RegExFilterHelper.cpp
  16. 48 0
      RegExFilterHelper.h

+ 32 - 32
AdvGeneral.cpp

@@ -162,36 +162,36 @@ BOOL CAdvGeneral::OnInitDialog()
 	CString processFilterDesc = _T("Process making the copy first must match this before the Regex filter will be applied (separate multiples by ;)");
 	CString regexFilterDesc = _T("If copied text matches this regular expression then the clip will not be saved to Ditto");
 
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 1 Regex"), CGetSetOptions::GetRegexFilter(1), regexFilterDesc, SETTING_REGEX_FILTERING_1));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 1 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(1), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_1));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 2 Regex"), CGetSetOptions::GetRegexFilter(2), regexFilterDesc, SETTING_REGEX_FILTERING_2));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 2 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(2), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_2));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 3 Regex"), CGetSetOptions::GetRegexFilter(3), regexFilterDesc, SETTING_REGEX_FILTERING_3));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 3 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(3), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_3));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 4 Regex"), CGetSetOptions::GetRegexFilter(4), regexFilterDesc, SETTING_REGEX_FILTERING_4));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 4 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(4), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_4));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 5 Regex"), CGetSetOptions::GetRegexFilter(5), regexFilterDesc, SETTING_REGEX_FILTERING_5));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 5 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(5), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_5));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 6 Regex"), CGetSetOptions::GetRegexFilter(6), regexFilterDesc, SETTING_REGEX_FILTERING_6));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 6 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(6), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_6));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 7 Regex"), CGetSetOptions::GetRegexFilter(7), regexFilterDesc, SETTING_REGEX_FILTERING_7));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 7 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(7), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_7));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 8 Regex"), CGetSetOptions::GetRegexFilter(8), regexFilterDesc, SETTING_REGEX_FILTERING_8));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 8 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(8), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_8));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 9 Regex"), CGetSetOptions::GetRegexFilter(9), regexFilterDesc, SETTING_REGEX_FILTERING_9));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 9 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(9), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_9));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 10 Regex"), CGetSetOptions::GetRegexFilter(10), regexFilterDesc, SETTING_REGEX_FILTERING_10));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 10 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(10), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_10));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 11 Regex"), CGetSetOptions::GetRegexFilter(11), regexFilterDesc, SETTING_REGEX_FILTERING_11));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 11 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(11), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_11));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 12 Regex"), CGetSetOptions::GetRegexFilter(12), regexFilterDesc, SETTING_REGEX_FILTERING_12));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 12 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(12), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_12));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 13 Regex"), CGetSetOptions::GetRegexFilter(13), regexFilterDesc, SETTING_REGEX_FILTERING_13));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 13 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(13), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_13));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 14 Regex"), CGetSetOptions::GetRegexFilter(14), regexFilterDesc, SETTING_REGEX_FILTERING_14));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 14 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(14), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_14));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 15 Regex"), CGetSetOptions::GetRegexFilter(15), regexFilterDesc, SETTING_REGEX_FILTERING_15));
-	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 15 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(15), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_14));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 1 Regex"), CGetSetOptions::GetRegexFilter(0), regexFilterDesc, SETTING_REGEX_FILTERING_1));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 1 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(0), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_1));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 2 Regex"), CGetSetOptions::GetRegexFilter(1), regexFilterDesc, SETTING_REGEX_FILTERING_2));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 2 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(1), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_2));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 3 Regex"), CGetSetOptions::GetRegexFilter(2), regexFilterDesc, SETTING_REGEX_FILTERING_3));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 3 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(2), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_3));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 4 Regex"), CGetSetOptions::GetRegexFilter(3), regexFilterDesc, SETTING_REGEX_FILTERING_4));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 4 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(3), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_4));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 5 Regex"), CGetSetOptions::GetRegexFilter(4), regexFilterDesc, SETTING_REGEX_FILTERING_5));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 5 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(4), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_5));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 6 Regex"), CGetSetOptions::GetRegexFilter(5), regexFilterDesc, SETTING_REGEX_FILTERING_6));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 6 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(5), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_6));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 7 Regex"), CGetSetOptions::GetRegexFilter(6), regexFilterDesc, SETTING_REGEX_FILTERING_7));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 7 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(6), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_7));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 8 Regex"), CGetSetOptions::GetRegexFilter(7), regexFilterDesc, SETTING_REGEX_FILTERING_8));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 8 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(7), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_8));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 9 Regex"), CGetSetOptions::GetRegexFilter(8), regexFilterDesc, SETTING_REGEX_FILTERING_9));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 9 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(8), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_9));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 10 Regex"), CGetSetOptions::GetRegexFilter(9), regexFilterDesc, SETTING_REGEX_FILTERING_10));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 10 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(9), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_10));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 11 Regex"), CGetSetOptions::GetRegexFilter(10), regexFilterDesc, SETTING_REGEX_FILTERING_11));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 11 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(10), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_11));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 12 Regex"), CGetSetOptions::GetRegexFilter(11), regexFilterDesc, SETTING_REGEX_FILTERING_12));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 12 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(11), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_12));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 13 Regex"), CGetSetOptions::GetRegexFilter(12), regexFilterDesc, SETTING_REGEX_FILTERING_13));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 13 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(12), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_13));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 14 Regex"), CGetSetOptions::GetRegexFilter(13), regexFilterDesc, SETTING_REGEX_FILTERING_14));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 14 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(13), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_14));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 15 Regex"), CGetSetOptions::GetRegexFilter(14), regexFilterDesc, SETTING_REGEX_FILTERING_15));
+	regexFilterGroup->AddSubItem(new CMFCPropertyGridProperty(_T("Filter 15 By Process Name"), CGetSetOptions::GetRegexFilterByProcessName(14), processFilterDesc, SETTING_REGEX_FILTERING_BY_PROCESS_NAME_14));
 
 	regexFilterGroup->Expand(FALSE);
 
@@ -517,7 +517,7 @@ void CAdvGeneral::OnBnClickedOk()
 			case SETTING_REGEX_FILTERING_15:
 				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
 				{
-					CGetSetOptions::SetRegexFilter(pNewValue->bstrVal, (((int)prop->GetData()) - SETTING_REGEX_FILTERING_1) + 1);
+					CGetSetOptions::SetRegexFilter(pNewValue->bstrVal, (((int)prop->GetData()) - SETTING_REGEX_FILTERING_1));
 				}
 				break;
 			case SETTING_REGEX_FILTERING_BY_PROCESS_NAME_1:
@@ -537,7 +537,7 @@ void CAdvGeneral::OnBnClickedOk()
 			case SETTING_REGEX_FILTERING_BY_PROCESS_NAME_15:
 				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
 				{
-					CGetSetOptions::SetRegexFilterByProcessName(pNewValue->bstrVal, (((int)prop->GetData()) - SETTING_REGEX_FILTERING_BY_PROCESS_NAME_1) + 1);
+					CGetSetOptions::SetRegexFilterByProcessName(pNewValue->bstrVal, (((int)prop->GetData()) - SETTING_REGEX_FILTERING_BY_PROCESS_NAME_1));
 				}
 				break;
 			}

+ 0 - 1
CP_Main.rc

@@ -391,7 +391,6 @@ BEGIN
             END
             POPUP "First Ten Hot Keys"
             BEGIN
-                MENUITEM "Use Ctrl - Num",              32777
                 MENUITEM "Show Hot Key Text",           32778
             END
             POPUP "View Caption Bar On"

+ 2 - 0
CP_Main.vcxproj

@@ -659,6 +659,7 @@
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
     </ClCompile>
     <ClCompile Include="QuickPasteKeyboard.cpp" />
+    <ClCompile Include="RegExFilterHelper.cpp" />
     <ClCompile Include="ScrollHelper.cpp" />
     <ClCompile Include="Shared\TextConvert.cpp" />
     <ClCompile Include="Shared\Tokenizer.cpp" />
@@ -1921,6 +1922,7 @@
     <ClInclude Include="QRCode\rsecc.h" />
     <ClInclude Include="QRCode\split.h" />
     <ClInclude Include="QuickPasteKeyboard.h" />
+    <ClInclude Include="RegExFilterHelper.h" />
     <ClInclude Include="RichEditCtrlEx.h" />
     <ClInclude Include="ScrollHelper.h" />
     <ClInclude Include="SearchEditBox.h" />

+ 2 - 0
CP_Main.vcxproj.filters

@@ -432,6 +432,7 @@
     <ClCompile Include="DimWnd.cpp" />
     <ClCompile Include="SymbolEdit.cpp" />
     <ClCompile Include="AdvGeneral.cpp" />
+    <ClCompile Include="RegExFilterHelper.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="sqlite\CppSQLite3.h">
@@ -904,6 +905,7 @@
     <ClInclude Include="DimWnd.h" />
     <ClInclude Include="SymbolEdit.h" />
     <ClInclude Include="AdvGeneral.h" />
+    <ClInclude Include="RegExFilterHelper.h" />
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="CP_Main.rc">

+ 34 - 6
Clip.cpp

@@ -286,7 +286,7 @@ bool CClip::AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen, bool setDesc)
 }
 
 // Fills this CClip with the contents of the clipboard.
-bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
+int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore, CString activeApp)
 {
 	COleDataObjectEx oleData;
 	CClipTypes defaultTypes;
@@ -299,7 +299,7 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
 	if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
 	{
 		Log(_T("Clipboard ignore type is on the clipboard, skipping this clipboard change"));
-		return false;
+		return FALSE;
 	}
 
 	//If we are saving a multi paste then delay us connecting to the clipboard
@@ -315,7 +315,7 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
 	{
 		Log(_T("failed to attache to clipboard, skipping this clipboard change"));
 		ASSERT(0); // does this ever happen?
-		return false;
+		return FALSE;
 	}
 	
 	oleData.EnsureClipboardObject();
@@ -360,6 +360,24 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
 		}
 		bIsDescSet = SetDescFromText(cfDesc.m_hgData, true);
 
+		if (activeApp != _T(""))
+		{
+			TCHAR* text = (TCHAR *)GlobalLock(cfDesc.m_hgData);
+			if (text != NULL)
+			{
+				std::wstring stringData(text);
+				GlobalUnlock(cfDesc.m_hgData);
+				if (g_Opt.m_regexHelper.TextMatchFilters(activeApp, stringData))
+				{
+					return -1;
+				}
+			}
+			else
+			{
+				GlobalUnlock(cfDesc.m_hgData);
+			}
+		}
+
 		Log(StrF(_T("Tried to set description from cf_unicode text, Set: %d, Desc: [%s]"), bIsDescSet, m_Desc.Left(30)));
 	}
 
@@ -439,7 +457,7 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
 					Log(cs);
 
 					oleData.Release();
-					return false;
+					return -1;
 				}
 
 				ASSERT(::IsValid(cf.m_hgData));
@@ -478,14 +496,24 @@ bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
 	}
 	
 	oleData.Release();
+
+	if (!bIsDescSet &&
+		this->m_Desc != _T(""))
+	{
+		std::wstring stringData(this->m_Desc);
+		if (g_Opt.m_regexHelper.TextMatchFilters(activeApp, stringData))
+		{
+			return -1;
+		}
+	}
 	
 	if(m_Formats.GetSize() == 0)
 	{
 		Log(_T("No clip types were in supported types array"));
-		return false;
+		return FALSE;
 	}
 
-	return true;
+	return TRUE;
 }
 
 bool CClip::SetDescFromText(HGLOBAL hgData, bool unicode)

+ 1 - 1
Clip.h

@@ -126,7 +126,7 @@ public:
 	void Clear();
 	void EmptyFormats();
 	bool AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen, bool setDesc = false);
-	bool LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore = true);
+	int LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore = true, CString activeApp = _T(""));
 	bool SetDescFromText(HGLOBAL hgData, bool unicode);
 	bool SetDescFromType();
 	bool AddToDB(bool bCheckForDuplicates = true);

+ 15 - 12
ClipboardViewer.cpp

@@ -292,7 +292,7 @@ void CClipboardViewer::OnDrawClipboard()
 
 bool CClipboardViewer::ValidActiveWnd()
 {
-	CString activeApp = _T("");
+	m_activeWindow = _T("");
 
 	HWND owner = ::GetClipboardOwner();
 	if (owner != NULL)
@@ -302,21 +302,22 @@ bool CClipboardViewer::ValidActiveWnd()
 
 		if (PID != 0)
 		{
-			activeApp = GetProcessName(NULL, PID);
+			m_activeWindow = GetProcessName(NULL, PID);
 		}
 	}
 
-	if (activeApp == _T(""))
+	//L"RuntimeBroker.exe" is what all modern apps report as
+	if (m_activeWindow == _T(""))
 	{
 		HWND active = ::GetForegroundWindow();
-		activeApp = GetProcessName(active, 0);
+		m_activeWindow = GetProcessName(active, 0);
 	}
 
-	activeApp = activeApp.MakeLower();
+	m_activeWindow = m_activeWindow.MakeLower();
 
 	CString includeApps = CGetSetOptions::GetCopyAppInclude().MakeLower();
 
-	Log(StrF(_T("INCLUDE app names: %s, Active App: %s"), includeApps, activeApp));
+	Log(StrF(_T("INCLUDE app names: %s, Active App: %s"), includeApps, m_activeWindow));
 
 	bool tokenMatch = false;
 
@@ -327,9 +328,9 @@ bool CClipboardViewer::ValidActiveWnd()
 	{
 		if(line != "")
 		{
-			if(CWildCardMatch::WildMatch(line, activeApp, ""))
+			if(CWildCardMatch::WildMatch(line, m_activeWindow, ""))
 			{
-				Log(StrF(_T("Inlclude app names Found Match %s - %s"), line, activeApp));
+				Log(StrF(_T("Inlclude app names Found Match %s - %s"), line, m_activeWindow));
 
 				tokenMatch = true;
 				break;
@@ -343,7 +344,7 @@ bool CClipboardViewer::ValidActiveWnd()
 
 		if(excludeApps != "")
 		{
-			Log(StrF(_T("EXCLUDE app names %s, Active App: %s"), excludeApps, activeApp));
+			Log(StrF(_T("EXCLUDE app names %s, Active App: %s"), excludeApps, m_activeWindow));
 
 			CTokenizer token2(excludeApps, CGetSetOptions::GetCopyAppSeparator());
 			CString line2;
@@ -351,9 +352,9 @@ bool CClipboardViewer::ValidActiveWnd()
 			{
 				if(line2 != "")
 				{
-					if(CWildCardMatch::WildMatch(line2, activeApp, ""))
+					if(CWildCardMatch::WildMatch(line2, m_activeWindow, ""))
 					{
-						Log(StrF(_T("Exclude app names Found Match %s - %s - NOT SAVING COPY"), line2, activeApp));
+						Log(StrF(_T("Exclude app names Found Match %s - %s - NOT SAVING COPY"), line2, m_activeWindow));
 
 						return false;
 					}
@@ -390,7 +391,7 @@ void CClipboardViewer::OnTimer(UINT_PTR nIDEvent)
 				{
 					Log(StrF(_T("OnDrawClipboard::OnTimer %d"), dwNow));
 
-					m_pHandler->OnClipboardChange();
+					m_pHandler->OnClipboardChange(m_activeWindow);
 
 					m_dwLastCopy = dwNow;
 				}
@@ -399,6 +400,8 @@ void CClipboardViewer::OnTimer(UINT_PTR nIDEvent)
 			{
 				Log(StrF(_T("Clip copy to fast difference from last copy = %d"), (dwNow - m_dwLastCopy)));
 			}
+
+			m_activeWindow = _T("");
 		}
 		break;
 

+ 1 - 0
ClipboardViewer.h

@@ -32,6 +32,7 @@ public:
 	bool	m_bConnect;
 	bool	m_bIsConnected;
 	bool	m_connectOnStartup;
+	CString m_activeWindow;
 
 	// m_pHandler->OnClipboardChange is called when the clipboard changes.
 	CCopyThread*	m_pHandler;

+ 5 - 5
CopyThread.cpp

@@ -51,7 +51,7 @@ int CCopyThread::ExitInstance()
 }
 
 // Called within Copy Thread:
-void CCopyThread::OnClipboardChange()
+void CCopyThread::OnClipboardChange(CString activeWindow)
 {
 	Log(_T("OnClipboardChange - Start"));
 
@@ -107,10 +107,10 @@ void CCopyThread::OnClipboardChange()
 	}
 
 	Log(_T("LoadFromClipboard - Before"));
-	bool bResult = pClip->LoadFromClipboard(pSupportedTypes);
+	int bResult = pClip->LoadFromClipboard(pSupportedTypes, true, activeWindow);
 	Log(_T("LoadFromClipboard - After"));
 
-	if(!bResult)
+	if(bResult == FALSE)
 	{
 		DWORD delay = CGetSetOptions::GetNoFormatsRetryDelay();
 		if(delay > 0)
@@ -119,7 +119,7 @@ void CCopyThread::OnClipboardChange()
 			Sleep(delay);
 
 			Log(_T("LoadFromClipboard #2 - Before"));
-			bResult = pClip->LoadFromClipboard(pSupportedTypes);
+			bResult = pClip->LoadFromClipboard(pSupportedTypes, activeWindow);
 			Log(_T("LoadFromClipboard #2 - After"));
 		}
 		else
@@ -134,7 +134,7 @@ void CCopyThread::OnClipboardChange()
 		pSupportedTypes = NULL;
 	}
 	
-	if(!bResult)
+	if(bResult != TRUE)
 	{
 		delete pClip;
 		return; // error

+ 1 - 1
CopyThread.h

@@ -62,7 +62,7 @@ public:
 	CCopyConfig         m_LocalConfig;
 
 	// Called within Copy Thread:
-	void OnClipboardChange(); // called by ClipboardViewer
+	void OnClipboardChange(CString activeWindow); // called by ClipboardViewer
 	void SyncConfig(); // safely syncs m_LocalConfig with m_SharedConfig
 
 // Shared (use thread-safe access functions below)

+ 1 - 1
MainFrm.cpp

@@ -1232,7 +1232,7 @@ void CMainFrame::OnFirstSavecurrentclipboard()
 		CClipTypes* pTypes = theApp.LoadTypesFromDB();
 		if(pTypes)
 		{
-			if(pClip->LoadFromClipboard(pTypes, false))
+			if(pClip->LoadFromClipboard(pTypes, false, _T("")))
 			{
 				Log(_T("Loaded clips from the clipboard, sending message to save to the db"));
 				::PostMessage(m_hWnd, WM_CLIPBOARD_COPIED, (WPARAM)pClip, 0);

+ 13 - 0
Options.cpp

@@ -66,6 +66,7 @@ CTheme CGetSetOptions::m_Theme;
 BOOL CGetSetOptions::m_showScrollBar = false;
 CGetSetOptions g_Opt;
 BOOL CGetSetOptions::m_bShowAlwaysOnTopWarning = TRUE;
+CRegExFilterHelper CGetSetOptions::m_regexHelper;
 
 CGetSetOptions::CGetSetOptions()
 {
@@ -184,6 +185,14 @@ void CGetSetOptions::LoadSettings()
 		GetSendClients(i);
 	}
 
+	for (int i = 0; i < MAX_REGEX_FILTERS; i++)
+	{
+		CRegExFilterData data;
+		data.m_regEx = GetRegexFilter(i);
+		data.m_processFilters = GetRegexFilterByProcessName(i);
+		m_regexHelper.Add(i, data);
+	}
+
 	GetClientSendCount();
 
 	m_Theme.Load(GetTheme());
@@ -2440,6 +2449,8 @@ void CGetSetOptions::SetRegexFilter(CString val, int pos)
 	CString cs;
 	cs.Format(_T("RegexFilter_%d"), pos);
 
+	m_regexHelper.SetRegEx(pos, std::wstring(val));
+
 	SetProfileString(cs, val);
 }
 
@@ -2455,6 +2466,8 @@ void CGetSetOptions::SetRegexFilterByProcessName(CString val, int pos)
 	CString cs;
 	cs.Format(_T("RegexFilterByProcessName_%d"), pos);
 
+	m_regexHelper.SetProcessFilter(pos, val);
+
 	SetProfileString(cs, val);
 }
 

+ 2 - 0
Options.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include "Theme.h"
+#include "RegExFilterHelper.h"
 
 #define MAX_SEND_CLIENTS	15
 class CSendClients
@@ -556,6 +557,7 @@ public:
 	static int GetErrorMsgPopupTimeout();
 	static void SetErrorMsgPopupTimeout(int val);
 
+	static CRegExFilterHelper m_regexHelper;
 	static void		SetRegexFilter(CString val, int pos);
 	static CString	GetRegexFilter(int pos);
 

+ 0 - 1
OptionsSheet.h

@@ -8,7 +8,6 @@
 //
 //#include "ShowTaskBarIcon.h"
 
-#include "CBPropertySheet.h"
 
 /////////////////////////////////////////////////////////////////////////////
 // COptionsSheet

+ 123 - 0
RegExFilterHelper.cpp

@@ -0,0 +1,123 @@
+#include "stdafx.h"
+#include "CP_Main.h"
+#include "RegExFilterHelper.h"
+#include "Shared\Tokenizer.h"
+#include "Options.h"
+#include "WildCardMatch.h"
+
+#include <regex>
+#include <string>
+
+void CRegExFilterData::ParseFilters()
+{
+	m_parsedProcessFilters.RemoveAll();
+
+	CTokenizer token(m_processFilters, CGetSetOptions::GetCopyAppSeparator());
+	CString line;
+
+	while (token.Next(line))
+	{
+		if (line != "")
+		{
+			m_parsedProcessFilters.Add(line);
+		}
+	}
+}
+
+bool CRegExFilterData::MatchesProcessFilters(CString &activeApp)
+{
+	if (activeApp == _T(""))
+	{
+		return true;
+	}
+
+	int count = m_parsedProcessFilters.GetCount();
+
+	if (count == 0)
+	{
+		return true;
+	}
+
+	for (int i = 0; i < count; i++)
+	{
+		if (CWildCardMatch::WildMatch(m_parsedProcessFilters[i], activeApp, ""))
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
+bool CRegExFilterData::MatchesRegEx(std::wstring &copiedText)
+{
+	//std::wregex integer(_T("(\\+|-)?[[:digit:]]+"));
+	//std::wstring input(copiedText);
+	if (m_regEx != _T(""))
+	{
+		std::wregex integer(m_regEx);
+		if (regex_match(copiedText, integer))
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
+
+CRegExFilterHelper::CRegExFilterHelper()
+{
+}
+
+
+CRegExFilterHelper::~CRegExFilterHelper()
+{
+}
+
+void CRegExFilterHelper::Add(int pos, CRegExFilterData &data)
+{
+	if (pos >= 0 && pos < MAX_REGEX_FILTERS)
+	{
+		ATL::CCritSecLock csLock(m_critSection.m_sect);
+		m_filters[pos] = data;
+	}
+}
+
+void CRegExFilterHelper::SetRegEx(int pos, std::wstring regEx)
+{
+	if (pos >= 0 && pos < MAX_REGEX_FILTERS)
+	{
+		ATL::CCritSecLock csLock(m_critSection.m_sect);
+		m_filters[pos].m_regEx = regEx;
+	}
+}
+
+void CRegExFilterHelper::SetProcessFilter(int pos, CString processName)
+{
+	if (pos >= 0 && pos < MAX_REGEX_FILTERS)
+	{
+		ATL::CCritSecLock csLock(m_critSection.m_sect);
+		m_filters[pos].m_processFilters = processName;
+		m_filters[pos].ParseFilters();
+	}
+}
+
+bool CRegExFilterHelper::TextMatchFilters(CString &activeApp, std::wstring &copiedText)
+{
+	ATL::CCritSecLock csLock(m_critSection.m_sect);
+
+	for (int i = 0; i < MAX_REGEX_FILTERS; i++)
+	{
+		if (m_filters[i].MatchesProcessFilters(activeApp))
+		{
+			if (m_filters[i].MatchesRegEx(copiedText))
+			{
+				Log(StrF(_T("regex matches copied text NOT SAVING CLIP, regex: %s, text: %s, active app: %s"), m_filters[i].m_regEx.c_str(), copiedText.c_str(), activeApp));
+				return true;
+			}
+		}
+	}
+
+	return false;
+}

+ 48 - 0
RegExFilterHelper.h

@@ -0,0 +1,48 @@
+#pragma once
+
+#include <vector>
+#include <string>
+
+#define MAX_REGEX_FILTERS 15
+
+class CRegExFilterData
+{
+public:
+	std::wstring m_regEx;
+	CString m_processFilters;
+	CStringArray m_parsedProcessFilters;
+
+	void ParseFilters();
+
+	bool MatchesProcessFilters(CString &activeApp);
+	bool MatchesRegEx(std::wstring &copiedText);
+
+	const CRegExFilterData& operator=(const CRegExFilterData &clip)
+	{
+		m_regEx = clip.m_regEx;
+		m_processFilters = clip.m_processFilters;
+
+		ParseFilters();
+		
+		return *this;
+	}
+};
+
+class CRegExFilterHelper
+{
+public:
+	CRegExFilterHelper();
+	~CRegExFilterHelper();
+
+	void Add(int pos, CRegExFilterData &data);
+	void SetRegEx(int pos, std::wstring regEx);
+	void SetProcessFilter(int pos, CString processName);
+
+	CRegExFilterData m_filters[MAX_REGEX_FILTERS];
+
+	bool TextMatchFilters(CString &activeApp, std::wstring &copiedText);
+
+private:
+	CCriticalSection m_critSection;
+};
+