-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoincProcessCheck.cs
More file actions
136 lines (122 loc) · 6.03 KB
/
BoincProcessCheck.cs
File metadata and controls
136 lines (122 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// This file is part of BOINC.
// https://boinc.berkeley.edu
// Copyright (C) 2025 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace boinc_buda_runner_wsl_installer
{
internal class BoincProcessCheck
{
private const string COMPONENT = "BoincProcessCheck";
public enum BoincProcessStatus
{
Running,
NotRunning,
Error
}
public class BoincProcessCheckResult
{
public BoincProcessStatus Status { get; set; }
public string Message { get; set; }
public int ProcessCount { get; set; }
public string ErrorMessage { get; set; }
}
/// <summary>
/// Checks if BOINC process is running on the system
/// </summary>
/// <returns>BoincProcessCheckResult with process status and details</returns>
public static async Task<BoincProcessCheckResult> CheckBoincProcessAsync()
{
DebugLogger.LogMethodStart("CheckBoincProcessAsync", component: COMPONENT);
var result = new BoincProcessCheckResult();
try
{
await Task.Run(() =>
{
DebugLogger.LogInfo("Searching for BOINC processes", COMPONENT);
// Get all processes named "boinc"
var boincProcesses = Process.GetProcessesByName("boinc");
result.ProcessCount = boincProcesses.Length;
DebugLogger.LogConfiguration("BOINC Process Count", result.ProcessCount, COMPONENT);
if (boincProcesses.Length == 0)
{
DebugLogger.LogInfo("No BOINC processes found", COMPONENT);
result.Status = BoincProcessStatus.NotRunning;
result.Message = "BOINC process is not running";
}
else
{
DebugLogger.LogWarning($"Found {boincProcesses.Length} BOINC process(es) running", COMPONENT);
// Log details of all running BOINC processes
for (int i = 0; i < boincProcesses.Length; i++)
{
try
{
var process = boincProcesses[i];
DebugLogger.LogConfiguration($"BOINC Process #{i + 1} PID", process.Id, COMPONENT);
DebugLogger.LogConfiguration($"BOINC Process #{i + 1} Process Name", process.ProcessName, COMPONENT);
DebugLogger.LogConfiguration($"BOINC Process #{i + 1} Start Time", process.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), COMPONENT);
// Try to get additional information safely
try
{
DebugLogger.LogConfiguration($"BOINC Process #{i + 1} Main Window Title", process.MainWindowTitle ?? "N/A", COMPONENT);
DebugLogger.LogConfiguration($"BOINC Process #{i + 1} Working Set", $"{process.WorkingSet64 / 1024 / 1024} MB", COMPONENT);
}
catch (Exception ex)
{
DebugLogger.LogException(ex, $"Error getting extended info for BOINC process #{i + 1}", COMPONENT);
}
}
catch (Exception ex)
{
DebugLogger.LogException(ex, $"Error getting info for BOINC process #{i + 1}", COMPONENT);
}
}
result.Status = BoincProcessStatus.Running;
result.Message = $"BOINC process is running (PID: {boincProcesses[0].Id})";
}
// Dispose of process objects
DebugLogger.LogInfo("Disposing of process objects", COMPONENT);
foreach (var process in boincProcesses)
{
try
{
process?.Dispose();
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Error disposing process object", COMPONENT);
}
}
});
DebugLogger.LogConfiguration("Final Status", result.Status, COMPONENT);
DebugLogger.LogConfiguration("Final Message", result.Message, COMPONENT);
DebugLogger.LogMethodEnd("CheckBoincProcessAsync", $"Status: {result.Status}", COMPONENT);
return result;
}
catch (Exception ex)
{
DebugLogger.LogException(ex, "Error in CheckBoincProcessAsync", COMPONENT);
result.Status = BoincProcessStatus.Error;
result.ErrorMessage = $"Error checking BOINC process: {ex.Message}";
result.Message = "Failed to check BOINC process status";
DebugLogger.LogMethodEnd("CheckBoincProcessAsync", $"Status: {result.Status} (Exception)", COMPONENT);
return result;
}
}
}
}