-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathController.h
99 lines (91 loc) · 3.71 KB
/
Controller.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <stack>
#include <string>
#include <functional>
#include <windows.h>
template <typename ProcessesPolicy, typename KillersPolicy>
class Controller: private ProcessesPolicy, private KillersPolicy {
typedef typename ProcessesPolicy::LstMode LstMode;
using ProcessesPolicy::ManageProcessList;
using ProcessesPolicy::SortByCpuUsage;
using ProcessesPolicy::SortByRecentlyCreated;
using ProcessesPolicy::Synchronize;
using ProcessesPolicy::RequestPopulatedCAN;
using KillersPolicy::KillByCpu;
using KillersPolicy::KillByPth;
using KillersPolicy::KillByMod;
using KillersPolicy::KillByPid;
using KillersPolicy::KillByD3d;
using KillersPolicy::KillByOgl;
using KillersPolicy::KillByGld;
using KillersPolicy::KillByInr;
using KillersPolicy::KillByFsc;
using KillersPolicy::KillByFgd;
private:
enum CmdMode:char {CMDCP_AUTO=0, CMDCP_UTF8, CMDCP_UTF16}; //Default mode should be 0 so variable can be reset by assigning it 0 or false
enum MIDStatus:char {MID_HIT, MID_NONE, MID_EMPTY};
struct {
bool first_run;
bool mode_blank;
bool mode_ignore;
bool mode_negate;
bool mode_all;
bool mode_loop;
bool mode_verbose;
bool mode_recent;
bool mode_blacklist;
bool mode_whitelist;
bool mode_mute;
bool mode_close;
bool mode_env;
//We should be able to change values of all variables in union by assigning something to it's largest member (should be param_first/param_second)
//Don't expect bool (param_first/param_second type) to be the largest because size of bool is implementation defined
//Test with static_assert for other types to be smaller or equal in size
union {
bool param_first;
bool param_plus;
static_assert(sizeof(LstMode)<=sizeof(bool), L"sizeof(ProcessesPolicy::LstMode) should be less or equal sizeof(bool)");
LstMode param_lst_mode;
static_assert(sizeof(CmdMode)<=sizeof(bool), L"sizeof(Controller::CmdMode) should be less or equal sizeof(bool)");
CmdMode param_cmd_mode;
bool param_full;
bool param_simple;
bool param_anywnd;
bool param_parent;
};
union {
bool param_second;
bool param_sub;
bool param_primary;
};
std::wstring args;
} ctrl_vars;
std::stack<std::wstring> args_stack;
//Windows will close mutex handle automatically when the process terminates
HANDLE sec_mutex;
void ClearParamsAndArgs();
void NoArgsAllowed(const std::wstring &sw);
void DiscardedParam(const std::wstring &sw_param);
void IgnoredSwitch(const std::wstring &sw);
void WaitForUserInput();
bool SecuredExecution();
DWORD IsBOM(DWORD bom);
std::wstring ExpandEnvironmentStringsWrapper(const std::wstring &args);
bool IsDone(bool sw_res);
bool ProcessCmdFile(std::stack<std::wstring> &rules, const wchar_t* arg_cmdpath, CmdMode param_cmd_mode);
MIDStatus MakeItDeadInternal(std::stack<std::wstring> &rules);
virtual bool ModeAll() { return ctrl_vars.mode_all||ctrl_vars.mode_blacklist||ctrl_vars.mode_whitelist; }
virtual bool ModeLoop() { return ctrl_vars.mode_loop||ctrl_vars.mode_blacklist||ctrl_vars.mode_whitelist; }
virtual bool ModeIgnore() { return ctrl_vars.mode_ignore||ctrl_vars.mode_blacklist||ctrl_vars.mode_whitelist; }
virtual bool ModeNegate() { return ctrl_vars.mode_negate; }
virtual bool ModeBlank() { return ctrl_vars.mode_blank||ctrl_vars.mode_blacklist||ctrl_vars.mode_whitelist; }
virtual bool ModeRecent() { return ctrl_vars.mode_recent; }
virtual bool ModeClose() { return ctrl_vars.mode_close; }
virtual bool ModeBlacklist() { return ctrl_vars.mode_blacklist&&!ctrl_vars.mode_whitelist; }
virtual bool ModeWhitelist() { return ctrl_vars.mode_whitelist&&!ctrl_vars.mode_blacklist; }
public:
void MakeItDead(std::stack<std::wstring> &rules);
Controller();
};
#endif //CONTROLLER_H