Mercurial > servermonitor
annotate ServerMonitor/Forms/SettingsForm.cs @ 29:f6235dc0a8ec
Add ability to play a sound on check failure.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Fri, 14 Jun 2019 21:01:55 -0400 |
parents | 7626b099aefd |
children | 7645122aa7a9 |
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); |
4 | 51 } |
52 | |
16 | 53 /// <summary>Gets whether an autorun registry key for this program exists.</summary> |
54 /// <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
|
55 private bool GetAutorun() |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
56 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
57 RegistryKey key = Registry.CurrentUser.OpenSubKey(autorunKey, false); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
58 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
|
59 return value.StartsWith(Application.ExecutablePath); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
60 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
61 |
16 | 62 /// <summary>Sets whether this program should automatically start with Windows.</summary> |
63 /// <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
|
64 private void SetAutorun(bool autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
65 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
66 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
|
67 if (autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
68 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
|
69 else |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
70 key.DeleteValue(autorunName, false); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
71 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
72 |
16 | 73 /// <summary>Shows a human readable description of possible check failure actions in the combo box.</summary> |
4 | 74 private void FailActionComboBox_Format(object sender, ListControlConvertEventArgs e) |
75 { | |
16 | 76 // Transform the "CamelCase" enum name in to a "Camel case" name, adding |
77 // spaces and making all characters besides the first lower case. | |
4 | 78 e.Value = e.Value.ToString().Substring(0, 1) + Regex.Replace(e.Value.ToString(), "(\\B[A-Z])", " $1").ToLower().Substring(1); |
79 } | |
80 | |
16 | 81 /// <summary>Saves the user settings and closes the form.</summary> |
4 | 82 private void OkButton_Click(object sender, EventArgs e) |
83 { | |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
8
diff
changeset
|
84 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
|
85 Settings.Default.KeepLogDays = (int)KeepLogDaysInput.Value; |
4 | 86 Settings.Default.ErrorAction = (FailAction)ErrorComboBox.SelectedItem; |
87 Settings.Default.WarningAction = (FailAction)WarningComboBox.SelectedItem; | |
88 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
|
89 Settings.Default.ErrorSound = getSelectedSound(ErrorSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
90 Settings.Default.WarningSound = getSelectedSound(WarningSoundComboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
91 Settings.Default.InformationSound = getSelectedSound(InformationSoundComboBox); |
4 | 92 Settings.Default.Save(); |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
93 SetAutorun(AutorunCheckBox.Checked); |
4 | 94 Close(); |
95 } | |
96 | |
16 | 97 /// <summary>Closes the form without saving settings.</summary> |
4 | 98 private void CancelSettingsButton_Click(object sender, EventArgs e) |
99 { | |
100 Close(); | |
101 } | |
29
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
102 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
103 /// <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
|
104 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
|
105 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
106 ComboBox comboBox = (ComboBox)sender; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
107 // 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
|
108 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
|
109 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
110 OpenFileDialog dialog = new OpenFileDialog() |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
111 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
112 Title = "Select audio file", |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
113 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
|
114 }; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
115 if (dialog.ShowDialog() == DialogResult.OK) |
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 // 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
|
118 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
|
119 comboBox.Items.RemoveAt(customSoundIndex); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
120 // 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
|
121 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
|
122 comboBox.SelectedIndex = customSoundIndex; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
123 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
124 else |
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 // 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
|
127 comboBox.SelectedIndex = getSoundSettingIndex(comboBox); |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
128 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
129 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
130 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
131 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
132 /// <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
|
133 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
|
134 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
135 ComboBox comboBox = (ComboBox)sender; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
136 if (!soundOptions.Contains(e.Value)) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
137 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
|
138 } |
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 /// <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
|
141 /// <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
|
142 /// <returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
143 /// 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
|
144 /// 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
|
145 /// </returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
146 private string getSelectedSound(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
147 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
148 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
|
149 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
150 |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
151 /// <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
|
152 /// <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
|
153 /// <returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
154 /// 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
|
155 /// 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
|
156 /// </returns> |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
157 private string getSoundSetting(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
158 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
159 string setting = string.Empty; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
160 if (comboBox == ErrorSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
161 setting = Settings.Default.ErrorSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
162 if (comboBox == WarningSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
163 setting = Settings.Default.WarningSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
164 if (comboBox == InformationSoundComboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
165 setting = Settings.Default.InformationSound; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
166 return setting; |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
167 } |
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 /// <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
|
170 /// <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
|
171 /// <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
|
172 private int getSoundSettingIndex(ComboBox comboBox) |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
173 { |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
174 // 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
|
175 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
|
176 } |
f6235dc0a8ec
Add ability to play a sound on check failure.
Brad Greco <brad@bgreco.net>
parents:
16
diff
changeset
|
177 |
4 | 178 } |
179 } |