Property.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:10k
开发平台:

Visual C++

  1. // Property.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "GuiRes.h"
  6. #include ".MainFrameMainFrame.h"
  7. #include ".MainSheet.h"
  8. #include "AclSet.h"
  9. #include "NetTimeSheet.h"
  10. #include "NetIPAria.h"
  11. #include "Acl.h"
  12. #include "Splash.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. //=============================================================================================
  19. // The one and only CPropertyApp object
  20. CPropertyApp theApp;
  21. CAclFile m_AclFile;
  22. extern CMainSheet *dlg;
  23. extern CAclSet *dlgAclSet;
  24. extern CNetTimeSheet *dlgNetTimeSheet;
  25. extern CFileDialog *dlgFile;
  26. extern CNetIPAria *dlgNetIPAria;
  27. extern CSystemTray m_TrayIcon;
  28. //=============================================================================================
  29. // CPropertyApp
  30. BEGIN_MESSAGE_MAP(CPropertyApp, CWinApp)
  31. //{{AFX_MSG_MAP(CPropertyApp)
  32. ON_COMMAND(ID_APP_EXIT, OnAppExit)
  33. ON_COMMAND(ID_ABOUT, OnAbout)
  34. ON_COMMAND(ID_ACL_SET, OnAclSet)
  35. ON_COMMAND(ID_LOG_QUERY, OnLogQuery)
  36. ON_COMMAND(ID_SYSTEM_SET, OnSystemSet)
  37. ON_UPDATE_COMMAND_UI(ID_ABOUT, OnUpdateAbout)
  38. ON_UPDATE_COMMAND_UI(ID_ACL_SET, OnUpdateAclSet)
  39. ON_UPDATE_COMMAND_UI(ID_APP_EXIT, OnUpdateAppExit)
  40. ON_UPDATE_COMMAND_UI(ID_LOG_QUERY, OnUpdateLogQuery)
  41. ON_UPDATE_COMMAND_UI(ID_SYSTEM_SET, OnUpdateSystemSet)
  42. ON_COMMAND(ID_CONTROL_FRAME, OnControlFrame)
  43. ON_UPDATE_COMMAND_UI(ID_CONTROL_FRAME, OnUpdateControlFrame)
  44. ON_COMMAND(ID_PACKET_MONITOR, OnPacketMonitor)
  45. ON_UPDATE_COMMAND_UI(ID_PACKET_MONITOR, OnUpdatePacketMonitor)
  46. //}}AFX_MSG_MAP
  47. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  48. END_MESSAGE_MAP()
  49. //=============================================================================================
  50. // CPropertyApp construction
  51. CPropertyApp::CPropertyApp()
  52. {
  53. m_EnablePacketMonitor = TRUE;
  54. m_EnableQueryLog = TRUE;
  55. m_EnableAcl = TRUE;
  56. m_EnableSystemSet = TRUE;
  57. m_EnableAbout = TRUE;
  58. m_EnableExit = TRUE;
  59. m_EnableContolFrame = TRUE;
  60. m_XfIoControl = NULL;
  61. }
  62. //=============================================================================================
  63. // CPropertyApp initialization
  64. BOOL CPropertyApp::InitInstance()
  65. {
  66. TCHAR sPathName[MAX_PATH];
  67. _stprintf(sPathName, _T("%s%s"), m_AclFile.GetAppPath(), XFILTER_SERVICE_DLL_NAME);
  68. TCHAR sTemp[MAX_PATH];
  69. _stprintf(sTemp, _T("%s%s"), m_AclFile.GetAppPath(), XFILTER_HELP_FILE_NAME);
  70. theApp.m_pszHelpFilePath = _tcsdup(sTemp);
  71. if(_tcscmp(theApp.m_lpCmdLine, _T("-install")) == 0)
  72. {
  73. int iRet;
  74. if((iRet = m_Install.InstallProvider(sPathName)) != XERR_SUCCESS
  75. && iRet != XERR_PROVIDER_ALREADY_INSTALL)
  76. AfxMessageBox(GUI_ACL_MESSAGE_INSTALL_FAILED);
  77. SetAutoStart(FALSE);
  78. m_RegisterRequest.UserReg();
  79. return FALSE;
  80. }
  81. if(_tcscmp(theApp.m_lpCmdLine, _T("-remove")) == 0)
  82. {
  83. m_Install.RemoveProvider();
  84. m_Install.DeleteReg(HKEY_LOCAL_MACHINE, REG_AUTO_START_KEY, REG_AUTO_START_ITEM);
  85. return FALSE;
  86. }
  87. if(!m_Install.IsWinsock2())
  88. {
  89. AfxMessageBox(GUI_ACL_MESSAGE_NO_WINSOCK2);
  90. return FALSE;
  91. }
  92. CWnd *PrevCWnd = CWnd::FindWindow(NULL, GUI_APP_CAPTION);
  93. if (PrevCWnd != NULL) 
  94. return FALSE;
  95. if(m_AclFile.ReadAcl() != XERR_SUCCESS)
  96. {
  97. AfxMessageBox(GUI_ACL_MESSAGE_ACL_READ_ERROR);
  98. return FALSE;
  99. }
  100. if(m_AclFile.GetBit(m_AclFile.mAclHeader.bSet, 6))
  101. {
  102. CCommandLineInfo cmdInfo;
  103. ParseCommandLine(cmdInfo);
  104. CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
  105. }
  106. if(!theApp.m_RegisterRequest.InitRegister())
  107. return FALSE;
  108. if(!m_Install.IsInstalled(sPathName) && m_Install.InstallProvider(sPathName) != XERR_SUCCESS)
  109. {
  110. AfxMessageBox(GUI_ACL_MESSAGE_INSTALL_FAILED);
  111. return FALSE;
  112. }
  113. if ((m_hTcpIpDog = LoadLibrary(sPathName)) == NULL)
  114. {
  115. AfxMessageBox(GUI_ACL_MESSAGE_DLL_NOT_FOUND);
  116. return FALSE;
  117. }
  118. m_XfIoControl = (XF_IO_CONTROL)GetProcAddress(m_hTcpIpDog, _T("XfIoControl"));
  119. if (m_XfIoControl == NULL)
  120. {
  121. AfxMessageBox(GUI_ACL_MESSAGE_FUNCTION_NOT_FOUNT);
  122. return FALSE;
  123. }
  124. if(!InitDllData())
  125. {
  126. AfxMessageBox(GUI_ACL_MESSAGE_INIT_DLL_DATA_ERROR);
  127. return FALSE;
  128. }
  129. CMainFrame* pFrame = new CMainFrame;
  130. m_pMainWnd = pFrame;
  131. pFrame->Create(NULL,GUI_APP_CAPTION);
  132. pFrame->ShowWindow(SW_HIDE);
  133. pFrame->UpdateWindow();
  134. XFILTER_IO_CONTROL ioControl;
  135. ioControl.hwnd = pFrame->m_hWnd;
  136. m_XfIoControl(IO_CONTROL_SET_GUI_INSTANCE, &ioControl);
  137. return TRUE;
  138. }
  139. BOOL CPropertyApp::InitDllData()
  140. {
  141. if(m_XfIoControl == NULL)
  142. return FALSE;
  143. XFILTER_IO_CONTROL ioControl;
  144. if((ioControl.iWorkMode = CAclFile::GetBit(m_AclFile.mAclHeader.bSet, 4, 2)) != XF_QUERY_ALL)
  145. {
  146. if(m_XfIoControl(IO_CONTROL_SET_WORK_MODE, &ioControl) != XERR_SUCCESS)
  147. return FALSE;
  148. SetTrayIcon();
  149. return TRUE;
  150. }
  151. ioControl.AclFile.mAclHeader = m_AclFile.mAclHeader;
  152. ioControl.AclFile.mAclIntranetIP = m_AclFile.mAclIntranetIP;
  153. memcpy(ioControl.AclFile.mAclTime , m_AclFile.mAclTime, ACL_TIME_LENTH * ACL_HEADER_TIME_COUNT) ;
  154. memcpy(ioControl.AclFile.mpAcl , m_AclFile.mpAcl , ACL_ACL_LENTH * m_AclFile.mAclHeader.ulAclCount);
  155. memcpy(ioControl.AclFile.mpAclCustomIP , m_AclFile.mpAclCustomIP , ACL_IP_LENTH * m_AclFile.mAclHeader.ulCustomIPCount);
  156. memcpy(ioControl.AclFile.mpAclDistrustIP , m_AclFile.mpAclDistrustIP , ACL_IP_LENTH * m_AclFile.mAclHeader.ulDistrustIPCount);
  157. memcpy(ioControl.AclFile.mpAclTrustIP , m_AclFile.mpAclTrustIP , ACL_IP_LENTH * m_AclFile.mAclHeader.ulTrustIPCount);
  158. if(m_XfIoControl(IO_CONTROL_SET_ACL, &ioControl) != XERR_SUCCESS)
  159. return FALSE;
  160. SetTrayIcon();
  161. return TRUE;
  162. }
  163. void CPropertyApp::ExitApp()
  164. {
  165. if(CheckDlg()) 
  166. return;
  167. if(dlg != NULL)
  168. {
  169. if(dlg->GetDlgItem(ID_APPLY_NOW)->IsWindowEnabled())
  170. dlg->OnCancel();
  171. dlg->EndDialog(IDCANCEL);
  172. }
  173. m_pMainWnd->DestroyWindow();
  174. }
  175. /*---------------------------------------------------------------------------------------------
  176. Return Value: 
  177. TRUE: had some sub_dialogs visible 
  178. FALSE: no sub_dialogs visible
  179. */
  180. BOOL CPropertyApp::CheckDlg(BOOL ShowMessage)
  181. {
  182. if( CheckDlgVisible (dlgNetIPAria , ShowMessage)
  183. || CheckDlgVisible (dlgNetTimeSheet, ShowMessage)
  184. || CheckDlgVisible (dlgFile , ShowMessage)
  185. || CheckDlgVisible (dlgAclSet , ShowMessage)
  186. )
  187. return TRUE;
  188. return FALSE;
  189. }
  190. BOOL CPropertyApp::CheckDlgVisible(void* pdlg, BOOL ShowMessage)
  191. {
  192. if(pdlg == NULL) 
  193. return FALSE;
  194. CDialog* mdlg = (CDialog*)pdlg;
  195. if(ShowMessage)
  196. AfxMessageBox(GUI_ACL_MESSAGE_PLEASE_CLOSE_SUB_WINDOW);
  197. mdlg->SetFocus();
  198. return TRUE;
  199. }
  200. void CPropertyApp::OnAppExit() 
  201. {
  202. if(!m_EnableExit) 
  203. return;
  204. ExitApp();
  205. }
  206. void CPropertyApp::OnPacketMonitor() 
  207. {
  208. if(!m_EnablePacketMonitor)
  209. return;
  210. CMainFrame::InitMainSheet();
  211. }
  212. void CPropertyApp::OnLogQuery() 
  213. {
  214. if(!m_EnableQueryLog) 
  215. return;
  216. CMainFrame::InitMainSheet(1);
  217. }
  218. void CPropertyApp::OnAclSet() 
  219. {
  220. if(!m_EnableAcl) 
  221. return;
  222. CMainFrame::InitMainSheet(2);
  223. }
  224. void CPropertyApp::OnSystemSet() 
  225. {
  226. if(!m_EnableSystemSet) 
  227. return;
  228. CMainFrame::InitMainSheet(3);
  229. }
  230. void CPropertyApp::OnAbout() 
  231. {
  232. if(!m_EnableAbout) 
  233. return;
  234. CMainFrame::InitMainSheet(4);
  235. }
  236. void CPropertyApp::OnControlFrame() 
  237. {
  238. if(!m_EnableContolFrame) 
  239. return;
  240. if(CheckDlg(FALSE))
  241. return;
  242. CMainFrame::InitMainSheet(-1);
  243. }
  244. void CPropertyApp::OnUpdateAbout(CCmdUI* pCmdUI) 
  245. {
  246. pCmdUI->Enable(m_EnableAbout);
  247. pCmdUI->SetText(GUI_MENU_ABOUT);
  248. }
  249. void CPropertyApp::OnUpdateAclSet(CCmdUI* pCmdUI) 
  250. {
  251. pCmdUI->Enable(m_EnableAcl);
  252. pCmdUI->SetText(GUI_MENU_ACL);
  253. }
  254. void CPropertyApp::OnUpdateAppExit(CCmdUI* pCmdUI) 
  255. {
  256. pCmdUI->Enable(m_EnableExit);
  257. pCmdUI->SetText(GUI_MENU_EXIT);
  258. }
  259. void CPropertyApp::OnUpdateLogQuery(CCmdUI* pCmdUI) 
  260. {
  261. pCmdUI->Enable(m_EnableQueryLog);
  262. pCmdUI->SetText(GUI_MENU_LOG_QUERY);
  263. }
  264. void CPropertyApp::OnUpdatePacketMonitor(CCmdUI* pCmdUI) 
  265. {
  266. pCmdUI->Enable(m_EnablePacketMonitor);
  267. pCmdUI->SetText(GUI_MENU_PACKET_MONITOR);
  268. }
  269. void CPropertyApp::OnUpdateSystemSet(CCmdUI* pCmdUI) 
  270. {
  271. pCmdUI->Enable(m_EnableSystemSet);
  272. pCmdUI->SetText(GUI_MENU_SYSTEM_SET);
  273. }
  274. void CPropertyApp::OnUpdateControlFrame(CCmdUI* pCmdUI) 
  275. {
  276. pCmdUI->Enable(m_EnableContolFrame);
  277. pCmdUI->SetText(GUI_MENU_CONTROL_FRAME);
  278. }
  279. int CPropertyApp::ExitInstance() 
  280. {
  281. ODS(_T("XFILTER.EXE: ExitInstance Starting..."));
  282. m_TrayIcon.HideIcon();
  283.   if(m_XfIoControl != NULL)
  284. {
  285. XFILTER_IO_CONTROL ioControl;
  286. ioControl.iWorkMode = XF_PASS_ALL;
  287. ioControl.hwnd = NULL;
  288. m_XfIoControl(IO_CONTROL_SET_WORK_MODE, &ioControl);
  289. m_XfIoControl(IO_CONTROL_SET_GUI_INSTANCE, &ioControl);
  290. }
  291. if(m_hTcpIpDog != NULL)
  292. FreeLibrary(m_hTcpIpDog);
  293. m_hTcpIpDog = NULL;
  294. while(m_DownloadCommand.m_IsConnecting || m_RegisterRequest.m_IsConnecting)
  295. Sleep(1000);
  296. ODS(_T("XFILTER.EXE: ExitInstance Over..."));
  297. return CWinApp::ExitInstance();
  298. }
  299. BOOL CPropertyApp::PreTranslateMessage(MSG* pMsg)
  300. {
  301. // CG: The following lines were added by the Splash Screen component. if (CSplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg);
  302. }
  303. void CPropertyApp::SetAutoStart(BOOL IsCheckFromAcl)
  304. {
  305. BOOL IsCheck = TRUE;
  306. if(IsCheckFromAcl)
  307. IsCheck = m_AclFile.GetBit(m_AclFile.mAclHeader.bSet, 1);
  308. if(IsCheck)
  309. {
  310. TCHAR tmpStr[MAX_PATH];
  311. strcpy(tmpStr, m_AclFile.GetAppPath(FALSE, NULL, TRUE));
  312. m_Install.SaveReg(REG_AUTO_START_ITEM, (BYTE*)tmpStr, _tcslen(tmpStr)
  313. , HKEY_LOCAL_MACHINE, REG_AUTO_START_KEY, REG_SZ);
  314. return;
  315. }
  316. m_Install.DeleteReg(HKEY_LOCAL_MACHINE, REG_AUTO_START_KEY, REG_AUTO_START_ITEM);
  317. }
  318. void CPropertyApp::SetTrayIcon()
  319. {
  320. int iWorkMode = XF_PASS_ALL;
  321. if(m_XfIoControl != NULL)
  322. iWorkMode = m_XfIoControl(IO_CONTROL_GET_WORK_MODE, NULL);
  323. if(iWorkMode == XF_PASS_ALL)
  324. m_TrayIcon.SetIcon(IDI_SMALL_PASS);
  325. else if(iWorkMode == XF_QUERY_ALL)
  326. m_TrayIcon.SetIcon(IDI_SMALL_QUERY);
  327. else if(iWorkMode == XF_DENY_ALL)
  328. m_TrayIcon.SetIcon(IDI_SMALL_DENY);
  329. else
  330. m_TrayIcon.SetIcon(IDI_SMALL_PASS);
  331. }
  332. void CPropertyApp::WinHelp(DWORD dwData, UINT nCmd) 
  333. {
  334. HWND hHtmlHelp = HtmlHelp(
  335. theApp.m_pMainWnd->m_hWnd, 
  336. theApp.m_pszHelpFilePath, 
  337. nCmd, 
  338. dwData
  339. );
  340. if(hHtmlHelp == 0)
  341. AfxMessageBox(GUI_MESSAGE_OPEN_HELP_FAILED);
  342. }