Преглед изворни кода

Added application names to include/exclude from saving copies from

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@559 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden пре 14 година
родитељ
комит
d8a17eb0dd
11 измењених фајлова са 597 додато и 309 уклоњено
  1. 7 2
      CP_Main.rc
  2. 2 0
      CP_Main.vcxproj
  3. 371 304
      ClipboardViewer.cpp
  4. 1 0
      ClipboardViewer.h
  5. 6 0
      Debug/Language/English.xml
  6. 31 0
      Options.cpp
  7. 8 0
      Options.h
  8. 16 3
      OptionsGeneral.cpp
  9. 2 0
      OptionsGeneral.h
  10. 143 0
      WildCardMatch.cpp
  11. 10 0
      WildCardMatch.h

+ 7 - 2
CP_Main.rc

@@ -455,7 +455,7 @@ BEGIN
     LTEXT           "Text Only Paste",IDC_STATIC_ACTIVATE2,19,33,71,14,SS_CENTERIMAGE
 END
 
-IDD_OPTIONS_GENERAL DIALOGEX 0, 0, 351, 259
+IDD_OPTIONS_GENERAL DIALOGEX 0, 0, 351, 281
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "General"
 FONT 8, "MS Shell Dlg", 0, 0, 0x0
@@ -499,6 +499,11 @@ BEGIN
     LTEXT           "Days",IDC_STATIC_DAYS,201,53,51,12,SS_CENTERIMAGE
     CONTROL         "Set Database Path",IDC_SET_DB_PATH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,79,320,10
     LTEXT           "Language",IDC_STATIC_LANGUAGE,23,65,36,12,SS_CENTERIMAGE
+    LTEXT           "Include",IDC_STATIC_INCLUDE_APPS,28,254,36,13,SS_CENTERIMAGE
+    LTEXT           "Exclude",IDC_STATIC_EXCLUDE_APPS,188,254,31,13,SS_CENTERIMAGE
+    EDITTEXT        IDC_EDIT_APP_COPY_INCLUDE,60,254,123,13,ES_AUTOHSCROLL
+    EDITTEXT        IDC_EDIT_APP_COPY_EXCLUDE,221,254,119,13,ES_AUTOHSCROLL
+    GROUPBOX        "Accepted Copy Applications (seperate by ;)",IDC_STATIC_APP_SEP_DESC,22,242,321,32
 END
 
 IDD_SELECT_DB DIALOGEX 0, 0, 276, 46
@@ -801,7 +806,7 @@ BEGIN
         LEFTMARGIN, 7
         RIGHTMARGIN, 344
         TOPMARGIN, 7
-        BOTTOMMARGIN, 254
+        BOTTOMMARGIN, 276
     END
 
     IDD_SELECT_DB, DIALOG

+ 2 - 0
CP_Main.vcxproj

@@ -1152,6 +1152,7 @@
       <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Unicode Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Unicode Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
     </ClCompile>
+    <ClCompile Include="WildCardMatch.cpp" />
     <ClCompile Include="WndEx.cpp">
       <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Disabled</Optimization>
       <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@@ -1310,6 +1311,7 @@
     <ClInclude Include="Shared\TextConvert.h" />
     <ClInclude Include="Shared\Tokenizer.h" />
     <ClInclude Include="ToolTipEx.h" />
+    <ClInclude Include="WildCardMatch.h" />
     <ClInclude Include="WndEx.h" />
     <ClInclude Include="Client.h" />
     <ClInclude Include="FileRecieve.h" />

+ 371 - 304
ClipboardViewer.cpp

