| 15 | "AdvSceneSwitcher.condition.process"}); |
| 16 | |
| 17 | bool 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 |
nothing calls this directly
no test coverage detected