This repository was archived by the owner on Jan 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSetting.cs
More file actions
231 lines (199 loc) · 8.01 KB
/
Setting.cs
File metadata and controls
231 lines (199 loc) · 8.01 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
using System;
using System.Diagnostics;
using System.IO;
using System.Media;
using System.Net;
using System.Windows.Forms;
namespace PingoMeter
{
public partial class Setting : Form
{
bool loaded;
SoundPlayer testPlay;
public Setting()
{
InitializeComponent();
SyncFromConfig();
labelVersion.Text = "Version " + Program.VERSION;
toolTip1.SetToolTip(numbersModeCheckBox, "Use numbers for the ping instead of a graph.");
pingTimeoutSFXBtn.Click += SelectWAV;
connectionLostSFXBtn.Click += SelectWAV;
connectionResumeSFXBtn.Click += SelectWAV;
pingTimeoutSFXBtn.MouseDown += (s, e) => ClearSFX(pingTimeoutSFXBtn, e);
connectionLostSFXBtn.MouseDown += (s, e) => ClearSFX(connectionLostSFXBtn, e);
connectionResumeSFXBtn.MouseDown += (s, e) => ClearSFX(connectionResumeSFXBtn, e);
if (Utils.IsWindows8Next())
{
cbStartupRun.Enabled = false;
cbStartupRun.Visible = false;
Config.RunOnStartup = false;
}
loaded = true;
}
private void SyncToConfig(IPAddress address)
{
Config.SetAll(
delay: (int)delay.Value,
maxPing: (int)maxPing.Value,
bgColor: setBgColor.BackColor,
goodColor: setGoodColor.BackColor,
normalColor: setNormalColor.BackColor,
badColor: setBadColor.BackColor,
runOnStartup: cbStartupRun.Checked,
address: address,
alarmConnectionLost: alarmConnectionLost.Checked,
alarmTimeOut: alarmTimeOut.Checked,
alarmResumed: alarmResumed.Checked,
useNumbers: numbersModeCheckBox.Checked,
_SFXConnectionLost: toolTip1.GetToolTip(connectionLostSFXBtn),
_SFXTimeOut: toolTip1.GetToolTip(pingTimeoutSFXBtn),
_SFXResumed: toolTip1.GetToolTip(connectionResumeSFXBtn),
offlineCounter: cbOfflineCounter.Checked);
}
private void SyncFromConfig()
{
delay.Value = Config.Delay;
maxPing.Value = Config.MaxPing;
setBgColor.BackColor = Config.BgColor.Color;
setGoodColor.BackColor = Config.GoodColor.Color;
setNormalColor.BackColor = Config.NormalColor.Color;
setBadColor.BackColor = Config.BadColor.Color;
alarmTimeOut.Checked = Config.AlarmTimeOut;
alarmConnectionLost.Checked = Config.AlarmConnectionLost;
alarmResumed.Checked = Config.AlarmResumed;
numbersModeCheckBox.Checked = Config.UseNumbers;
cbStartupRun.Checked = Config.RunOnStartup;
cbOfflineCounter.Checked = Config.OfflineCounter;
//isStartUp.Checked = Config.s_runOnStartup;
if (Config.TheIPAddress != null)
ipAddress.Text = Config.TheIPAddress.ToString();
SetSoundInfoForButtom(pingTimeoutSFXBtn, Config.SFXTimeOut);
SetSoundInfoForButtom(connectionLostSFXBtn, Config.SFXConnectionLost);
SetSoundInfoForButtom(connectionResumeSFXBtn, Config.SFXResumed);
}
private void ClearSFX(Button button, MouseEventArgs mouseEvent)
{
if (mouseEvent.Button == MouseButtons.Right)
SetSoundInfoForButtom(button, null);
}
private void SetSoundInfoForButtom(Button button, string pathToFile)
{
if (string.IsNullOrWhiteSpace(pathToFile) || pathToFile == Config.NONE_SFX || !File.Exists(pathToFile))
{
button.Text = Config.NONE_SFX;
toolTip1.SetToolTip(button, Config.NONE_SFX);
}
else
{
button.Text = Path.GetFileNameWithoutExtension(pathToFile);
toolTip1.SetToolTip(button, pathToFile);
if (loaded)
{
if (testPlay == null)
testPlay = new SoundPlayer();
if (testPlay.SoundLocation != pathToFile)
{
testPlay.SoundLocation = pathToFile;
try
{
testPlay.Load();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\nFile: " + pathToFile, "Load sound error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
if (testPlay.IsLoadCompleted)
testPlay.Play();
}
}
}
private void SelectWAV(object senderAsButton, EventArgs e)
{
var dialog = new OpenFileDialog
{
CheckFileExists = true,
DefaultExt = "",
InitialDirectory = @"C:\Windows\Media\",
// Filter string you provided is not valid. The filter string must contain a description of the filter,
// followed by the vertical bar (|) and the filter pattern. The strings for different filtering options
// must also be separated by the vertical bar.
// Example: "Text files (*.txt)|*.txt|All files (*.*)|*.*"
Filter = "WAV file (*.wav)|*.wav",
Multiselect = false,
Title = "Select .wav file",
};
if (dialog.ShowDialog() == DialogResult.OK)
{
SetSoundInfoForButtom((Button)senderAsButton, dialog.FileName);
}
dialog.Dispose();
}
private void SetBgColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setBgColor.BackColor = colorDialog1.Color;
}
}
private void SetGoodColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setGoodColor.BackColor = colorDialog1.Color;
}
}
private void SetNormalColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setNormalColor.BackColor = colorDialog1.Color;
}
}
private void SetBadColor_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
setBadColor.BackColor = colorDialog1.Color;
}
}
private void Apply_Click(object sender, EventArgs e)
{
// check ip address
if (!IPAddress.TryParse(ipAddress.Text, out IPAddress address))
{
MessageBox.Show("IP Address is invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
SyncToConfig(address);
Config.Save();
Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
Close();
}
private void Reset_Click(object sender, EventArgs e)
{
if (MessageBox.Show(
"Reset all settings to default?",
"Reset all?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question)
== DialogResult.Yes)
{
Config.Reset();
SyncFromConfig();
}
}
private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("https://github.com/EFLFE/PingoMeter");
}
private void numbersModeCheckBox_CheckedChanged(object sender, EventArgs e)
{
graphColorsGroupBox.Visible = !numbersModeCheckBox.Checked;
}
}
}