-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwndSettings.cs
87 lines (74 loc) · 2.9 KB
/
wndSettings.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
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WalkieTalkie
{
public partial class wndSettings : Form
{
public wndSettings()
{
InitializeComponent();
}
public new DialogResult ShowDialog()
{
RegistryKey key;
DialogResult result;
string startupCommand;
txtUserName.Text = Configuration.UserName;
txtIPAddress.Text = Configuration.LANIP.ToString();
key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
startupCommand = (string)key.GetValue("WalkieTalkie", null);
key.Close();
if (startupCommand != null)
{
chkAutoStart.Checked = true;
if (startupCommand.Contains("systray"))
chkStartMinimized.Checked = true;
}
chkShowGroupNotification.Checked = Configuration.GroupChatNotifications;
result = base.ShowDialog();
if (result == DialogResult.OK)
{
Configuration.SaveConfiguration();
MessageBox.Show("The new settings will take effect after restarting the program.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return result;
}
private void btnOK_Click(object sender, EventArgs e)
{
RegistryKey key;
string startupCommand;
if (txtUserName.Text.Contains(" "))
{
MessageBox.Show("Username cannot have embedded spaces.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
try
{
Configuration.UserName = txtUserName.Text;
System.Net.IPAddress tIPAdd;
if (!System.Net.IPAddress.TryParse(txtIPAddress.Text, out tIPAdd))
{
MessageBox.Show("Invalid IP Address.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
Configuration.LANIP = tIPAdd;
if (chkAutoStart.Checked)
{
key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
startupCommand = Application.ExecutablePath;
if (chkStartMinimized.Checked)
startupCommand += " -systray";
key.SetValue("WalkieTalkie", startupCommand);
key.Close();
}
Configuration.GroupChatNotifications = chkShowGroupNotification.Checked;
this.DialogResult = DialogResult.OK;
}
catch (Exception) { }
}
}
}