Skip to content

Commit a17cdbb

Browse files
committed
Cleaned code.
1 parent ac34636 commit a17cdbb

8 files changed

+124
-107
lines changed

Forms/PluginForm.cs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ protected override void OnFormClosed(FormClosedEventArgs e)
7777
GlobalWindowManager.RemoveWindow(this);
7878
}
7979

80+
#region Event Handler
81+
82+
private void pluginsDataGridView_SelectionChanged(object sender, EventArgs e)
83+
{
84+
UpdatePluginDescription();
85+
}
86+
87+
private void NativeMethodComboBox_SelectionChangeCommitted(object sender, EventArgs e)
88+
{
89+
var cb = sender as ComboBox;
90+
if (cb == null)
91+
{
92+
return;
93+
}
94+
95+
var methodInfo = cb.SelectedItem as NativeHelper.MethodInfo;
96+
if (methodInfo != null)
97+
{
98+
nativeHelper.SetActiveNativeMethod(methodInfo);
99+
}
100+
}
101+
102+
#endregion
103+
80104
private void FillComboBox(ComboBox cb, NativeHelper.RequestFunction method)
81105
{
82106
Contract.Requires(cb != null);
@@ -90,11 +114,6 @@ private void FillComboBox(ComboBox cb, NativeHelper.RequestFunction method)
90114
cb.SelectedIndex = methods.FindIndex(m => m.FunctionPtr == selectedFnPtr);
91115
}
92116

93-
private void pluginsDataGridView_SelectionChanged(object sender, EventArgs e)
94-
{
95-
UpdatePluginDescription();
96-
}
97-
98117
private void UpdatePluginDescription()
99118
{
100119
var row = pluginsDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault();
@@ -113,20 +132,5 @@ private void UpdatePluginDescription()
113132
descriptionLabel.Text = plugin.Description;
114133
}
115134
}
116-
117-
private void NativeMethodComboBox_SelectionChangeCommitted(object sender, EventArgs e)
118-
{
119-
var cb = sender as ComboBox;
120-
if (cb == null)
121-
{
122-
return;
123-
}
124-
125-
var methodInfo = cb.SelectedItem as NativeHelper.MethodInfo;
126-
if (methodInfo != null)
127-
{
128-
nativeHelper.SetActiveNativeMethod(methodInfo);
129-
}
130-
}
131135
}
132136
}

Forms/ProcessBrowserForm.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/ProcessBrowserForm.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,35 @@ protected override void OnFormClosed(FormClosedEventArgs e)
7979
GlobalWindowManager.RemoveWindow(this);
8080
}
8181

82+
#region Event Handler
83+
8284
private void filterCheckBox_CheckedChanged(object sender, EventArgs e)
8385
{
8486
RefreshProcessList();
8587
}
8688

89+
private void filterTextBox_TextChanged(object sender, EventArgs e)
90+
{
91+
ApplyFilter();
92+
}
93+
8794
private void refreshButton_Click(object sender, EventArgs e)
8895
{
8996
RefreshProcessList();
9097
}
9198

92-
private void openProcessButton_Click(object sender, EventArgs e)
99+
private void previousProcessLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
100+
{
101+
filterTextBox.Text = previousProcessLinkLabel.Text == NoPreviousProcess ? string.Empty : previousProcessLinkLabel.Text;
102+
}
103+
104+
private void processDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
93105
{
94-
DialogResult = DialogResult.OK;
106+
AcceptButton.PerformClick();
95107
}
96108

109+
#endregion
110+
97111
/// <summary>Queries all processes and displays them.</summary>
98112
private void RefreshProcessList()
99113
{
@@ -160,11 +174,6 @@ private DateTime GetProcessCreateTime(int pid)
160174
return DateTime.MinValue;
161175
}
162176

163-
private void filterTextBox_TextChanged(object sender, EventArgs e)
164-
{
165-
ApplyFilter();
166-
}
167-
168177
private void ApplyFilter()
169178
{
170179
var filter = filterTextBox.Text;
@@ -174,15 +183,5 @@ private void ApplyFilter()
174183
}
175184
(processDataGridView.DataSource as DataTable).DefaultView.RowFilter = filter;
176185
}
177-
178-
private void previousProcessLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
179-
{
180-
filterTextBox.Text = previousProcessLinkLabel.Text == NoPreviousProcess ? string.Empty : previousProcessLinkLabel.Text;
181-
}
182-
183-
private void processDataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
184-
{
185-
openProcessButton_Click(sender, e);
186-
}
187186
}
188187
}

Forms/ProcessBrowserForm.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,16 @@
129129
<metadata name="pathColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
130130
<value>True</value>
131131
</metadata>
132+
<metadata name="iconColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
133+
<value>True</value>
134+
</metadata>
135+
<metadata name="processNameColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
136+
<value>True</value>
137+
</metadata>
138+
<metadata name="pidColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
139+
<value>True</value>
140+
</metadata>
141+
<metadata name="pathColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
142+
<value>True</value>
143+
</metadata>
132144
</root>

Forms/ProcessMemoryViewForm.Designer.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/ProcessMemoryViewForm.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Linq;
66
using System.Windows.Forms;
77
using ReClassNET.Forms;
8-
using ReClassNET.Nodes;
98
using ReClassNET.UI;
109
using ReClassNET.Util;
1110

@@ -24,8 +23,6 @@ public ProcessMemoryViewer(RemoteProcess process, ClassNodeView classesView)
2423

2524
InitializeComponent();
2625

27-
//BannerFactory.CreateBannerEx(bannerImage, Properties.Resources.B32x32_Magnifier, "Memory Regions", "The list contains all memory regions mapped in the process.");
28-
2926
sectionsDataGridView.AutoGenerateColumns = false;
3027

3128
if (process.IsValid)
@@ -71,6 +68,8 @@ protected override void OnFormClosed(FormClosedEventArgs e)
7168
GlobalWindowManager.RemoveWindow(this);
7269
}
7370

71+
#region Event Handler
72+
7473
private void sectionsDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
7574
{
7675
if (e.Button == MouseButtons.Right)
@@ -83,16 +82,6 @@ private void sectionsDataGridView_CellMouseDown(object sender, DataGridViewCellM
8382
}
8483
}
8584

86-
private IntPtr GetSelectedRegionAddress()
87-
{
88-
var row = sectionsDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.DataBoundItem as DataRowView;
89-
if (row != null)
90-
{
91-
return (IntPtr)(long)row["address"];
92-
}
93-
return IntPtr.Zero;
94-
}
95-
9685
private void setCurrentClassAddressToolStripMenuItem_Click(object sender, EventArgs e)
9786
{
9887
var address = GetSelectedRegionAddress();
@@ -124,9 +113,16 @@ private void sectionsDataGridView_CellMouseDoubleClick(object sender, DataGridVi
124113
setCurrentClassAddressToolStripMenuItem_Click(sender, e);
125114
}
126115

127-
private void ProcessMemoryViewer_Load(object sender, EventArgs e)
128-
{
116+
#endregion
129117

118+
private IntPtr GetSelectedRegionAddress()
119+
{
120+
var row = sectionsDataGridView.SelectedRows.Cast<DataGridViewRow>().FirstOrDefault()?.DataBoundItem as DataRowView;
121+
if (row != null)
122+
{
123+
return (IntPtr)(long)row["address"];
124+
}
125+
return IntPtr.Zero;
130126
}
131127
}
132128
}

UI/BannerFactory.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ public static class BannerFactory
1616
private const int MaxCacheEntries = 20;
1717
private static readonly Dictionary<string, Image> imageCache = new Dictionary<string, Image>();
1818

19+
/// <summary>Creates a banner with the given <paramref name="icon"/>, <paramref name="title"/> and <paramref name="text"/>.</summary>
20+
/// <param name="bannerWidth">Width of the banner.</param>
21+
/// <param name="bannerHeight">Height of the banner.</param>
22+
/// <param name="icon">The icon of the banner.</param>
23+
/// <param name="title">The title of the banner.</param>
24+
/// <param name="text">The text of the banner.</param>
25+
/// <param name="skipCache">True to skip cache.</param>
26+
/// <returns>The created banner.</returns>
1927
public static Image CreateBanner(int bannerWidth, int bannerHeight, Image icon, string title, string text, bool skipCache)
2028
{
2129
Contract.Requires(title != null);
@@ -41,8 +49,8 @@ public static Image CreateBanner(int bannerWidth, int bannerHeight, Image icon,
4149
int hIconScaled = StdIconDim;
4250
if (icon != null)
4351
{
44-
float fIconRel = (float)icon.Width / (float)icon.Height;
45-
wIconScaled = (int)Math.Round(DpiScaleFloat(fIconRel * (float)StdIconDim, bannerHeight));
52+
float iconRel = (float)icon.Width / (float)icon.Height;
53+
wIconScaled = (int)Math.Round(DpiScaleFloat(iconRel * (float)StdIconDim, bannerHeight));
4654
hIconScaled = DpiScaleInt(StdIconDim, bannerHeight);
4755

4856
int yIcon = (bannerHeight - hIconScaled) / 2;
@@ -116,14 +124,8 @@ private static void DrawText(Graphics g, string text, int x, int y, Font font, C
116124
}
117125
}
118126

119-
private static int DpiScaleInt(int x, int height)
120-
{
121-
return (int)Math.Round((x * height) / (double)StdHeight);
122-
}
127+
private static int DpiScaleInt(int x, int height) => (int)Math.Round((x * height) / (double)StdHeight);
123128

124-
private static float DpiScaleFloat(float x, int height)
125-
{
126-
return (x * height) / StdHeight;
127-
}
129+
private static float DpiScaleFloat(float x, int height) => (x * height) / StdHeight;
128130
}
129131
}

UI/ClassNodeView.cs

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,49 +156,7 @@ public ClassNodeView()
156156
classesTreeView.Nodes.Add(root);
157157
}
158158

159-
/// <summary>Adds the class to the view.</summary>
160-
/// <param name="node">The class to add.</param>
161-
public void Add(ClassNode node)
162-
{
163-
Contract.Requires(node != null);
164-
165-
root.Nodes.Add(new ClassTreeNode(node, autoExpand));
166-
167-
classesTreeView.Sort();
168-
169-
root.Expand();
170-
}
171-
172-
/// <summary>Removes the class from the view.</summary>
173-
/// <param name="node">The class to remove.</param>
174-
public void Remove(ClassNode node)
175-
{
176-
var tn = FindClassTreeNode(node);
177-
if (tn != null)
178-
{
179-
root.Nodes.Remove(tn);
180-
181-
if (selectedClass == node)
182-
{
183-
if (root.Nodes.Count > 0)
184-
{
185-
classesTreeView.SelectedNode = root.Nodes[0];
186-
}
187-
else
188-
{
189-
SelectedClass = null;
190-
}
191-
}
192-
}
193-
}
194-
195-
/// <summary>Searches for the ClassTreeNode which represents the class.</summary>
196-
/// <param name="node">The class to search.</param>
197-
/// <returns>The found class tree node.</returns>
198-
private ClassTreeNode FindClassTreeNode(ClassNode node)
199-
{
200-
return root.Nodes.OfType<ClassTreeNode>().Where(t => t.ClassNode == node).FirstOrDefault();
201-
}
159+
#region Event Handler
202160

203161
private void classesTreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
204162
{
@@ -304,5 +262,51 @@ private void collapseAllClassesToolStripMenuItem_Click(object sender, EventArgs
304262
{
305263
root.Nodes.Cast<TreeNode>().ForEach(n => n.Collapse());
306264
}
265+
266+
#endregion
267+
268+
/// <summary>Adds the class to the view.</summary>
269+
/// <param name="node">The class to add.</param>
270+
public void Add(ClassNode node)
271+
{
272+
Contract.Requires(node != null);
273+
274+
root.Nodes.Add(new ClassTreeNode(node, autoExpand));
275+
276+
classesTreeView.Sort();
277+
278+
root.Expand();
279+
}
280+
281+
/// <summary>Removes the class from the view.</summary>
282+
/// <param name="node">The class to remove.</param>
283+
public void Remove(ClassNode node)
284+
{
285+
var tn = FindClassTreeNode(node);
286+
if (tn != null)
287+
{
288+
root.Nodes.Remove(tn);
289+
290+
if (selectedClass == node)
291+
{
292+
if (root.Nodes.Count > 0)
293+
{
294+
classesTreeView.SelectedNode = root.Nodes[0];
295+
}
296+
else
297+
{
298+
SelectedClass = null;
299+
}
300+
}
301+
}
302+
}
303+
304+
/// <summary>Searches for the ClassTreeNode which represents the class.</summary>
305+
/// <param name="node">The class to search.</param>
306+
/// <returns>The found class tree node.</returns>
307+
private ClassTreeNode FindClassTreeNode(ClassNode node)
308+
{
309+
return root.Nodes.OfType<ClassTreeNode>().Where(t => t.ClassNode == node).FirstOrDefault();
310+
}
307311
}
308312
}

0 commit comments

Comments
 (0)