Mercurial > servermonitor
annotate ServerMonitor/Forms/SettingsForm.cs @ 40:c4fc74593a78 default tip
Mono fix
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 13 Jun 2020 13:28:20 -0400 |
parents | 7645122aa7a9 |
children |
rev | line source |
---|---|
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
1 using Microsoft.Win32; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
2 using ServerMonitorApp.Properties; |
4 | 3 using System; |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
4 using System.IO; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
5 using System.Linq; |
4 | 6 using System.Text.RegularExpressions; |
7 using System.Windows.Forms; | |
8 | |
9 namespace ServerMonitorApp | |
10 { | |
16 | 11 /// <summary>Application settings form.</summary> |
4 | 12 public partial class SettingsForm : Form |
13 { | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
14 private readonly string autorunKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
15 private readonly string autorunName = "ServerMonitor"; |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
16 private readonly string[] soundOptions = { "None", "Windows error", "Custom sound..." }; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
17 private readonly int customSoundIndex = 2; |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
18 |
4 | 19 public SettingsForm() |
20 { | |
21 InitializeComponent(); | |
22 } | |
23 | |
24 private void SettingsForm_Load(object sender, EventArgs e) | |
25 { | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
26 Icon = Resources.icon; |
16 | 27 // Populate each action combo box with the available actions to perform on failure. |
4 | 28 foreach (ComboBox comboBox in new object[] { ErrorComboBox, WarningComboBox, InformationComboBox }) |
29 { | |
30 comboBox.DataSource = Enum.GetValues(typeof(FailAction)); | |
31 comboBox.Format += FailActionComboBox_Format; | |
32 } | |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
33 // Populate the sound options combo boxes. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
34 foreach (ComboBox comboBox in new object[] { ErrorSoundComboBox, WarningSoundComboBox, InformationSoundComboBox }) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
35 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
36 comboBox.Items.AddRange(soundOptions); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
37 // Add the already-selected custom sound, if any. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
38 if (getSoundSettingIndex(comboBox) == customSoundIndex) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
39 comboBox.Items.Insert(customSoundIndex, getSoundSetting(comboBox)); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
40 } |
16 | 41 // Initialize controls with current settings. |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
42 AutorunCheckBox.Checked = GetAutorun(); |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
8
diff
changeset
|
43 KeepRunningCheckBox.Checked = Settings.Default.HideToNotificationArea; |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
44 KeepLogDaysInput.Value = Settings.Default.KeepLogDays; |
4 | 45 ErrorComboBox.SelectedItem = Settings.Default.ErrorAction; |
46 WarningComboBox.SelectedItem = Settings.Default.WarningAction; | |
47 InformationComboBox.SelectedItem = Settings.Default.InformationAction; | |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
48 ErrorSoundComboBox.SelectedIndex = getSoundSettingIndex(ErrorSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
49 WarningSoundComboBox.SelectedIndex = getSoundSettingIndex(WarningSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
50 InformationSoundComboBox.SelectedIndex = getSoundSettingIndex(InformationSoundComboBox); |
40 | 51 |
52 AutorunCheckBox.Enabled = !Helpers.IsMono(); | |
4 | 53 } |
54 | |
16 | 55 /// <summary>Gets whether an autorun registry key for this program exists.</summary> |
56 /// <returns>Whether an autorun registry key for this program exists</returns> | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
57 private bool GetAutorun() |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
58 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
59 RegistryKey key = Registry.CurrentUser.OpenSubKey(autorunKey, false); |
40 | 60 if (key == null) |
61 { | |
62 return false; | |
63 } | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
64 string value = (string)key.GetValue(autorunName, string.Empty); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
65 return value.StartsWith(Application.ExecutablePath); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
66 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
67 |
16 | 68 /// <summary>Sets whether this program should automatically start with Windows.</summary> |
69 /// <param name="autorun">Whether autorun should be enabled or disabled.</param> | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
70 private void SetAutorun(bool autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
71 { |
40 | 72 if (Helpers.IsMono()) |
73 { | |
74 return; | |
75 } | |
76 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
77 RegistryKey key = Registry.CurrentUser.OpenSubKey(autorunKey, true); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
78 if (autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
79 key.SetValue(autorunName, Application.ExecutablePath.ToString()); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
80 else |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
81 key.DeleteValue(autorunName, false); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
82 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
83 |
16 | 84 /// <summary>Shows a human readable description of possible check failure actions in the combo box.</summary> |
4 | 85 private void FailActionComboBox_Format(object sender, ListControlConvertEventArgs e) |
86 { | |
16 | 87 // Transform the "CamelCase" enum name in to a "Camel case" name, adding |
88 // spaces and making all characters besides the first lower case. | |
4 | 89 e.Value = e.Value.ToString().Substring(0, 1) + Regex.Replace(e.Value.ToString(), "(\\B[A-Z])", " $1").ToLower().Substring(1); |
90 } | |
91 | |
16 | 92 /// <summary>Saves the user settings and closes the form.</summary> |
4 | 93 private void OkButton_Click(object sender, EventArgs e) |
94 { | |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
8
diff
changeset
|
95 Settings.Default.HideToNotificationArea = KeepRunningCheckBox.Checked; |
6
c1dffaac66fa
- Don't show multiple password dialogs for the same key if the first one was cancelled.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
96 Settings.Default.KeepLogDays = (int)KeepLogDaysInput.Value; |
4 | 97 Settings.Default.ErrorAction = (FailAction)ErrorComboBox.SelectedItem; |
98 Settings.Default.WarningAction = (FailAction)WarningComboBox.SelectedItem; | |
99 Settings.Default.InformationAction = (FailAction)InformationComboBox.SelectedItem; | |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
100 Settings.Default.ErrorSound = getSelectedSound(ErrorSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
101 Settings.Default.WarningSound = getSelectedSound(WarningSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
102 Settings.Default.InformationSound = getSelectedSound(InformationSoundComboBox); |
4 | 103 Settings.Default.Save(); |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
104 SetAutorun(AutorunCheckBox.Checked); |
4 | 105 Close(); |
106 } | |
107 | |
16 | 108 /// <summary>Closes the form without saving settings.</summary> |
4 | 109 private void CancelSettingsButton_Click(object sender, EventArgs e) |
110 { | |
111 Close(); | |
112 } | |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
113 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
114 /// <summary>Shows a file browser when "Custom cound..." is selected.</summary> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
115 private void SoundComboBox_SelectedIndexChanged(object sender, EventArgs e) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
116 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
117 ComboBox comboBox = (ComboBox)sender; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
118 // Show the dialog if the last item is selected. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
119 if (comboBox.SelectedIndex == comboBox.Items.Count - 1) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
120 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
121 OpenFileDialog dialog = new OpenFileDialog() |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
122 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
123 Title = "Select audio file", |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
124 Filter = "Audio files (*.wav;*.mp3;*.wma,*.aif,*.aiff,*.asf,*.aac,*.m4a)|*.wav;*.mp3;*.wma,*.aif,*.aiff,*.asf,*.aac,*.m4a|All files (*.*)|*.*" |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
125 }; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
126 if (dialog.ShowDialog() == DialogResult.OK) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
127 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
128 // Remove the previous custom sound, if any. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
129 if (comboBox.Items.Count > soundOptions.Length) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
130 comboBox.Items.RemoveAt(customSoundIndex); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
131 // Add the custom sound and mark it as selected. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
132 comboBox.Items.Insert(customSoundIndex, dialog.FileName); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
133 comboBox.SelectedIndex = customSoundIndex; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
134 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
135 else |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
136 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
137 // Restore the existing setting if the dialog was cancelled. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
138 comboBox.SelectedIndex = getSoundSettingIndex(comboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
139 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
140 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
141 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
142 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
143 /// <summary>Shows only the filename of the custom sound.</summary> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
144 private void SoundComboBox_Format(object sender, ListControlConvertEventArgs e) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
145 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
146 if (!soundOptions.Contains(e.Value)) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
147 e.Value = Path.GetFileName(e.Value.ToString()); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
148 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
149 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
150 /// <summary>Returns the selected sound for a combo box as stored in program settings.</summary> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
151 /// <param name="comboBox">The combo box to read from.</param> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
152 /// <returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
153 /// The index ("0" or "1") of the selected option, or the |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
154 /// path to the custom sound if a custom sound is selected. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
155 /// </returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
156 private string getSelectedSound(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
157 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
158 return comboBox.SelectedIndex == customSoundIndex ? comboBox.SelectedItem.ToString() : comboBox.SelectedIndex.ToString(); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
159 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
160 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
161 /// <summary>Reads the sound setting for a combobox from program settings.</summary> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
162 /// <param name="comboBox">The combo box to read data for.</param> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
163 /// <returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
164 /// The index ("0" or "1") of the selected option, or the |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
165 /// path to the custom sound if a custom sound is selected. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
166 /// </returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
167 private string getSoundSetting(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
168 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
169 string setting = string.Empty; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
170 if (comboBox == ErrorSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
171 setting = Settings.Default.ErrorSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
172 if (comboBox == WarningSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
173 setting = Settings.Default.WarningSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
174 if (comboBox == InformationSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
175 setting = Settings.Default.InformationSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
176 return setting; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
177 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
178 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
179 /// <summary>Gets the index of the combo box item that corresponds to its program sound setting.</summary> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
180 /// <param name="comboBox">The combo box to read data for.</param> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
181 /// <returns>The index of the combo box item that corresponds to its program sound setting.</returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
182 private int getSoundSettingIndex(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
183 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
184 // If the string is not numeric, it contains the path to the custom sound. |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
185 return int.TryParse(getSoundSetting(comboBox), out int index) ? index : customSoundIndex; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
186 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
187 |
4 | 188 } |
189 } |