CProcessManager.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #define OBJPREFIX LR"(Local\)"
  3. constexpr size_t guidSize = std::size(L"{00000000-0000-0000-0000-000000000000}"); // including the null terminator
  4. constexpr size_t prefixSize = std::size(OBJPREFIX) - 1;
  5. constexpr size_t objNameSize = prefixSize + guidSize;
  6. struct ProcessInfo
  7. {
  8. DWORD processId;
  9. DWORD threadId;
  10. HWND hWndConsole;
  11. };
  12. class CProcessManager : public SSingleton<CProcessManager>
  13. {
  14. public:
  15. enum struct State
  16. {
  17. Stop,
  18. Running,
  19. WaitStop
  20. };
  21. CProcessManager();
  22. ~CProcessManager();
  23. void _UpdateClashCmd();
  24. void SetInsTanCe(HINSTANCE m);
  25. void SetArgs(std::filesystem::path exePath, std::filesystem::path homeDir, std::filesystem::path cconfigFile);
  26. void SetConfigFile(std::filesystem::path configFile);
  27. inline State IsRunning() { return _state; }
  28. inline const PROCESS_INFORMATION& GetSubProcessInfo() { return _subProcInfo; }
  29. inline const PROCESS_INFORMATION& GetClashProcessInfo() { return _clashProcInfo; }
  30. inline HWND GetConsoleWindow() { return _hWndConsole; }
  31. bool Start();
  32. void Stop();
  33. void SendStopSignal();
  34. int SubProcess(std::wstring_view guid);
  35. private:
  36. State _state = State::Stop;
  37. std::filesystem::path _exePath;
  38. std::filesystem::path _homeDir;
  39. std::filesystem::path _configFile;
  40. std::wstring _ctlAddr, _ctlSecret, _clashCmd;
  41. wil::unique_handle _hJob;
  42. wil::unique_process_information _subProcInfo, _clashProcInfo;
  43. HWND _hWndConsole = nullptr;
  44. wil::unique_handle _hEvent;
  45. HINSTANCE mInstance;
  46. };