SProxy.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // dui-demo.cpp : main source file
  2. //
  3. #include "stdafx.h"
  4. #include "MainDlg.h"
  5. #include "LoginDlg.h"
  6. #include "SouiInit.h"
  7. #include "CApp.h"
  8. #include "CTool.h"
  9. #include "Logger.h"
  10. #include "SysProxy.h"
  11. #include "log4z/log4z.h"
  12. bool startWisth(const std::wstring& mainstr, const std::wstring& substr)
  13. {
  14. return mainstr.find(substr) == 0 ? 1 : 0;
  15. }
  16. int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
  17. {
  18. HRESULT hRes = OleInitialize(NULL);
  19. SASSERT(SUCCEEDED(hRes));
  20. int nRet = 0;
  21. new Logger();
  22. new CApp();
  23. new CProcessManager();
  24. CApp::getSingletonPtr()->Init();
  25. CApp::getSingletonPtr()->SetMethod(hInstance);
  26. CApp::getSingletonPtr()->ChkeAndSetDtaPath();
  27. //Logger::getSingletonPtr()->terminal = true;
  28. if (!CApp::getSingletonPtr()->CheckOnlyOneInstance())
  29. {
  30. std::wstring pmPrefix = L"--pm=";
  31. std::wstring cmdLine(lpstrCmdLine);
  32. if (startWisth(cmdLine, pmPrefix))
  33. return CProcessManager::getSingletonPtr()->SubProcess(cmdLine.substr(pmPrefix.size()));
  34. }
  35. CreateDirectoryIgnoreExist(CApp::getSingletonPtr()->GetDataPath().c_str());
  36. CApp::getSingletonPtr()->CheckOnlyOneInstance();
  37. PortableModeUtil::SetAppId();
  38. /**/
  39. CProcessManager::getSingletonPtr()->SetInsTanCe(hInstance);
  40. //---------------------------防止程序多开-----------------------------------------
  41. auto hEventStatus = CreateEvent(nullptr, TRUE, FALSE, L"sproxy");
  42. if (hEventStatus)
  43. {
  44. if (GetLastError() == ERROR_ALREADY_EXISTS)
  45. {
  46. auto hwndMain = FindWindow(L"sproxy", NULL);//获取该窗体句柄
  47. if (hwndMain)
  48. {
  49. auto hwnpop = GetLastActivePopup(hwndMain);
  50. ShowWindow(hwnpop, SW_SHOW);
  51. SetForegroundWindow(hwnpop);
  52. //ShowWindow(hwndMain, SW_SHOW);
  53. }
  54. CloseHandle(hEventStatus);//互斥量存在释放句柄并复位互斥量
  55. //
  56. SStringT strDisplayInfo;
  57. strDisplayInfo.Format(L"sproxy 正在运行中.");
  58. MessageBox(GetForegroundWindow(), strDisplayInfo, L"", MB_ICONINFORMATION);
  59. return 0;
  60. }
  61. }//-----------------------------------------------------------------
  62. CSouiLoader Loader(hInstance);
  63. InitSystemRes(Loader.GetApp(), Loader.GetComMgr());
  64. InitUserRes(Loader.GetApp(), Loader.GetComMgr());
  65. new CTool();
  66. new SNotifyCenter();
  67. new CManageNetWork();
  68. TCHAR szCurrentDir[MAX_PATH] = { 0 };
  69. GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
  70. LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
  71. _tcscpy(lpInsertPos + 1, _T("\0"));
  72. SetCurrentDirectory(szCurrentDir);
  73. Logger::getSingletonPtr()->Init(Logger::file_and_terminal, Logger::info);
  74. nRet = Run<CLoginDlg>(Loader.GetApp());
  75. if (CApp::getSingletonPtr()->GetOut() == 1)
  76. {
  77. nRet = Run<CMainDlg>(Loader.GetApp());
  78. }
  79. delete CTool::getSingletonPtr();
  80. delete SNotifyCenter::getSingletonPtr();
  81. delete CManageNetWork::getSingletonPtr();
  82. delete CApp::getSingletonPtr();
  83. delete Logger::getSingletonPtr();
  84. delete CProcessManager::getSingletonPtr();
  85. DisableSystemProxy();
  86. OleUninitialize();
  87. return nRet;
  88. }