Mercurial > servermonitor
annotate ServerMonitor/Forms/SettingsForm.cs @ 12:d92176c5398a
Better display of schedule name.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 15 Apr 2019 19:24:55 -0400 |
parents | 75ca86e0862c |
children | 7626b099aefd |
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; |
4 using System.Collections.Generic; | |
5 using System.ComponentModel; | |
6 using System.Data; | |
7 using System.Drawing; | |
8 using System.Linq; | |
9 using System.Text; | |
10 using System.Text.RegularExpressions; | |
11 using System.Threading.Tasks; | |
12 using System.Windows.Forms; | |
13 | |
14 namespace ServerMonitorApp | |
15 { | |
16 public partial class SettingsForm : Form | |
17 { | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
18 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
|
19 private readonly string autorunName = "ServerMonitor"; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
20 |
4 | 21 public SettingsForm() |
22 { | |
23 InitializeComponent(); | |
24 } | |
25 | |
26 private void SettingsForm_Load(object sender, EventArgs e) | |
27 { | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
28 Icon = Resources.icon; |
4 | 29 foreach (ComboBox comboBox in new object[] { ErrorComboBox, WarningComboBox, InformationComboBox }) |
30 { | |
31 comboBox.DataSource = Enum.GetValues(typeof(FailAction)); | |
32 comboBox.Format += FailActionComboBox_Format; | |
33 } | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
34 AutorunCheckBox.Checked = GetAutorun(); |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
8
diff
changeset
|
35 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
|
36 KeepLogDaysInput.Value = Settings.Default.KeepLogDays; |
4 | 37 ErrorComboBox.SelectedItem = Settings.Default.ErrorAction; |
38 WarningComboBox.SelectedItem = Settings.Default.WarningAction; | |
39 InformationComboBox.SelectedItem = Settings.Default.InformationAction; | |
40 } | |
41 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
42 private bool GetAutorun() |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
43 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
44 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
|
45 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
|
46 return value.StartsWith(Application.ExecutablePath); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
47 } |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
48 |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
49 private void SetAutorun(bool autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
50 { |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
51 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
|
52 if (autorun) |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
53 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
|
54 else |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
55 key.DeleteValue(autorunName, false); |
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 |
4 | 58 private void FailActionComboBox_Format(object sender, ListControlConvertEventArgs e) |
59 { | |
60 e.Value = e.Value.ToString().Substring(0, 1) + Regex.Replace(e.Value.ToString(), "(\\B[A-Z])", " $1").ToLower().Substring(1); | |
61 } | |
62 | |
63 private void OkButton_Click(object sender, EventArgs e) | |
64 { | |
11
75ca86e0862c
Add setting to hide to notification area.
Brad Greco <brad@bgreco.net>
parents:
8
diff
changeset
|
65 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
|
66 Settings.Default.KeepLogDays = (int)KeepLogDaysInput.Value; |
4 | 67 Settings.Default.ErrorAction = (FailAction)ErrorComboBox.SelectedItem; |
68 Settings.Default.WarningAction = (FailAction)WarningComboBox.SelectedItem; | |
69 Settings.Default.InformationAction = (FailAction)InformationComboBox.SelectedItem; | |
70 Settings.Default.Save(); | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
6
diff
changeset
|
71 SetAutorun(AutorunCheckBox.Checked); |
4 | 72 Close(); |
73 } | |
74 | |
75 private void CancelSettingsButton_Click(object sender, EventArgs e) | |
76 { | |
77 Close(); | |
78 } | |
79 } | |
80 } |