Repository navigation
Expand file tree
/
Copy pathPerformanceMonitorForm.cs
More file actions
288 lines (261 loc) · 9.53 KB
/
Copy pathPerformanceMonitorForm.cs
File metadata and controls
288 lines (261 loc) · 9.53 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
using System;
using System.Diagnostics;
using System.Drawing;
using System.Management;
using System.Windows.Forms;
namespace Exoptimizer
{
public partial class PerformanceMonitorForm : Form
{
private System.Windows.Forms.Timer? updateTimer;
private Label? cpuLabel;
private Label? memoryLabel;
private Label? networkLabel;
private Label? processLabel;
public PerformanceMonitorForm()
{
InitializeComponent();
SetupTimer();
}
private void InitializeComponent()
{
this.SuspendLayout();
// Set application icon
try
{
string iconPath = System.IO.Path.Combine(Application.StartupPath, "icon-new.ico");
if (System.IO.File.Exists(iconPath))
{
this.Icon = new Icon(iconPath);
}
else
{
// Try alternative path
iconPath = System.IO.Path.Combine(Application.StartupPath, "..", "assets", "icon-new.ico");
if (System.IO.File.Exists(iconPath))
{
this.Icon = new Icon(iconPath);
}
}
}
catch
{
// Use default icon if loading fails
}
// Form properties - Native Windows styling
this.Text = " PulseBoost Performance Monitor";
this.Size = new Size(600, 400);
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = SystemColors.Control;
this.ForeColor = SystemColors.ControlText;
this.Font = SystemFonts.DefaultFont;
// Header
var headerLabel = new Label
{
Text = "PulseBoost Performance Monitor - Real Time",
Font = new Font(SystemFonts.CaptionFont.FontFamily, 14F, FontStyle.Bold),
ForeColor = SystemColors.HotTrack,
Location = new Point(20, 20),
Size = new Size(500, 30)
};
// Performance labels
cpuLabel = new Label
{
Text = "CPU Usage: Loading...",
Location = new Point(20, 70),
Size = new Size(500, 25),
Font = new Font("Consolas", 10F)
};
memoryLabel = new Label
{
Text = "Memory Usage: Loading...",
Location = new Point(20, 100),
Size = new Size(500, 25),
Font = new Font("Consolas", 10F)
};
networkLabel = new Label
{
Text = "Network Latency: Testing...",
Location = new Point(20, 130),
Size = new Size(500, 25),
Font = new Font("Consolas", 10F)
};
processLabel = new Label
{
Text = "VALORANT Processes: Checking...",
Location = new Point(20, 160),
Size = new Size(500, 100),
Font = new Font("Consolas", 9F)
};
var closeButton = new Button
{
Text = "Close",
Size = new Size(100, 30),
Location = new Point(480, 320),
Font = SystemFonts.DefaultFont,
FlatStyle = FlatStyle.System
};
closeButton.Click += (s, e) => this.Close();
this.Controls.AddRange(new Control[] {
headerLabel, cpuLabel, memoryLabel, networkLabel, processLabel, closeButton
});
this.ResumeLayout(false);
}
private void SetupTimer()
{
updateTimer = new System.Windows.Forms.Timer
{
Interval = 2000 // Update every 2 seconds
};
updateTimer.Tick += UpdatePerformanceData;
updateTimer.Start();
}
private void UpdatePerformanceData(object? sender, EventArgs e)
{
try
{
UpdateCpuUsage();
UpdateMemoryUsage();
UpdateNetworkLatency();
UpdateValorantProcesses();
}
catch (Exception ex)
{
if (cpuLabel != null)
{
cpuLabel.Text = $"Error updating data: {ex.Message}";
}
}
}
private void UpdateCpuUsage()
{
try
{
using var searcher = new ManagementObjectSearcher("select * from Win32_PerfRawData_PerfOS_Processor where Name='_Total'");
foreach (ManagementObject obj in searcher.Get())
{
var usage = GetCpuUsage();
if (cpuLabel != null)
{
cpuLabel.Text = $"CPU Usage: {usage:F1}%";
cpuLabel.ForeColor = usage > 80 ? Color.Red : usage > 50 ? Color.Orange : Color.Green;
}
break;
}
}
catch
{
if (cpuLabel != null)
{
cpuLabel.Text = "CPU Usage: Unable to retrieve";
}
}
}
private static double GetCpuUsage()
{
using var pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
pc.NextValue(); // First call returns 0
System.Threading.Thread.Sleep(100);
return pc.NextValue();
}
private void UpdateMemoryUsage()
{
try
{
using var searcher = new ManagementObjectSearcher("SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem");
foreach (ManagementObject obj in searcher.Get())
{
var total = Convert.ToDouble(obj["TotalVisibleMemorySize"]) / 1024 / 1024; // Convert to GB
var free = Convert.ToDouble(obj["FreePhysicalMemory"]) / 1024 / 1024;
var used = total - free;
var percentage = (used / total) * 100;
if (memoryLabel != null)
{
memoryLabel.Text = $"Memory Usage: {used:F1}GB / {total:F1}GB ({percentage:F1}%)";
memoryLabel.ForeColor = percentage > 80 ? Color.Red : percentage > 60 ? Color.Orange : Color.Green;
}
break;
}
}
catch
{
if (memoryLabel != null)
{
memoryLabel.Text = "Memory Usage: Unable to retrieve";
}
}
}
private void UpdateNetworkLatency()
{
try
{
var ping = new System.Net.NetworkInformation.Ping();
var reply = ping.Send("8.8.8.8", 1000);
if (networkLabel != null)
{
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
{
networkLabel.Text = $"Network Latency: {reply.RoundtripTime}ms (Google DNS)";
networkLabel.ForeColor = reply.RoundtripTime > 100 ? Color.Red :
reply.RoundtripTime > 50 ? Color.Orange : Color.Green;
}
else
{
networkLabel.Text = "Network Latency: Connection failed";
networkLabel.ForeColor = Color.Red;
}
}
}
catch
{
if (networkLabel != null)
{
networkLabel.Text = "Network Latency: Unable to test";
}
}
}
private void UpdateValorantProcesses()
{
try
{
var processes = Process.GetProcessesByName("VALORANT-Win64-Shipping");
var riotProcesses = Process.GetProcessesByName("RiotClientServices");
string processInfo = "VALORANT Processes:\n";
if (processes.Length > 0)
{
processInfo += $"• VALORANT: Running (PID: {processes[0].Id})\n";
}
else
{
processInfo += "• VALORANT: Not running\n";
}
if (riotProcesses.Length > 0)
{
processInfo += $"• Riot Client: Running (PID: {riotProcesses[0].Id})";
}
else
{
processInfo += "• Riot Client: Not running";
}
if (processLabel != null)
{
processLabel.Text = processInfo;
processLabel.ForeColor = (processes.Length > 0 || riotProcesses.Length > 0) ? Color.Green : SystemColors.GrayText;
}
}
catch
{
if (processLabel != null)
{
processLabel.Text = "VALORANT Processes: Unable to check";
}
}
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
updateTimer?.Stop();
updateTimer?.Dispose();
base.OnFormClosed(e);
}
}
}