@@ -1,305 +1,372 @@
-// ClipboardViewer.cpp : implementation file
-//
-
-#include "stdafx.h"
-#include "cp_main.h"
-#include "ClipboardViewer.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-// CClipboardViewer
-
-CClipboardViewer::CClipboardViewer(CCopyThread* pHandler) :
-	m_hNextClipboardViewer(0),
-	m_bCalling_SetClipboardViewer(false),
-	m_pHandler(pHandler),
-	m_bPinging(false),
-	m_bHandlingClipChange(false),
-	m_bIsConnected(false),
-	m_bConnect(false),
-	m_dwLastCopy(0),
-	m_connectOnStartup(true)
-{
-
-}
-
-CClipboardViewer::~CClipboardViewer()
-{
-}
-
-
-BEGIN_MESSAGE_MAP(CClipboardViewer, CWnd)
-	//{{AFX_MSG_MAP(CClipboardViewer)
-	ON_WM_CREATE()
-	ON_WM_CHANGECBCHAIN()
-	ON_WM_DRAWCLIPBOARD()
-	ON_WM_TIMER()
-	ON_WM_DESTROY()
-	//}}AFX_MSG_MAP
-	ON_MESSAGE(WM_SETCONNECT, OnSetConnect)
-END_MESSAGE_MAP()
-
-
-/////////////////////////////////////////////////////////////////////////////
-// CClipboardViewer message handlers
-void CClipboardViewer::Create()
-{
-	CString strParentClass = AfxRegisterWndClass(0);
-	CWnd::CreateEx(0, strParentClass, _T("Ditto Clipboard Viewer"), 0, -1, -1, 0, 0, 0, 0);
-
-	if(m_connectOnStartup)
-	{
-		SetConnect(true);
-	}
-}
-
-// connects as a clipboard viewer
-void CClipboardViewer::Connect()
-{
-	Log(_T("Connect to Clipboard"));
-	
-	//Set up the clip board viewer
-	m_bCalling_SetClipboardViewer = true;
-	m_hNextClipboardViewer = CWnd::SetClipboardViewer();
-	m_bCalling_SetClipboardViewer = false;
-	
-	m_bIsConnected = true;
-	m_bConnect = true;
-
-	SetEnsureConnectedTimer();
-}
-
-void CClipboardViewer::SetEnsureConnectedTimer()
-{
-	SetTimer(TIMER_ENSURE_VIEWER_IN_CHAIN, ONE_MINUTE*5, NULL);
-}
-
-// disconnects as a clipboard viewer
-void CClipboardViewer::Disconnect(bool bSendPing)
-{
-	Log(_T("Disconnect From Clipboard"));
-
-	KillTimer(TIMER_ENSURE_VIEWER_IN_CHAIN);
-
-	BOOL bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
-	if(!bRet)
-	{
-		Log(_T("Error disconnecting from clipboard"));
-		bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
-		if(!bRet)
-		{
-			Log(_T("Error disconnecting from clipboard2"));
-		}
-	}
-
-	m_hNextClipboardViewer = 0;
-	m_bConnect = false;
-	m_bIsConnected = false;
-	if(bSendPing)
-		SendPing();
-}
-
-void CClipboardViewer::SendPing()
-{
-	if(g_Opt.m_bEnsureConnectToClipboard)
-	{
-		if(OpenClipboard())
-		{
-			m_bPinging = true;
-			SetClipboardData(theApp.m_PingFormat, NewGlobalP("Ditto Ping", sizeof("Ditto Ping")));
-			SetClipboardData(theApp.m_cfIgnoreClipboard , NewGlobalP("Ignore", sizeof("Ignore")));
-
-			SetTimer(TIMER_PING, 2000, NULL);
-			CloseClipboard();
-		}
-	}
-}
-
-void CClipboardViewer::SetConnect(bool bConnect)
-{
-	m_bConnect = bConnect;
-	if(bConnect)
-	{
-		if(m_bIsConnected == false)
-		{
-			Connect();
-		}
-		else
-		{
-			SendPing();
-		}
-	}
-	else
-	{
-		Disconnect();
-	}
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// CClipboardViewer message handlers
-
-int CClipboardViewer::OnCreate(LPCREATESTRUCT lpCreateStruct)
-{
-	if(CWnd::OnCreate(lpCreateStruct) == -1)
-		return -1;
-	
-	//Set up the clip board viewer
-	if(m_connectOnStartup)
-	{
-		Connect();
-	}
-	
-	return 0;
-}
-
-void CClipboardViewer::OnDestroy()
-{
-	Disconnect();
-	CWnd::OnDestroy();
-}
-
-void CClipboardViewer::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter) 
-{
-	Log(_T("OnChangeCbChain"));
-	
-	// If the next window is closing, repair the chain. 
-	if(m_hNextClipboardViewer == hWndRemove)
-    {
-		m_hNextClipboardViewer = hWndAfter;
-    }
-    // Otherwise, pass the message to the next link.
-	else if (m_hNextClipboardViewer != NULL)
-    {
-		if(m_hNextClipboardViewer != m_hWnd)
-		{
-			::SendMessage(m_hNextClipboardViewer, WM_CHANGECBCHAIN, (WPARAM) hWndRemove, (LPARAM) hWndAfter);
-		}
-		else
-		{
-			m_hNextClipboardViewer = NULL;
-		}
-    }
-}
-
-//Message that the clipboard data has changed
-void CClipboardViewer::OnDrawClipboard() 
-{
-	if(::IsClipboardFormatAvailable(theApp.m_PingFormat))
-	{
-		m_bPinging = false;
-		return;
-	}
-
-	// don't process the event when we first attach
-	if(m_pHandler && !m_bCalling_SetClipboardViewer)
-	{
-		if(m_bIsConnected)
-		{
-			if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
-			{
-				Log(StrF(_T("OnDrawClipboard:: *** SetTimer *** %d"), GetTickCount()));
-				
-				KillTimer(TIMER_DRAW_CLIPBOARD);
-				SetTimer(TIMER_DRAW_CLIPBOARD, g_Opt.m_lProcessDrawClipboardDelay, NULL);		
-			}
-		}
-		else
-		{
-			Log(_T("Not connected, ignore clipboard change"));
-		}
-	}
-
-	// pass the event to the next Clipboard viewer in the chain
-	if(m_hNextClipboardViewer != NULL)
-	{
-		if(m_hNextClipboardViewer != m_hWnd)
-		{
-			::SendMessage(m_hNextClipboardViewer, WM_DRAWCLIPBOARD, 0, 0);	
-		}
-		else
-		{
-			m_hNextClipboardViewer = NULL;
-		}
-	}
-}
-
-void CClipboardViewer::OnTimer(UINT nIDEvent) 
-{
-	switch(nIDEvent)
-	{
-	case TIMER_ENSURE_VIEWER_IN_CHAIN:
-		SendPing();
-		break;
-
-	case TIMER_DRAW_CLIPBOARD:
-		KillTimer(nIDEvent);
-
-		if(m_bHandlingClipChange == false)
-		{
-			m_bHandlingClipChange = true;
-			DWORD dwNow = GetTickCount();
-
-			if(dwNow - m_dwLastCopy > g_Opt.m_dwSaveClipDelay || m_dwLastCopy > dwNow)
-			{
-				if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
-				{
-					Log(StrF(_T("OnDrawClipboard::OnTimer %d"), dwNow));
-
-					m_pHandler->OnClipboardChange();
-
-					m_dwLastCopy = dwNow;
-				}
-			}
-			else
-			{
-				Log(StrF(_T("Clip copy to fast difference from last copy = %d"), (dwNow - m_dwLastCopy)));
-			}
-
-			m_bHandlingClipChange = false;
-		}
-		else
-		{
-			Log(_T("HandlingClipChange is Set, ERROR"));
-		}
-	case TIMER_PING:
-		KillTimer(TIMER_PING);
-
-		//If we haven't received the change clipboard message then we are disconnected
-		//if so reconnect
-		if(m_bPinging)
-		{
-			if(m_bConnect)
-			{
-				Log(_T("Ping Failed Reconnecting to clipboard"));
-				Connect();
-			}
-			else
-			{
-				Log(_T("Ping Failed but Connected set to FALSE so this is ok"));
-			}
-		}
-		else
-		{
-			if(m_bConnect)
-			{
-				m_bIsConnected = true;
-			}
-		}
-
-		break;
-	}
-	
-	CWnd::OnTimer(nIDEvent);
-}
-
-LRESULT CClipboardViewer::OnSetConnect(WPARAM wParam, LPARAM lParam)
-{
-	bool bConnect = wParam == TRUE;
-	SetConnect(bConnect);
-	return TRUE;
+// ClipboardViewer.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "cp_main.h"
+#include "ClipboardViewer.h"
+#include "Misc.h"
+#include "shared/Tokenizer.h"
+#include "WildCardMatch.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CClipboardViewer
+
+CClipboardViewer::CClipboardViewer(CCopyThread* pHandler) :
+	m_hNextClipboardViewer(0),
+	m_bCalling_SetClipboardViewer(false),
+	m_pHandler(pHandler),
+	m_bPinging(false),
+	m_bHandlingClipChange(false),
+	m_bIsConnected(false),
+	m_bConnect(false),
+	m_dwLastCopy(0),
+	m_connectOnStartup(true)
+{
+
+}
+
+CClipboardViewer::~CClipboardViewer()
+{
+}
+
+
+BEGIN_MESSAGE_MAP(CClipboardViewer, CWnd)
+	//{{AFX_MSG_MAP(CClipboardViewer)
+	ON_WM_CREATE()
+	ON_WM_CHANGECBCHAIN()
+	ON_WM_DRAWCLIPBOARD()
+	ON_WM_TIMER()
+	ON_WM_DESTROY()
+	//}}AFX_MSG_MAP
+	ON_MESSAGE(WM_SETCONNECT, OnSetConnect)
+END_MESSAGE_MAP()
+
+
+/////////////////////////////////////////////////////////////////////////////
+// CClipboardViewer message handlers
+void CClipboardViewer::Create()
+{
+	CString strParentClass = AfxRegisterWndClass(0);
+	CWnd::CreateEx(0, strParentClass, _T("Ditto Clipboard Viewer"), 0, -1, -1, 0, 0, 0, 0);
+
+	if(m_connectOnStartup)
+	{
+		SetConnect(true);
+	}
+}
+
+// connects as a clipboard viewer
+void CClipboardViewer::Connect()
+{
+	Log(_T("Connect to Clipboard"));
+	
+	//Set up the clip board viewer
+	m_bCalling_SetClipboardViewer = true;
+	m_hNextClipboardViewer = CWnd::SetClipboardViewer();
+	m_bCalling_SetClipboardViewer = false;
+	
+	m_bIsConnected = true;
+	m_bConnect = true;
+
+	SetEnsureConnectedTimer();
+}
+
+void CClipboardViewer::SetEnsureConnectedTimer()
+{
+	SetTimer(TIMER_ENSURE_VIEWER_IN_CHAIN, ONE_MINUTE*5, NULL);
+}
+
+// disconnects as a clipboard viewer
+void CClipboardViewer::Disconnect(bool bSendPing)
+{
+	Log(_T("Disconnect From Clipboard"));
+
+	KillTimer(TIMER_ENSURE_VIEWER_IN_CHAIN);
+
+	BOOL bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
+	if(!bRet)
+	{
+		Log(_T("Error disconnecting from clipboard"));
+		bRet = CWnd::ChangeClipboardChain(m_hNextClipboardViewer);
+		if(!bRet)
+		{
+			Log(_T("Error disconnecting from clipboard2"));
+		}
+	}
+
+	m_hNextClipboardViewer = 0;
+	m_bConnect = false;
+	m_bIsConnected = false;
+	if(bSendPing)
+		SendPing();
+}
+
+void CClipboardViewer::SendPing()
+{
+	if(g_Opt.m_bEnsureConnectToClipboard)
+	{
+		if(OpenClipboard())
+		{
+			m_bPinging = true;
+			SetClipboardData(theApp.m_PingFormat, NewGlobalP("Ditto Ping", sizeof("Ditto Ping")));
+			SetClipboardData(theApp.m_cfIgnoreClipboard , NewGlobalP("Ignore", sizeof("Ignore")));
+
+			SetTimer(TIMER_PING, 2000, NULL);
+			CloseClipboard();
+		}
+	}
+}
+
+void CClipboardViewer::SetConnect(bool bConnect)
+{
+	m_bConnect = bConnect;
+	if(bConnect)
+	{
+		if(m_bIsConnected == false)
+		{
+			Connect();
+		}
+		else
+		{
+			SendPing();
+		}
+	}
+	else
+	{
+		Disconnect();
+	}
+}
+
+/////////////////////////////////////////////////////////////////////////////
+// CClipboardViewer message handlers
+
+int CClipboardViewer::OnCreate(LPCREATESTRUCT lpCreateStruct)
+{
+	if(CWnd::OnCreate(lpCreateStruct) == -1)
+		return -1;
+	
+	//Set up the clip board viewer
+	if(m_connectOnStartup)
+	{
+		Connect();
+	}
+	
+	return 0;
+}
+
+void CClipboardViewer::OnDestroy()
+{
+	Disconnect();
+	CWnd::OnDestroy();
+}
+
+void CClipboardViewer::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter) 
+{
+	Log(_T("OnChangeCbChain"));
+	
+	// If the next window is closing, repair the chain. 
+	if(m_hNextClipboardViewer == hWndRemove)
+    {
+		m_hNextClipboardViewer = hWndAfter;
+    }
+    // Otherwise, pass the message to the next link.
+	else if (m_hNextClipboardViewer != NULL)
+    {
+		if(m_hNextClipboardViewer != m_hWnd)
+		{
+			::SendMessage(m_hNextClipboardViewer, WM_CHANGECBCHAIN, (WPARAM) hWndRemove, (LPARAM) hWndAfter);
+		}
+		else
+		{
+			m_hNextClipboardViewer = NULL;
+		}
+    }
+}
+
+//Message that the clipboard data has changed
+void CClipboardViewer::OnDrawClipboard() 
+{
+	if(::IsClipboardFormatAvailable(theApp.m_PingFormat))
+	{
+		m_bPinging = false;
+		return;
+	}
+
+	// don't process the event when we first attach
+	if(m_pHandler && !m_bCalling_SetClipboardViewer)
+	{
+		if(m_bIsConnected)
+		{
+			if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
+			{
+				if(ValidActiveWnd())
+				{
+					Log(StrF(_T("OnDrawClipboard:: *** SetTimer *** %d"), GetTickCount()));
+
+					KillTimer(TIMER_DRAW_CLIPBOARD);
+					SetTimer(TIMER_DRAW_CLIPBOARD, g_Opt.m_lProcessDrawClipboardDelay, NULL);		
+				}
+			}
+		}
+		else
+		{
+			Log(_T("Not connected, ignore clipboard change"));
+		}
+	}
+
+	// pass the event to the next Clipboard viewer in the chain
+	if(m_hNextClipboardViewer != NULL)
+	{
+		if(m_hNextClipboardViewer != m_hWnd)
+		{
+			::SendMessage(m_hNextClipboardViewer, WM_DRAWCLIPBOARD, 0, 0);	
+		}
+		else
+		{
+			m_hNextClipboardViewer = NULL;
+		}
+	}
+}
+
+bool CClipboardViewer::ValidActiveWnd()
+{
+	HWND active = ::GetForegroundWindow();
+	CString activeApp = GetProcessName(active).MakeLower();
+
+	CString includeApps = CGetSetOptions::GetCopyAppInclude().MakeLower();
+
+	Log(StrF(_T("INCLUDE app names: %s, Active App: %s"), includeApps, activeApp));
+
+	bool tokenMatch = false;
+
+	CTokenizer token(includeApps, CGetSetOptions::GetCopyAppSeparator());
+	CString line;
+
+	while(token.Next(line))
+	{
+		if(line != "")
+		{
+			if(CWildCardMatch::WildMatch(line, activeApp, ""))
+			{
+				Log(StrF(_T("Inlclude app names Found Match %s - %s"), line, activeApp));
+
+				tokenMatch = true;
+				break;
+			}
+		}
+	}				
+
+	if(tokenMatch)
+	{
+		CString excludeApps = CGetSetOptions::GetCopyAppExclude().MakeLower();
+
+		if(excludeApps != "")
+		{
+			Log(StrF(_T("EXCLUDE app names %s, Active App: %s"), excludeApps, activeApp));
+
+			CTokenizer token2(excludeApps, CGetSetOptions::GetCopyAppSeparator());
+			CString line2;
+			while(token2.Next(line2))
+			{
+				if(line2 != "")
+				{
+					if(CWildCardMatch::WildMatch(line2, activeApp, ""))
+					{
+						Log(StrF(_T("Exclude app names Found Match %s - %s - NOT SAVING COPY"), line2, activeApp));
+
+						return false;
+					}
+				}
+			}
+		}
+	}
+	else
+	{
+		Log(StrF(_T("Didn't find a match to INCLUDE match %s, NOT SAVING COPY"), includeApps));
+		return false;
+	}
+
+	return true;
+}
+
+void CClipboardViewer::OnTimer(UINT nIDEvent) 
+{
+	switch(nIDEvent)
+	{
+	case TIMER_ENSURE_VIEWER_IN_CHAIN:
+		SendPing();
+		break;
+
+	case TIMER_DRAW_CLIPBOARD:
+		KillTimer(nIDEvent);
+
+		if(m_bHandlingClipChange == false)
+		{
+			m_bHandlingClipChange = true;
+			DWORD dwNow = GetTickCount();
+
+			if(dwNow - m_dwLastCopy > g_Opt.m_dwSaveClipDelay || m_dwLastCopy > dwNow)
+			{
+				if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
+				{
+					Log(StrF(_T("OnDrawClipboard::OnTimer %d"), dwNow));
+
+					m_pHandler->OnClipboardChange();
+
+					m_dwLastCopy = dwNow;
+				}
+			}
+			else
+			{
+				Log(StrF(_T("Clip copy to fast difference from last copy = %d"), (dwNow - m_dwLastCopy)));
+			}
+
+			m_bHandlingClipChange = false;
+		}
+		else
+		{
+			Log(_T("HandlingClipChange is Set, ERROR"));
+		}
+	case TIMER_PING:
+		KillTimer(TIMER_PING);
+
+		//If we haven't received the change clipboard message then we are disconnected
+		//if so reconnect
+		if(m_bPinging)
+		{
+			if(m_bConnect)
+			{
+				Log(_T("Ping Failed Reconnecting to clipboard"));
+				Connect();
+			}
+			else
+			{
+				Log(_T("Ping Failed but Connected set to FALSE so this is ok"));
+			}
+		}
+		else
+		{
+			if(m_bConnect)
+			{
+				m_bIsConnected = true;
+			}
+		}
+
+		break;
+	}
+	
+	CWnd::OnTimer(nIDEvent);
+}
+
+LRESULT CClipboardViewer::OnSetConnect(WPARAM wParam, LPARAM lParam)
+{
+	bool bConnect = wParam == TRUE;
+	SetConnect(bConnect);
+	return TRUE;
 }

