-
Notifications
You must be signed in to change notification settings - Fork 2
/
SettingsForm.cs
151 lines (133 loc) · 5.4 KB
/
SettingsForm.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
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
using DmLib.Autorun;
using OnTopper.Properties;
using System.Globalization;
using System.Threading;
using System.Windows.Forms;
using OnTopper.Util;
using static DmLib.Autorun.Autorun;
namespace OnTopper
{
public partial class SettingsForm : Form
{
public bool HideNonInteractive = true;
public bool TimerEnabled;
public bool ShowWindowTitles;
public int Interval = 3000;
private const string AppName = "OnTopper.exe";
private readonly string deleteFromAutorun = LocalizedMessageProvider.GetMessage("DELETE_AUTORUN");
private readonly string addToAutorun = LocalizedMessageProvider.GetMessage("ADD_AUTORUN");
private readonly Updater updater = new Updater();
private readonly Settings settings = Settings.Default;
public SettingsForm()
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(settings.LanguageAbbreviation.ToLower());
InitializeComponent();
ApplyUiFromSettings();
if (InAutorun())
{
checkBoxAutoHide.Visible = true;
buttonAutorun.Text = deleteFromAutorun;
}
if (settings.AutoHide)
{
checkBoxAutoHide.Checked = true;
}
}
private void ApplyUiFromSettings()
{
checkBoxAutoUpdate.Checked = settings.AutoUpdate;
checkBoxAutoHide.Checked = settings.AutoHide;
numericUpDownInterval.Value = settings.UpdateInterval;
checkBoxShowWindowTitles.Checked = settings.WindowTitles;
checkBoxHideUninteractive.Checked = settings.HideNonInteractive;
comboBoxLanguage.SelectedItem = settings.Language;
}
public void ShowDialogWithTopMostState(bool onTop)
{
TopMost = onTop;
ShowDialog();
}
private static bool InAutorun()
{
return Autorun.Contains(AppName, TARGET.USER);
}
private void ButtonApply_Click(object sender, System.EventArgs e)
{
HideNonInteractive = checkBoxHideUninteractive.Checked;
TimerEnabled = checkBoxAutoUpdate.Checked;
ShowWindowTitles = checkBoxShowWindowTitles.Checked;
Interval = (int)numericUpDownInterval.Value;
if (comboBoxLanguage.SelectedItem.ToString() != settings.Language)
{
Application.Restart();
}
Close();
}
private void ButtonDefault_Click(object sender, System.EventArgs e)
{
checkBoxHideUninteractive.Checked = true;
}
private void ButtonAutorunOff_Click(object sender, System.EventArgs e)
{
if (InAutorun())
{
Remove(AppName, TARGET.USER);
MessageBox.Show(LocalizedMessageProvider.GetMessage("DELETED_AUTORUN"),
LocalizedMessageProvider.GetMessage("AUTORUN"), MessageBoxButtons.OK, MessageBoxIcon.Information);
checkBoxAutoHide.Visible = false;
settings.AutoStart = false;
buttonAutorun.Text = deleteFromAutorun;
}
else
{
Add(AppName, Application.ExecutablePath, TARGET.USER);
MessageBox.Show(LocalizedMessageProvider.GetMessage("ADDED_AUTORUN"),
LocalizedMessageProvider.GetMessage("AUTORUN"), MessageBoxButtons.OK, MessageBoxIcon.Information);
checkBoxAutoHide.Visible = true;
settings.AutoStart = true;
buttonAutorun.Text = addToAutorun;
}
settings.Save();
}
private void CheckBoxAutoUpdate_CheckedChanged(object sender, System.EventArgs e)
{
if (checkBoxAutoUpdate.Checked)
{
labelInterval.Visible = true;
numericUpDownInterval.Visible = true;
}
else
{
labelInterval.Visible = false;
numericUpDownInterval.Visible = false;
}
}
private void ButtonCheckUpdates_Click(object sender, System.EventArgs e)
{
if (updater.UpdateAvailable())
{
var result = MessageBox.Show(LocalizedMessageProvider.GetMessage("NEW_VERSION_AVAILABLE_QUESTION"),
LocalizedMessageProvider.GetMessage("UPDATE"), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Updater.InstallUpdate();
}
}
else
{
MessageBox.Show(LocalizedMessageProvider.GetMessage("NO_UPDATE"),
LocalizedMessageProvider.GetMessage("UPDATE"), MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
settings.AutoUpdate = checkBoxAutoUpdate.Checked;
settings.AutoHide = checkBoxAutoHide.Checked;
settings.UpdateInterval = (int)numericUpDownInterval.Value;
settings.WindowTitles = checkBoxShowWindowTitles.Checked;
settings.HideNonInteractive = checkBoxHideUninteractive.Checked;
settings.Language = comboBoxLanguage.SelectedItem.ToString();
settings.Save();
}
}
}