123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #pragma once
- #define OBJPREFIX LR"(Local\)"
- constexpr size_t guidSize = std::size(L"{00000000-0000-0000-0000-000000000000}"); // including the null terminator
- constexpr size_t prefixSize = std::size(OBJPREFIX) - 1;
- constexpr size_t objNameSize = prefixSize + guidSize;
- struct ProcessInfo
- {
- DWORD processId;
- DWORD threadId;
- HWND hWndConsole;
- };
- class CProcessManager : public SSingleton<CProcessManager>
- {
- public:
- enum struct State
- {
- Stop,
- Running,
- WaitStop
- };
- CProcessManager();
- ~CProcessManager();
- void _UpdateClashCmd();
- void SetInsTanCe(HINSTANCE m);
- void SetArgs(std::filesystem::path exePath, std::filesystem::path homeDir, std::filesystem::path cconfigFile);
- void SetConfigFile(std::filesystem::path configFile);
- inline State IsRunning() { return _state; }
- inline const PROCESS_INFORMATION& GetSubProcessInfo() { return _subProcInfo; }
- inline const PROCESS_INFORMATION& GetClashProcessInfo() { return _clashProcInfo; }
- inline HWND GetConsoleWindow() { return _hWndConsole; }
- bool Start();
- void Stop();
- void SendStopSignal();
- int SubProcess(std::wstring_view guid);
- private:
- State _state = State::Stop;
- std::filesystem::path _exePath;
- std::filesystem::path _homeDir;
- std::filesystem::path _configFile;
- std::wstring _ctlAddr, _ctlSecret, _clashCmd;
- wil::unique_handle _hJob;
- wil::unique_process_information _subProcInfo, _clashProcInfo;
- HWND _hWndConsole = nullptr;
- wil::unique_handle _hEvent;
- HINSTANCE mInstance;
- };
|