+ 1 - 0
ClipboardViewer.h

@@ -44,6 +44,7 @@ public:
 	bool GetConnect()				{ return m_bConnect; }
 	void SetConnect(bool bConnect);
 	void SetEnsureConnectedTimer();
+	bool ValidActiveWnd();
 
 	DWORD m_dwLastCopy;
 	bool m_bHandlingClipChange;

+ 6 - 0
Debug/Language/English.xml

@@ -115,6 +115,12 @@
 		<Item English_Text = "Ensure Ditto is always connected to the clipboard" ID = "1042"></Item>
 		<Item English_Text = "General" ID = "-1" PropertyPage = "true"></Item>
 		<Item English_Text = "Multi-Paste clip separator ([LF] = line feed)" ID = "2090"></Item>
+		
+		//New item added 3/1/11
+		<Item English_Text = "Accepted Copy Applications (seperate by ;)" ID = "2098"></Item>
+		<Item English_Text = "Include" ID = "2097"></Item>
+		<Item English_Text = "Exclude" ID = "2096"></Item>
+		
 	</Ditto_Options_General>
 	<Ditto_Options_Supported_Types>
 		<Item English_Text = "&Add" ID = "1015"></Item>

+ 31 - 0
Options.cpp

@@ -1946,4 +1946,35 @@ BOOL CGetSetOptions::GetSetFocusToApp(CString csAppName)
 DWORD CGetSetOptions::SelectedIndex()
 {
 	return (DWORD)GetProfileLong(_T("SelectedIndex"), 0);
+}
+
+void CGetSetOptions::SetCopyAppInclude(CString csAppName)
+{
+	SetProfileString(_T("CopyAppInclude"), csAppName);
+}
+
+CString CGetSetOptions::GetCopyAppInclude()
+{
+	CString includeApp = GetProfileString(_T("CopyAppInclude"), "*");
+	if(includeApp == "")
+	{
+		includeApp = "*";
+	}
+
+	return includeApp;
+}
+
+void CGetSetOptions::SetCopyAppExclude(CString csAppName)
+{
+	SetProfileString(_T("CopyAppExclude"), csAppName);
+}
+
+CString CGetSetOptions::GetCopyAppExclude()
+{
+	return GetProfileString(_T("CopyAppExclude"), "");
+}
+
+CString CGetSetOptions::GetCopyAppSeparator()
+{
+	return GetProfileString(_T("CopyAppSeparator"), ";");
 }

