SProxy.cpp 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. bool startWisth(const std::wstring& mainstr, const std::wstring& substr)
  10. {
  11. return mainstr.find(substr) == 0 ? 1 : 0;
  12. }
  13. int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int /*nCmdShow*/)
  14. {
  15. HRESULT hRes = OleInitialize(NULL);
  16. SASSERT(SUCCEEDED(hRes));
  17. int nRet = 0;
  18. new CApp();
  19. new CProcessManager();
  20. CApp::getSingletonPtr()->Init();
  21. CApp::getSingletonPtr()->SetMethod(hInstance);
  22. CApp::getSingletonPtr()->ChkeAndSetDtaPath();
  23. if (!CApp::getSingletonPtr()->CheckOnlyOneInstance())
  24. {
  25. std::wstring pmPrefix = L"--pm=";
  26. std::wstring cmdLine(lpstrCmdLine);
  27. if (startWisth(cmdLine, pmPrefix))
  28. return CProcessManager::getSingletonPtr()->SubProcess(cmdLine.substr(pmPrefix.size()));
  29. }
  30. CreateDirectoryIgnoreExist(CApp::getSingletonPtr()->GetDataPath().c_str());
  31. CApp::getSingletonPtr()->CheckOnlyOneInstance();
  32. PortableModeUtil::SetAppId();
  33. /**/
  34. CProcessManager::getSingletonPtr()->SetInsTanCe(hInstance);
  35. CSouiLoader Loader(hInstance);
  36. InitSystemRes(Loader.GetApp(), Loader.GetComMgr());
  37. InitUserRes(Loader.GetApp(), Loader.GetComMgr());
  38. new CTool();
  39. new SNotifyCenter();
  40. new CManageNetWork();
  41. TCHAR szCurrentDir[MAX_PATH] = { 0 };
  42. GetModuleFileName(NULL, szCurrentDir, sizeof(szCurrentDir));
  43. LPTSTR lpInsertPos = _tcsrchr(szCurrentDir, _T('\\'));
  44. _tcscpy(lpInsertPos + 1, _T("\0"));
  45. SetCurrentDirectory(szCurrentDir);
  46. nRet = Run<CLoginDlg>(Loader.GetApp());
  47. if (CApp::getSingletonPtr()->GetOut() == 1)
  48. {
  49. nRet = Run<CMainDlg>(Loader.GetApp());
  50. }
  51. delete CTool::getSingletonPtr();
  52. delete SNotifyCenter::getSingletonPtr();
  53. delete CManageNetWork::getSingletonPtr();
  54. CProcessManager::getSingletonPtr()->SendStopSignal();
  55. WaitForSingleObject(CProcessManager::getSingletonPtr()->GetClashProcessInfo().hProcess, 3000);
  56. CProcessManager::getSingletonPtr()->Stop();
  57. delete CProcessManager::getSingletonPtr();
  58. delete CApp::getSingletonPtr();
  59. OleUninitialize();
  60. return nRet;
  61. }