Browse Source

added option to not start up the server thread

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@110 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 21 years ago
parent
commit
f230722b74
9 changed files with 71 additions and 14 deletions
  1. 13 1
      CP_Main.cpp
  2. 3 0
      CP_Main.h
  3. 12 10
      CP_Main.rc
  4. 11 0
      Misc.cpp
  5. 2 1
      Misc.h
  6. 16 0
      OptionFriends.cpp
  7. 2 0
      OptionFriends.h
  8. 2 1
      Resource.h
  9. 10 1
      Server.cpp

+ 13 - 1
CP_Main.cpp

@@ -65,6 +65,8 @@ CCP_MainApp::CCP_MainApp()
 	m_lClipsRecieved = 0;
 	m_oldtStartUp = COleDateTime::GetCurrentTime();
 
+	m_bExitServerThread = false;
+
 	::InitializeCriticalSection(&m_CriticalSection);
 }
 
@@ -157,13 +159,23 @@ void CCP_MainApp::AfterMainCreate()
 	// CopyThread initialization
 	StartCopyThread();
 	
-	AfxBeginThread(MTServerThread, m_MainhWnd);
+	StartStopServerThread();
 
 	m_bAppRunning = true;
 
 	m_pcpSendRecieveError = NULL;
 }
 
+void CCP_MainApp::StartStopServerThread()
+{
+	if(CGetSetOptions::GetDisableRecieve() == FALSE)
+	{
+		AfxBeginThread(MTServerThread, m_MainhWnd);
+	}
+	else
+		m_bExitServerThread = true;
+}
+
 void CCP_MainApp::BeforeMainClose()
 {
 	ASSERT( m_bAppRunning && !m_bAppExiting );

+ 3 - 0
CP_Main.h

@@ -44,6 +44,8 @@ public:
 	bool	m_bAppRunning;
 	bool	m_bAppExiting;
 
+	bool	m_bExitServerThread;
+
 // MainFrame
 	HWND m_MainhWnd;
 	CMainFrame*	m_pMainFrame;
@@ -149,6 +151,7 @@ public:
 	SOCKET	m_sSocket;
 	CRITICAL_SECTION m_CriticalSection;
 	CPopup	 *m_pcpSendRecieveError;
+	void	StartStopServerThread();
 
 
 	long	m_lClipsSent;

+ 12 - 10
CP_Main.rc

@@ -620,22 +620,24 @@ BEGIN
     EDITTEXT        IDC_NAME,7,11,172,12,ES_AUTOHSCROLL
 END
 
-IDD_OPTIONS_FRIENDS DIALOG DISCARDABLE  0, 0, 300, 214
+IDD_OPTIONS_FRIENDS DIALOG DISCARDABLE  0, 0, 310, 227
 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Friends"
 FONT 8, "MS Sans Serif"
 BEGIN
     CONTROL         "List1",IDC_LIST,"SysListView32",LVS_REPORT | WS_BORDER | 
-                    WS_TABSTOP,7,82,286,116
+                    WS_TABSTOP,7,93,296,116
     LTEXT           "If Send All Copies is selected then all copies from this computer will be sent to the other computer.  If that is not selected then it will just be in the right click menu to send a copy to that computer.",
-                    IDC_STATIC,7,52,278,24
-    EDITTEXT        IDC_EDIT_PLACE_ON_CLIPBOARD,83,31,210,13,ES_AUTOHSCROLL
-    LTEXT           "IP/Computer Names seperated by commas",IDC_STATIC,7,29,
+                    IDC_STATIC,7,63,278,24
+    EDITTEXT        IDC_EDIT_PLACE_ON_CLIPBOARD,93,34,210,13,ES_AUTOHSCROLL
+    LTEXT           "IP/Computer Names seperated by commas",IDC_STATIC,7,32,
                     70,17
     LTEXT           "When you recieve a sent copy if their ip or computer name is in this list then it will be put on the clipboard.  Otherwise it will be in the saved clips to use at a later time.",
-                    IDC_STATIC,7,7,286,18
+                    IDC_STATIC,7,10,296,18
     CONTROL         "Log Send Receive Commands",IDC_CHECK_LOG_SEND_RECIEVE,
-                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,199,176,12
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,212,176,12
+    CONTROL         "Disable Recieving Clips",IDC_CHECK_DISABLE_FRIENDS,
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,93,48,90,10
 END
 
 IDD_FRIEND_DETAILS DIALOG DISCARDABLE  0, 0, 203, 79
@@ -808,9 +810,9 @@ BEGIN
     IDD_OPTIONS_FRIENDS, DIALOG
     BEGIN
         LEFTMARGIN, 7
-        RIGHTMARGIN, 293
-        TOPMARGIN, 7
-        BOTTOMMARGIN, 211
+        RIGHTMARGIN, 303
+        TOPMARGIN, 4
+        BOTTOMMARGIN, 224
     END
 
     IDD_FRIEND_DETAILS, DIALOG

+ 11 - 0
Misc.cpp

@@ -1080,6 +1080,17 @@ long CGetSetOptions::GetPort()
 	return GetProfileLong("SendRecvPort", 23443);
 }
 
+BOOL CGetSetOptions::GetDisableRecieve()
+{
+	return GetProfileLong("DisableRecieve", FALSE);
+}
+
+void CGetSetOptions::SetDisableRecieve(BOOL bVal)
+{
+	SetProfileLong("DisableRecieve", bVal);
+}
+
+
 /*------------------------------------------------------------------*\
 CHotKey - a single system-wide hotkey
 \*------------------------------------------------------------------*/

+ 2 - 1
Misc.h

