Skip to content

Commit 33a604e

Browse files
authored
Merge pull request #3 from taylorflatt/dev
Release 2.1.0.0
2 parents 9ee9bb5 + adc045c commit 33a604e

File tree

9 files changed

+269
-127
lines changed

9 files changed

+269
-127
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0.0
1+
2.1.0.0

WindowsShutdownTimer.exe

3 KB
Binary file not shown.

WindowsShutdownTimer/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<setting name="ShutdownTimer" serializeAs="String">
2323
<value>0002-01-01</value>
2424
</setting>
25+
<setting name="ShowShutdownNotification" serializeAs="String">
26+
<value>False</value>
27+
</setting>
2528
</WindowsShutdownTimer.Properties.Settings>
2629
</userSettings>
2730
</configuration>

WindowsShutdownTimer/Options.Designer.cs

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WindowsShutdownTimer/Options.cs

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
using System;
1+
using Microsoft.Win32.TaskScheduler;
2+
using System;
23
using System.Windows.Forms;
34

45
namespace WindowsShutdownTimer
56
{
67
public partial class Options : Form
78
{
9+
#region Main
10+
811
/// <summary>
912
/// The parent form object.
1013
/// </summary>
@@ -26,45 +29,97 @@ public Options(TimerForm parent)
2629

2730
last_shutdown_label_desc.Text = "Last Attempted Shutdown: ";
2831

29-
if(timerWindow.TimerExists(TimerForm.DEFAULT_TASK_NAME))
32+
if (timerWindow.TimerExists(TimerForm.DEFAULT_TASK_NAME))
3033
{
31-
if(timerWindow.TimerRunning(TimerForm.DEFAULT_TASK_NAME, DateTime.Now))
34+
if (timerWindow.TimerRunning(TimerForm.DEFAULT_TASK_NAME, DateTime.Now))
3235
last_shutdown_label.Text = "Pending " + "(" + Convert.ToString(Properties.Settings.Default.ShutdownTimer) + ")";
3336
else
3437
{
35-
// If the timer was never run, display the time accordingly.
36-
if (timerWindow.GetLastRunTime(TimerForm.DEFAULT_TASK_NAME) == timerWindow.SetDefaultDateTime(new DateTime()))
37-
last_shutdown_label.Text = "N/A";
38-
else
38+
try
3939
{
40-
// Windows 7 doesn't have the last run time so I need to do something else.
41-
if (timerWindow.GetLastRunTime(TimerForm.DEFAULT_TASK_NAME) == default(DateTime))
42-
last_shutdown_label.Text = Convert.ToString(Properties.Settings.Default.ShutdownTimer);
40+
// If the timer was never run, display the time accordingly.
41+
if (GetLastRunTime(TimerForm.DEFAULT_TASK_NAME) == timerWindow.SetDefaultDateTime(new DateTime()))
42+
last_shutdown_label.Text = "N/A";
4343
else
44-
last_shutdown_label.Text = Convert.ToString(timerWindow.GetLastRunTime(TimerForm.DEFAULT_TASK_NAME));
44+
{
45+
// Windows 7 doesn't have the last run time so I need to do something else.
46+
if (GetLastRunTime(TimerForm.DEFAULT_TASK_NAME) == default(DateTime))
47+
last_shutdown_label.Text = Convert.ToString(Properties.Settings.Default.ShutdownTimer);
48+
else
49+
last_shutdown_label.Text = Convert.ToString(GetLastRunTime(TimerForm.DEFAULT_TASK_NAME));
50+
}
51+
}
52+
catch(NoTimerExists)
53+
{
54+
last_shutdown_label.Text = "N/A";
4555
}
4656
}
4757
}
4858
else
4959
last_shutdown_label.Text = "N/A";
60+
61+
timerWindow.BringFormForward();
62+
}
63+
64+
#endregion
65+
66+
#region Helper Functions
67+
68+
/// <summary>
69+
/// Gets the last time a scheduled task was run (successfully or not).
70+
/// </summary>
71+
/// <param name="taskName">The name of the task that will be searched.</param>
72+
/// <returns>Returns the DateTime of when the scheduled even last fired.</returns>
73+
public DateTime GetLastRunTime(string taskName)
74+
{
75+
if(Properties.Settings.Default.ShowShutdownNotification)
76+
return Properties.Settings.Default.ShutdownTimer;
77+
78+
else
79+
{
80+
using (TaskService ts = new TaskService())
81+
{
82+
// If the task exists, return the last run time.
83+
if (timerWindow.TimerExists(taskName))
84+
{
85+
Task task = ts.GetTask(taskName);
86+
return task.LastRunTime;
87+
}
88+
89+
else
90+
throw new NoTimerExists("The timer doesn't exist in the task scheduler.");
91+
}
92+
}
5093
}
5194

95+
#endregion
96+
97+
#region Event Handlers
98+
5299
/// <summary>
53100
/// When the form loads, set the check boxes according to the user's prior settings (if any).
54101
/// </summary>
55102
/// <param name="sender"></param>
56103
/// <param name="e"></param>
57104
private void Options_Load(object sender, EventArgs e)
58105
{
106+
// First check box
59107
if (Properties.Settings.Default.MinimizeToSysTray)
60108
minimize_to_sys_tray.Checked = true;
61109
else
62110
minimize_to_sys_tray.Checked = false;
63111

112+
// Second check box
64113
if (Properties.Settings.Default.LClickOpenSysTray)
65114
left_click_open_sys_tray.Checked = true;
66115
else
67116
left_click_open_sys_tray.Checked = false;
117+
118+
// Third check box
119+
if (Properties.Settings.Default.ShowShutdownNotification)
120+
show_shutdown_notification.Checked = true;
121+
else
122+
show_shutdown_notification.Checked = false;
68123
}
69124

70125
/// <summary>
@@ -73,26 +128,44 @@ private void Options_Load(object sender, EventArgs e)
73128
/// <param name="sender"></param>
74129
/// <param name="e"></param>
75130
public void save_options_button_Click(object sender, EventArgs e)
76-
{
131+
{
77132
// Minimize program to system tray rather than to the taskbar.
78133
if (minimize_to_sys_tray.Checked)
79134
Properties.Settings.Default.MinimizeToSysTray = true;
80135
else
81136
Properties.Settings.Default.MinimizeToSysTray = false;
82-
137+
83138
// Single left click to re-show program when clicking icon in system tray.
84139
if (left_click_open_sys_tray.Checked)
85140
Properties.Settings.Default.LClickOpenSysTray = true;
86141
else
87142
Properties.Settings.Default.LClickOpenSysTray = false;
88143

144+
// Display the shutdown notification from windows alerting the user of an impending shutdown.
145+
if (show_shutdown_notification.Checked && !Properties.Settings.Default.ShowShutdownNotification)
146+
{
147+
DialogResult confirm = MessageBox.Show("Are you sure you want to show the shutdown notifications? This may result in the " +
148+
"timer being inaccurate and you not being shown the correct time remaining. In addition, it also has to create/remove a " +
149+
"shutdown timer each time you load the program in order to check if one exists. So that might result in a message indicating " +
150+
"that a shutdown was stopped but it was only a check. I honestly don't recommend enabling this option. Proceed with caution!"
151+
, "WARNING - Are you sure?" , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
152+
153+
if (confirm == DialogResult.Yes)
154+
Properties.Settings.Default.ShowShutdownNotification = true;
155+
else
156+
return;
157+
}
158+
else
159+
Properties.Settings.Default.ShowShutdownNotification = false;
160+
89161
Properties.Settings.Default.Save();
90-
//timerWindow.ApplyUserSettings();
91162

92163
// Close the options form and redisplay the parent.
93164
ActiveForm.Close();
94165
timerWindow.Enabled = true;
95166
timerWindow.Visible = true;
167+
168+
timerWindow.BringFormForward();
96169
}
97170

98171
/// <summary>
@@ -103,6 +176,7 @@ public void save_options_button_Click(object sender, EventArgs e)
103176
private void Options_FormClosing(object sender, FormClosingEventArgs e)
104177
{
105178
timerWindow.Enabled = true;
179+
timerWindow.BringFormForward();
106180
}
107181

108182
/// <summary>
@@ -123,9 +197,9 @@ public void check_update_button_Click(object sender, EventArgs e)
123197
Array curV = currentVersion.Split('.');
124198

125199
// Note: The user's version number should never be higher than the release version. So I don't even consider that case.
126-
for(int i = 0; i < 4; i++)
200+
for (int i = 0; i < 4; i++)
127201
{
128-
if(Convert.ToInt32(webV.GetValue(i)) > Convert.ToInt32(curV.GetValue(i)))
202+
if (Convert.ToInt32(webV.GetValue(i)) > Convert.ToInt32(curV.GetValue(i)))
129203
{
130204
DialogResult result = MessageBox.Show("The current version is: " + currentVersion + " and the newest version is " + webVersion + ". Would you " +
131205
"like to download the newest version?", "New Version Found!", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
@@ -168,5 +242,7 @@ public void check_update_button_Click(object sender, EventArgs e)
168242

169243
MessageBox.Show("The current version is: " + currentVersion + " and it is up to date!", "No New Update!", MessageBoxButtons.OK, MessageBoxIcon.Information);
170244
}
245+
246+
#endregion
171247
}
172248
}

WindowsShutdownTimer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.0.0")]
36-
[assembly: AssemblyFileVersion("2.0.0.0")]
35+
[assembly: AssemblyVersion("2.1.0.0")]
36+
[assembly: AssemblyFileVersion("2.1.0.0")]

WindowsShutdownTimer/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WindowsShutdownTimer/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<Setting Name="ShutdownTimer" Type="System.DateTime" Scope="User">
1515
<Value Profile="(Default)">0002-01-01</Value>
1616
</Setting>
17+
<Setting Name="ShowShutdownNotification" Type="System.Boolean" Scope="User">
18+
<Value Profile="(Default)">False</Value>
19+
</Setting>
1720
</Settings>
1821
</SettingsFile>

0 commit comments

Comments
 (0)