+ 8 - 0
Options.h

@@ -398,6 +398,14 @@ public:
 	static BOOL		GetSetFocusToApp(CString csAppName);
 
 	static DWORD	SelectedIndex();
+
+	static void		SetCopyAppInclude(CString csAppName);
+	static CString  GetCopyAppInclude();
+
+	static void		SetCopyAppExclude(CString csAppName);
+	static CString  GetCopyAppExclude();
+
+	static CString  GetCopyAppSeparator();
 };
 
 // global for easy access and for initialization of fast access variables

+ 16 - 3
OptionsGeneral.cpp

@@ -64,6 +64,8 @@ void COptionsGeneral::DoDataExchange(CDataExchange* pDX)
 	DDX_Control(pDX, IDC_ALLOW_DUPLICATES, m_btAllowDuplicates);
 	DDX_Control(pDX, IDC_UPDATE_TIME_ON_PASTE, m_btUpdateTimeOnPaste);
 	DDX_Control(pDX, IDC_SAVE_MULTIPASTE, m_btSaveMultiPaste);
+	DDX_Control(pDX, IDC_EDIT_APP_COPY_INCLUDE, m_copyAppInclude);
+	DDX_Control(pDX, IDC_EDIT_APP_COPY_EXCLUDE, m_copyAppExclude);
 }
 
 
