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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
|
|
||||||
namespace Artemis.Core.Modules;
|
namespace Artemis.Core.Modules;
|
||||||
@ -38,16 +35,7 @@ public class ProcessActivationRequirement : IModuleActivationRequirement
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Evaluate()
|
public bool Evaluate()
|
||||||
{
|
{
|
||||||
if (!ProcessMonitor.IsStarted || (ProcessName == null && Location == null))
|
return ProcessMonitor.IsProcessRunning(ProcessName, Location);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
@ -99,6 +100,23 @@ public static partial class ProcessMonitor
|
|||||||
FreeBuffer();
|
FreeBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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
|
// ReSharper disable once SuggestBaseTypeForParameter
|
||||||
private static void HandleStoppedProcesses(HashSet<int> currentProcessIds)
|
private static void HandleStoppedProcesses(HashSet<int> currentProcessIds)
|
||||||
@ -112,6 +130,21 @@ public static partial class ProcessMonitor
|
|||||||
OnProcessStopped(info);
|
OnProcessStopped(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
private static void OnProcessStarted(ProcessInfo processInfo)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user