-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormMain.cs
108 lines (101 loc) · 3.31 KB
/
FormMain.cs
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
namespace Base64Decoder
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void buttonDecode64_Click(object sender, EventArgs e)
{
try
{
if (String.IsNullOrWhiteSpace(textBase64.Text))
{
hexBox.ByteProvider = null;
}
else
{
byte[] data = Convert.FromBase64String(textBase64.Text);
var byteProvider = new ArrayByteProvider(data);
hexBox.ByteProvider = byteProvider;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void buttonClear_Click(object sender, EventArgs e)
{
try
{
textBase64.Text = null;
hexBox.ByteProvider = null;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void hexBox_CurrentLineChanged(object sender, EventArgs e)
{
UpdatePosition();
}
private void hexBox_CurrentPositionInLineChanged(object sender, EventArgs e)
{
UpdatePosition();
}
private void UpdatePosition()
{
try
{
long pos = hexBox.BytesPerLine * (hexBox.CurrentLine - 1) + hexBox.CurrentPositionInLine - 1;
if (pos < 0)
pos = 0;
toolStripStatusPosition.Text = String.Format("Position: {0}", pos);
if (hexBox.ByteProvider != null && hexBox.ByteProvider.Length > pos)
{
byte b = hexBox.ByteProvider.ReadByte(pos);
toolStripStatusByteDec.Text = Convert.ToString(b);
toolStripStatusByteBin.Text = Convert.ToString(b, 2).PadLeft(8, '0').Insert(4, " ");
}
else
{
toolStripStatusByteDec.Text = "?";
toolStripStatusByteBin.Text = "???? ????";
}
}
catch (Exception)
{
toolStripStatusPosition.Text = String.Format("Position: {0}", 0);
toolStripStatusByteDec.Text = "?";
toolStripStatusByteBin.Text = "???? ????";
}
}
private void toolStripStatusWeb_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo("https://www.sntcz.cz") { UseShellExecute = true });
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
private void toolStripStatusSupport_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo("https://github.com/sntcz/Base64Decoder/issues") { UseShellExecute = true });
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
}
}
}