-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEditDialog.cs
74 lines (61 loc) · 1.82 KB
/
EditDialog.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
using System;
using System.Windows.Forms;
using System.Net;
namespace HostsManager
{
public partial class EditDialog : Form
{
private HostsEntry entry;
public EditDialog(HostsEntry entry = null)
{
InitializeComponent();
this.entry = entry;
if (this.entry == null)
{
this.Text = "Add new entry";
}
else
{
this.textBox1.Text = entry.Host;
this.textBox2.Text = entry.Address;
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
IPAddress parsedIp = IPAddress.Parse(textBox2.Text);
}
catch (FormatException)
{
MessageBox.Show("Please enter a valid IP address.", "Invalid IP", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (textBox1.TextLength == 0)
{
MessageBox.Show("Please fill in a hostname.", "Missing hostname", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
bool createNew = false;
if (entry == null)
{
createNew = true;
entry = new HostsEntry();
entry.Enabled = true;
}
entry.Host = textBox1.Text;
entry.Address = textBox2.Text;
if (createNew)
{
HostsFileManager.Entries.Add(entry);
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}