Skip to content
Snippets Groups Projects
Commit a6d00d78 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Move CheckForBlacklistedProcesses to SystemChecks.

parent dacd9751
No related branches found
No related tags found
No related merge requests found
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
......@@ -74,7 +75,7 @@ namespace ATXCommon
public static string CheckFreeDiskSpace(List<Serializables.DriveToCheck> drives) {
var msg = "";
foreach (var driveToCheck in drives) {
var freeSpace = SystemChecks.GetFreeDriveSpace(driveToCheck.DriveName);
var freeSpace = GetFreeDriveSpace(driveToCheck.DriveName);
if (freeSpace >= driveToCheck.SpaceThreshold)
continue;
......@@ -85,6 +86,26 @@ namespace ATXCommon
return msg;
}
/// <summary>
/// Compares all processes against the ProcessNames in the BlacklistedProcesses list.
/// </summary>
/// <returns>Returns the name of the first matching process, an empty string otherwise.</returns>
public static string CheckForBlacklistedProcesses(List<string> processNames) {
foreach (var running in Process.GetProcesses()) {
try {
foreach (var blacklisted in processNames) {
if (running.ProcessName.ToLower().Equals(blacklisted)) {
return blacklisted;
}
}
}
catch (Exception ex) {
Log.Warn("Error in checkProcesses(): {0}", ex.Message);
}
}
return "";
}
/// <summary>
/// Check if a user is currently logged into Windows.
///
......
......@@ -103,9 +103,6 @@
<Compile Include="RoboCommand.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="SystemChecks.cs">
<SubType>Component</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
......
......@@ -446,7 +446,8 @@ namespace AutoTx
else if (SystemChecks.GetFreeMemory() < _config.MinAvailableMemory)
limitReason = "RAM usage";
else {
var blacklistedProcess = CheckForBlacklistedProcesses();
var blacklistedProcess = SystemChecks.CheckForBlacklistedProcesses(
_config.BlacklistedProcesses);
if (blacklistedProcess != "") {
limitReason = "blacklisted process '" + blacklistedProcess + "'";
}
......
using System;
using System.Diagnostics;
using ATXCommon;
namespace AutoTx
{
public partial class AutoTx
{
/// <summary>
/// Compares all processes against the ProcessNames in the BlacklistedProcesses list.
/// </summary>
/// <returns>Returns the name of the first matching process, an empty string otherwise.</returns>
public string CheckForBlacklistedProcesses() {
foreach (var running in Process.GetProcesses()) {
try {
foreach (var blacklisted in _config.BlacklistedProcesses) {
if (running.ProcessName.ToLower().Equals(blacklisted)) {
return blacklisted;
}
}
}
catch (Exception ex) {
Log.Warn("Error in checkProcesses(): {0}", ex.Message);
}
}
return "";
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment