Skip to content

Commit f024d1a

Browse files
committed
Extracted methods to individual classes.
1 parent 5bfdc2e commit f024d1a

7 files changed

Lines changed: 88 additions & 73 deletions

File tree

ReClass.NET/Forms/ScannerForm.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,9 @@ int CalculateSignificantDigits(string input, NumberFormatInfo numberFormat)
764764
return digits;
765765
}
766766

767-
var nf1 = Utils.GuessNumberFormat(dualValueBox.Value1);
767+
var nf1 = NumberFormat.GuessNumberFormat(dualValueBox.Value1);
768768
if (!double.TryParse(dualValueBox.Value1, NumberStyles.Float, nf1, out var value1)) throw new InvalidInputException(dualValueBox.Value1);
769-
var nf2 = Utils.GuessNumberFormat(dualValueBox.Value2);
769+
var nf2 = NumberFormat.GuessNumberFormat(dualValueBox.Value2);
770770
if (!double.TryParse(dualValueBox.Value2, NumberStyles.Float, nf2, out var value2) && checkBothInputFields) throw new InvalidInputException(dualValueBox.Value2);
771771

772772
var significantDigits = Math.Max(

ReClass.NET/MemoryScanner/MemoryRecord.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void SetValue(RemoteProcess process, string input, bool isHex)
253253
}
254254
else if (ValueType == ScanValueType.Float || ValueType == ScanValueType.Double)
255255
{
256-
var nf = Utils.GuessNumberFormat(input);
256+
var nf = NumberFormat.GuessNumberFormat(input);
257257
double.TryParse(input, NumberStyles.Float, nf, out var value);
258258

259259
switch (ValueType)
@@ -281,7 +281,7 @@ public void SetValue(RemoteProcess process, string input, bool isHex)
281281
private static string FormatValue(long value, bool showAsHex) => showAsHex ? value.ToString("X") : value.ToString();
282282
private static string FormatValue(float value) => value.ToString("0.0000");
283283
private static string FormatValue(double value) => value.ToString("0.0000");
284-
private static string FormatValue(byte[] value) => Utils.ByteArrayToHexString(value);
284+
private static string FormatValue(byte[] value) => HexadecimalFormatter.ToString(value);
285285
private static string FormatValue(string value) => value;
286286
}
287287
}

ReClass.NET/Nodes/ClassNode.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ public override Size Draw(ViewInfo view, int x, int y)
133133
nv.Level++;
134134
foreach (var node in Nodes)
135135
{
136+
Size AggregateNodeSizes(Size baseSize, Size newSize)
137+
{
138+
return new Size(Math.Max(baseSize.Width, newSize.Width), baseSize.Height + newSize.Height);
139+
}
140+
136141
// Draw the node if it is in the visible area.
137142
if (view.ClientArea.Contains(tx, y))
138143
{
139144
var innerSize = node.Draw(nv, tx, y);
140145

141-
size = Utils.AggregateNodeSizes(size, innerSize.Extend(childOffset, 0));
146+
size = AggregateNodeSizes(size, innerSize.Extend(childOffset, 0));
142147

143148
y += innerSize.Height;
144149
}
@@ -153,14 +158,14 @@ public override Size Draw(ViewInfo view, int x, int y)
153158
// then draw the node...
154159
var innerSize = node.Draw(nv, tx, y);
155160

156-
size = Utils.AggregateNodeSizes(size, innerSize.Extend(childOffset, 0));
161+
size = AggregateNodeSizes(size, innerSize.Extend(childOffset, 0));
157162

158163
y += innerSize.Height;
159164
}
160165
else
161166
{
162167
// or skip drawing and just use the calculated height.
163-
size = Utils.AggregateNodeSizes(size, new Size(0, calculatedHeight));
168+
size = AggregateNodeSizes(size, new Size(0, calculatedHeight));
164169

165170
y += calculatedHeight;
166171
}

ReClass.NET/ReClass.NET.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,9 @@
505505
<Compile Include="UI\GlobalWindowManager.cs" />
506506
<Compile Include="UI\ViewInfo.cs" />
507507
<Compile Include="Extensions\LinqExtensions.cs" />
508+
<Compile Include="Util\HexadecimalFormatter.cs" />
508509
<Compile Include="Util\IntPtrComparer.cs" />
510+
<Compile Include="Util\NumberFormat.cs" />
509511
<Compile Include="Util\PathUtil.cs" />
510512
<Compile Include="Util\Rtf\RtfBuilder.cs" />
511513
<Compile Include="Util\Rtf\RtfBuilder.RtfFormatLock.cs" />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Diagnostics.Contracts;
2+
3+
namespace ReClassNET.Util
4+
{
5+
public static class HexadecimalFormatter
6+
{
7+
private static readonly uint[] lookup = CreateHexLookup();
8+
9+
private static uint[] CreateHexLookup()
10+
{
11+
var result = new uint[256];
12+
for (var i = 0; i < 256; i++)
13+
{
14+
var s = i.ToString("X2");
15+
result[i] = (uint)s[0] + ((uint)s[1] << 16);
16+
}
17+
return result;
18+
}
19+
20+
public static string ToString(byte[] data)
21+
{
22+
Contract.Requires(data != null);
23+
24+
if (data.Length == 0)
25+
{
26+
return string.Empty;
27+
}
28+
29+
var result = new char[data.Length * 2 + data.Length - 1];
30+
31+
var val = lookup[data[0]];
32+
result[0] = (char)val;
33+
result[1] = (char)(val >> 16);
34+
35+
for (var i = 1; i < data.Length; i++)
36+
{
37+
val = lookup[data[i]];
38+
result[3 * i - 1] = ' ';
39+
result[3 * i] = (char)val;
40+
result[3 * i + 1] = (char)(val >> 16);
41+
}
42+
43+
return new string(result);
44+
}
45+
}
46+
}

ReClass.NET/Util/NumberFormat.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Diagnostics.Contracts;
2+
using System.Globalization;
3+
4+
namespace ReClassNET.Util
5+
{
6+
public class NumberFormat
7+
{
8+
public static NumberFormatInfo GuessNumberFormat(string input)
9+
{
10+
Contract.Requires(input != null);
11+
Contract.Ensures(Contract.Result<NumberFormatInfo>() != null);
12+
13+
if (input.Contains(",") && !input.Contains("."))
14+
{
15+
return new NumberFormatInfo
16+
{
17+
NumberDecimalSeparator = ",",
18+
NumberGroupSeparator = "."
19+
};
20+
}
21+
return new NumberFormatInfo
22+
{
23+
NumberDecimalSeparator = ".",
24+
NumberGroupSeparator = ","
25+
};
26+
}
27+
}
28+
}

ReClass.NET/Util/Util.cs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
4-
using System.Drawing;
5-
using System.Globalization;
64

75
namespace ReClassNET.Util
86
{
@@ -52,69 +50,5 @@ public static void Swap<T>(ref T lhs, ref T rhs)
5250
lhs = rhs;
5351
rhs = temp;
5452
}
55-
56-
public static Size AggregateNodeSizes(Size baseSize, Size newSize)
57-
{
58-
return new Size(Math.Max(baseSize.Width, newSize.Width), baseSize.Height + newSize.Height);
59-
}
60-
61-
public static NumberFormatInfo GuessNumberFormat(string input)
62-
{
63-
Contract.Requires(input != null);
64-
Contract.Ensures(Contract.Result<NumberFormatInfo>() != null);
65-
66-
if (input.Contains(",") && !input.Contains("."))
67-
{
68-
return new NumberFormatInfo
69-
{
70-
NumberDecimalSeparator = ",",
71-
NumberGroupSeparator = "."
72-
};
73-
}
74-
return new NumberFormatInfo
75-
{
76-
NumberDecimalSeparator = ".",
77-
NumberGroupSeparator = ","
78-
};
79-
}
80-
81-
private static readonly uint[] hexLookup = CreateHexLookup();
82-
83-
private static uint[] CreateHexLookup()
84-
{
85-
var result = new uint[256];
86-
for (var i = 0; i < 256; i++)
87-
{
88-
var s = i.ToString("X2");
89-
result[i] = (uint)s[0] + ((uint)s[1] << 16);
90-
}
91-
return result;
92-
}
93-
94-
public static string ByteArrayToHexString(byte[] data)
95-
{
96-
Contract.Requires(data != null);
97-
98-
if (data.Length == 0)
99-
{
100-
return string.Empty;
101-
}
102-
103-
var lookup = hexLookup;
104-
var result = new char[data.Length * 2 + data.Length - 1];
105-
106-
var val = lookup[data[0]];
107-
result[0] = (char)val;
108-
result[1] = (char)(val >> 16);
109-
110-
for (var i = 1; i < data.Length; i++)
111-
{
112-
val = lookup[data[i]];
113-
result[3 * i - 1] = ' ';
114-
result[3 * i] = (char)val;
115-
result[3 * i + 1] = (char)(val >> 16);
116-
}
117-
return new string(result);
118-
}
11953
}
12054
}

0 commit comments

Comments
 (0)