@@ -103,6 +105,9 @@ BOOL COptionsGeneral::OnInitDialog()
 	m_btHideDittoOnHotKey.SetCheck(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown);
 	m_btSendPasteMessage.SetCheck(g_Opt.m_bSendPasteMessageAfterSelection);
 	m_EnsureConnected.SetCheck(g_Opt.m_bEnsureConnectToClipboard);
+	
+	m_copyAppInclude.SetWindowText(g_Opt.GetCopyAppInclude());
+	m_copyAppExclude.SetWindowText(g_Opt.GetCopyAppExclude());
 
 	m_ClipSeparator.SetWindowText(g_Opt.GetMultiPasteSeparator(false));
 
@@ -211,9 +216,17 @@ BOOL COptionsGeneral::OnApply()
 	g_Opt.SetAllowDuplicates(m_btAllowDuplicates.GetCheck());
 	g_Opt.SetUpdateTimeOnPaste(m_btUpdateTimeOnPaste.GetCheck());
 	g_Opt.SetSaveMultiPaste(m_btSaveMultiPaste.GetCheck());
-	CString csSep;
-	m_ClipSeparator.GetWindowText(csSep);
-	g_Opt.SetMultiPasteSeparator(csSep);
+	
+	CString stringVal;
+
+	m_ClipSeparator.GetWindowText(stringVal);
+	g_Opt.SetMultiPasteSeparator(stringVal);
+
+	m_copyAppInclude.GetWindowText(stringVal);
+	g_Opt.SetCopyAppInclude(stringVal);
+
+	m_copyAppExclude.GetWindowText(stringVal);
+	g_Opt.SetCopyAppExclude(stringVal);
 
 	CString csLanguage;
 	if(m_cbLanguage.GetCurSel() >= 0)

