MCPcopy Create free account
hub / github.com/WarmUpTill/SceneSwitcher / CheckCondition

Method CheckCondition

plugins/base/macro-condition-process.cpp:17–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 "AdvSceneSwitcher.condition.process"});
16
17bool MacroConditionProcess::CheckCondition()
18{
19 const auto foregroundProcessName = GetForegroundProcessName();
20 SetVariableValue(foregroundProcessName);
21
22 const QString proc = QString::fromStdString(_process);
23
24 if (_checkFocus) {
25 // Check name and path against the same foreground process
26 // instance to avoid false positives when multiple processes
27 // share the same name
28 const auto foregroundPath = GetForegroundProcessPath();
29 const QString foregroundName =
30 QString::fromStdString(foregroundProcessName);
31
32 SetTempVarValue("name", foregroundProcessName);
33 SetTempVarValue("path", foregroundPath);
34
35 bool nameMatches =
36 _regex.Enabled() ? _regex.Matches(foregroundName, proc)
37 : (foregroundName == proc);
38 if (!nameMatches) {
39 return false;
40 }
41
42 if (_checkPath) {
43 const QString pathPattern =
44 QString::fromStdString(_processPath);
45 const QString qForegroundPath =
46 QString::fromStdString(foregroundPath);
47 bool pathMatches =
48 _pathRegex.Enabled()
49 ? _pathRegex.Matches(qForegroundPath,
50 pathPattern)
51 : qForegroundPath == pathPattern;
52 if (!pathMatches) {
53 return false;
54 }
55 }
56
57 return true;
58 }
59
60 const auto runningProcesses = GetProcessList();
61
62 for (const auto &process : runningProcesses) {
63 bool nameMatches = _regex.Enabled()
64 ? _regex.Matches(process, proc)
65 : (process == proc);
66 if (!nameMatches) {
67 continue;
68 }
69
70 if (!_checkPath) {
71 SetTempVarValue("name", process.toStdString());
72 return true;
73 }
74

Callers

nothing calls this directly

Calls 7

SetTempVarValueFunction · 0.85
GetForegroundProcessNameFunction · 0.50
GetForegroundProcessPathFunction · 0.50
GetProcessListFunction · 0.50
GetProcessPathsFromNameFunction · 0.50
EnabledMethod · 0.45
MatchesMethod · 0.45

Tested by

no test coverage detected