@@ -296,8 +296,9 @@ public:
 	static long		m_lPort;
 	static void		SetPort(long lPort);
 	static long		GetPort();
-	
 
+	static BOOL		GetDisableRecieve();
+	static void		SetDisableRecieve(BOOL bVal);
 
 	/*
 	BOOL IsAutoRun();

+ 16 - 0
OptionFriends.cpp

@@ -34,6 +34,7 @@ void COptionFriends::DoDataExchange(CDataExchange* pDX)
 {
 	CPropertyPage::DoDataExchange(pDX);
 	//{{AFX_DATA_MAP(COptionFriends)
+	DDX_Control(pDX, IDC_CHECK_DISABLE_FRIENDS, m_bDisableRecieve);
 	DDX_Control(pDX, IDC_CHECK_LOG_SEND_RECIEVE, m_SendRecieve);
 	DDX_Control(pDX, IDC_LIST, m_List);
 	DDX_Text(pDX, IDC_EDIT_PLACE_ON_CLIPBOARD, m_PlaceOnClipboard);
@@ -45,6 +46,7 @@ BEGIN_MESSAGE_MAP(COptionFriends, CPropertyPage)
 	//{{AFX_MSG_MAP(COptionFriends)
 	ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
 	ON_NOTIFY(LVN_KEYDOWN, IDC_LIST, OnKeydownList)
+	ON_BN_CLICKED(IDC_CHECK_DISABLE_FRIENDS, OnCheckDisableFriends)
 	//}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -65,6 +67,8 @@ BOOL COptionFriends::OnInitDialog()
 
 	m_SendRecieve.SetCheck(CGetSetOptions::GetLogSendReceiveErrors());
 
+	m_bDisableRecieve.SetCheck(CGetSetOptions::GetDisableRecieve());
+
 	m_PlaceOnClipboard = g_Opt.m_csIPListToPutOnClipboard;
 
 	UpdateData(FALSE);
@@ -95,6 +99,10 @@ BOOL COptionFriends::OnApply()
 
 	CGetSetOptions::SetLogSendReceiveErrors(m_SendRecieve.GetCheck());
 
+
+	CGetSetOptions::SetDisableRecieve(m_bDisableRecieve.GetCheck());
+	theApp.StartStopServerThread();
+
 	UpdateData();
 
 	g_Opt.SetListToPutOnClipboard(m_PlaceOnClipboard);
@@ -248,3 +256,11 @@ void COptionFriends::OnKeydownList(NMHDR* pNMHDR, LRESULT* pResult)
 	
 	*pResult = 0;
 }
+
+void COptionFriends::OnCheckDisableFriends() 
+{
+	if(m_bDisableRecieve.GetCheck() == BST_CHECKED)
+		GetDlgItem(IDC_EDIT_PLACE_ON_CLIPBOARD)->EnableWindow(FALSE);
+	else
+		GetDlgItem(IDC_EDIT_PLACE_ON_CLIPBOARD)->EnableWindow(TRUE);
+}

+ 2 - 0
OptionFriends.h

@@ -23,6 +23,7 @@ public:
 // Dialog Data
 	//{{AFX_DATA(COptionFriends)
 	enum { IDD = IDD_OPTIONS_FRIENDS };
+	CButton	m_bDisableRecieve;
 	CButton	m_SendRecieve;
 	CListCtrl	m_List;
 	CString	m_PlaceOnClipboard;
@@ -51,6 +52,7 @@ protected:
 	virtual BOOL OnInitDialog();
 	afx_msg void OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult);
 	afx_msg void OnKeydownList(NMHDR* pNMHDR, LRESULT* pResult);
+	afx_msg void OnCheckDisableFriends();
 	//}}AFX_MSG
 	DECLARE_MESSAGE_MAP()
 

+ 2 - 1
Resource.h

@@ -109,6 +109,7 @@
 #define IDC_HOTKEY2                     2025
 #define IDC_EDIT_PLACE_ON_CLIPBOARD     2025
 #define IDC_HOTKEY3                     2026
+#define IDC_CHECK_DISABLE_FRIENDS       2026
 #define IDC_HOTKEY4                     2027
 #define IDC_HOTKEY5                     2028
 #define IDC_HOTKEY6                     2029
@@ -189,7 +190,7 @@
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        151
 #define _APS_NEXT_COMMAND_VALUE         32840
-#define _APS_NEXT_CONTROL_VALUE         2026
+#define _APS_NEXT_CONTROL_VALUE         2027
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif

+ 10 - 1
Server.cpp

@@ -18,8 +18,15 @@ static char THIS_FILE[]=__FILE__;
 
 UINT  MTServerThread(LPVOID pParam)
 {		
+	static bool bRunning = false;
+	if(bRunning)
+		return 0;
+	bRunning = true;
+
 	LogSendRecieveInfo("Start of ServerThread");
 
+	theApp.m_bExitServerThread = false;
+
 	WSADATA wsaData;
 	sockaddr_in local;
 	int wsaret = WSAStartup(0x101,&wsaData);
@@ -55,7 +62,7 @@ UINT  MTServerThread(LPVOID pParam)
 
 	while(true)
 	{
-		if(theApp.m_bAppExiting)
+		if(theApp.m_bAppExiting || theApp.m_bExitServerThread)
 			break;
 
 		socket = accept(theApp.m_sSocket, (struct sockaddr*)&from,&fromlen);
@@ -65,6 +72,8 @@ UINT  MTServerThread(LPVOID pParam)
 
 	LogSendRecieveInfo("End of Server Thread");
 
+	bRunning = false;
+
 	return 0;
 }