+ 2 - 0
OptionsGeneral.h

@@ -48,6 +48,8 @@ public:
 	CButton m_btSaveMultiPaste;
 	CString	m_csPlaySound;
 	CEdit m_ClipSeparator;
+	CEdit m_copyAppInclude;
+	CEdit m_copyAppExclude;
 	//}}AFX_DATA
 
 

+ 143 - 0
WildCardMatch.cpp

@@ -0,0 +1,143 @@
+#include "stdafx.h"
+#include "WildCardMatch.h"
+
+
+CWildCardMatch::CWildCardMatch(void)
+{
+}
+
+
+CWildCardMatch::~CWildCardMatch(void)
+{
+}
+
+BOOL CWildCardMatch::WildMatch(CString sWild, CString sString, CString sLimitChar)
+{
+	BOOL bAny = FALSE;
+	BOOL bNextIsOptional = FALSE;
+	BOOL bAutorizedChar = TRUE;
+
+	int i=0;
+	int j=0;
+
+	// Check all the string char by char
+	while (i < sString.GetLength()) 
+	{
+		// Check index for array overflow
+		if (j < sWild.GetLength())
+		{
+			// Manage '*' in the wildcard
+			if (sWild[j]=='*') 
+			{
+				// Go to next character in the wildcard
+				j++;
+
+				// Enf of the string and wildcard end 
+				// with *, only test string validity
+				if (j >= sWild.GetLength()) 
+				{
+					// Check end of the string
+					while (!sLimitChar.IsEmpty() && i < sString.GetLength()) 
+					{
+						// If this char is not ok, return false
+						if (sLimitChar.Find(sString[i]) < 0)
+							return FALSE;
+
+						i++;
+					}
+
+					return TRUE;
+				}
+
+				bAny = TRUE;
+				bNextIsOptional = FALSE;
+			} 
+			else 
+			{
+				// Optional char in the wildcard
+				if (sWild[j] == '^')
+				{
+					// Go to next char in the wildcard and indicate 
+					// that the next is optional
+					j++;
+					bNextIsOptional = TRUE;
+				}
+				else
+				{
+					bAutorizedChar = ((sLimitChar.IsEmpty()) || (sLimitChar.Find(sString[i])>=0));
+
+					// IF :
+					// Current char match the wildcard
+					// '?' is used and current char is in authorized char list
+					// Char is optional and it's not in the string
+					// and it's necessary to test if '*' make any 
+					// char browsing
+
+					if (sWild[j] == sString[i] || 
+						(sWild[j] == '?' && bAutorizedChar) || 
+						(bNextIsOptional && !(bAny && bAutorizedChar))) 
+					{
+						// If current char match wildcard, 
+						// we stop for any char browsing
+						if (sWild[j] == sString[i])
+							bAny = FALSE;
+
+						// If it's not an optional char who is not present,
+						// go to next
+						if (sWild[j] == sString[i] || sWild[j] == '?')
+							i++;
+
+						j++;
+
+						bNextIsOptional = FALSE;
+					} 
+					else
+					{
+						// If we are in any char browsing ('*') 
+						// and current char is authorized
+						if (bAny && bAutorizedChar)
+						{
+							// Go to next
+							i++;
+						}
+						else
+						{
+							return FALSE;
+						}
+					}
+				}
+			}
+		}
+		else
+		{
+			// End of the wildcard but not the 
+			// end of the string => 
+			// not matching
+			return FALSE;
+		}
+	}
+
+	if (j < sWild.GetLength() && sWild[j] == '^')
+	{
+		bNextIsOptional = TRUE;
+		j++;
+	}
+
+
+	// If the string is shorter than wildcard 
+	// we test end of the 
+	// wildcard to check matching
+	while ((j < sWild.GetLength() && sWild[j] == '*') || bNextIsOptional)
+	{
+		j++;
+		bNextIsOptional = FALSE;
+
+		if (j < sWild.GetLength() && sWild[j] == '^')
+		{
+			bNextIsOptional = TRUE;
+			j++;
+		}
+	}
+
+	return j >= sWild.GetLength();
+}

+ 10 - 0
WildCardMatch.h

@@ -0,0 +1,10 @@
+#pragma once
+class CWildCardMatch
+{
+public:
+	CWildCardMatch(void);
+	~CWildCardMatch(void);
+
+	static BOOL WildMatch(CString sWild, CString sString, CString sLimitChar);
+};
+