mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Merge branch 'master' into development
This commit is contained in:
commit
3394786d31
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.Modules;
|
||||
@ -38,16 +35,7 @@ public class ProcessActivationRequirement : IModuleActivationRequirement
|
||||
/// <inheritdoc />
|
||||
public bool Evaluate()
|
||||
{
|
||||
if (!ProcessMonitor.IsStarted || (ProcessName == null && Location == null))
|
||||
return false;
|
||||
|
||||
IEnumerable<ProcessInfo> processes = ProcessMonitor.Processes;
|
||||
if (ProcessName != null)
|
||||
processes = processes.Where(p => string.Equals(p.ProcessName, ProcessName, StringComparison.InvariantCultureIgnoreCase));
|
||||
if (Location != null)
|
||||
processes = processes.Where(p => string.Equals(Path.GetDirectoryName(p.Executable), Location, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
return processes.Any();
|
||||
return ProcessMonitor.IsProcessRunning(ProcessName, Location);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
@ -100,6 +101,23 @@ public static partial class ProcessMonitor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the specified process is running
|
||||
/// </summary>
|
||||
/// <param name="processName">The name of the process to check</param>
|
||||
/// <param name="processLocation">The location of where the process must be running from (optional)</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsProcessRunning(string? processName = null, string? processLocation = null)
|
||||
{
|
||||
if (!IsStarted || (processName == null && processLocation == null))
|
||||
return false;
|
||||
|
||||
lock (LOCK)
|
||||
{
|
||||
return _processes.Values.Any(x => IsProcessRunning(x, processName, processLocation));
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once SuggestBaseTypeForParameter
|
||||
private static void HandleStoppedProcesses(HashSet<int> currentProcessIds)
|
||||
{
|
||||
@ -113,6 +131,21 @@ public static partial class ProcessMonitor
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsProcessRunning(ProcessInfo info, string? processName, string? processLocation)
|
||||
{
|
||||
if (processName != null && processLocation != null)
|
||||
return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
if (processName != null)
|
||||
return string.Equals(info.ProcessName, processName, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
if (processLocation != null)
|
||||
return string.Equals(Path.GetDirectoryName(info.Executable), processLocation, StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void OnProcessStarted(ProcessInfo processInfo)
|
||||
{
|
||||
try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user