This repository was archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemoryTrackerForm.cs
More file actions
87 lines (71 loc) · 2.67 KB
/
MemoryTrackerForm.cs
File metadata and controls
87 lines (71 loc) · 2.67 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MaplestoryMemoryTracker
{
public partial class MemoryTrackerForm : Form
{
private readonly Timer _memoryTrackerTimer = new Timer();
private const string ProcessName = "MapleStory";
public MemoryTrackerForm()
{
InitializeComponent();
_memoryTrackerTimer.Interval = 5000; // Every 5 seconds, check status of maple
_memoryTrackerTimer.Tick += MemoryTrackerTimerOnTick;
_memoryTrackerTimer.Start();
// Trigger a tick immediately;
MemoryTrackerTimerOnTick();
}
private void MemoryTrackerTimerOnTick(object sender = null, EventArgs e = null)
{
var processList = Process.GetProcessesByName(ProcessName);
if (processList.Length == 0)
{
MemoryStatusLabel.Text = @"Game not running...";
this.ResetBackColor();
MemoryStatusLabel.ForeColor = Color.Black;
return;
}
var process = processList[0];
process.Refresh(); // Clear cache
var sizeInGigabytes = ToGigabyte(process.WorkingSet64);
// Now check how unstable this is
var maxGood = (long) (2 /* Gigabytes */ * Math.Pow(1024, 3));
var maxForGrinding = (long) Math.Floor(2.8 * Math.Pow(1024, 3));
string status;
if (process.WorkingSet64 <= maxGood)
{
status = "All Good";
BackColor = Color.LimeGreen;
MemoryStatusLabel.ForeColor = Color.Black;
} else if (process.WorkingSet64 <= maxForGrinding)
{
status = "Warning";
BackColor = Color.Yellow;
MemoryStatusLabel.ForeColor = Color.Black;
}
else
{
status = "Danger!";
BackColor = Color.Red;
MemoryStatusLabel.ForeColor = Color.White;
}
MemoryStatusLabel.Text = $@"{status} ({sizeInGigabytes} GB)";
}
private static string ToGigabyte(long value)
{
return (value / Math.Pow(1024, 3)).ToString("0.000");
}
private void OnForegroundCheckboxChanged(object sender, EventArgs e)
{
TopMost = ForceForegroundCheckbox.Checked;
}
}
}