Skip to content

Commit

Permalink
release 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
karusb committed Jun 30, 2024
1 parent 300f00f commit 04695fc
Show file tree
Hide file tree
Showing 18 changed files with 1,546 additions and 220 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# BazWare SIT - Shutdown In Time 1.0

Do you know when your computer should shutdown but are you not there to shut it down? Shutdown your computer with a timer and save precious energy.
![Program](https://github.com/karusb/SIT-ShutdownInTime/blob/master/sitgui.png?raw=true)

## [DOWNLOAD]

- [Download V1.0 Installer for Windows](https://github.com/karusb/SIT-ShutdownInTime/releases/download/1.0/BazWareShutdownInTime-1.0-Installer.zip)
- [Download V1.0 Portable for Windows](https://github.com/karusb/SIT-ShutdownInTime/releases/download/1.0/BazWareShutdownInTime-1.0-Portable.zip)
- Portable Requires Microsoft .NET Framework 4.8

## [Timed Shutdown]

To initiate a timed shutdown, select the amount of time you would like to wait in hours and/or minutes, then press the Start button.

![Program](https://github.com/karusb/SIT-ShutdownInTime/blob/master/sitgui2.png?raw=true)

- Windows likely will inform with an additional popup on the date and time of the shutdown.

## [Force Shutdown Now]

Immediately shutdown your computer by forcing all applications to close. Popup will appear for confirmation.
4 changes: 2 additions & 2 deletions ShutdownInTime.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShutdownInTime", "ShutdownInTime\ShutdownInTime.csproj", "{9713F6E8-A74F-4125-B202-54779148A083}"
EndProject
Expand Down
21 changes: 18 additions & 3 deletions ShutdownInTime/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SIT.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
<userSettings>
<SIT.Properties.Settings>
<setting name="userHours" serializeAs="String">
<value>0</value>
</setting>
<setting name="userMinutes" serializeAs="String">
<value>1</value>
</setting>
</SIT.Properties.Settings>
</userSettings>
</configuration>
295 changes: 211 additions & 84 deletions ShutdownInTime/Form1.Designer.cs

Large diffs are not rendered by default.

145 changes: 86 additions & 59 deletions ShutdownInTime/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,109 +13,114 @@ namespace ShutdownInTime
{
public partial class Form1 : Form
{
int selection = 0;
int seconds = 0;
decimal seconds = 0;
decimal requestedSeconds = 0;
Timer timer;
public Form1()
{
InitializeComponent();
hourNumeric.Value = SIT.Properties.Settings.Default.userHours;
minuteNumeric.Value = SIT.Properties.Settings.Default.userMinutes;
}

private void Form1_Load(object sender, EventArgs e)
{

timer = new Timer();
timer.Interval = (1000);
timer.Tick += new EventHandler(timer_Tick);
}

private void DKradio_CheckedChanged(object sender, EventArgs e)
string ShutdownInitiateCmd()
{
selection = 1;
return "shutdown /s /t " + seconds.ToString();
}

private void SaatRadio_CheckedChanged(object sender, EventArgs e)
string ShutdownForceNowCmd()
{
selection = 2;
return "shutdown /f /p";
}

private void SaatDKradio_CheckedChanged(object sender, EventArgs e)
string ShutdownAbortCmd()
{
selection = 3;
return "shutdown /a";
}

private void StartButton_Click(object sender, EventArgs e)
private bool ParseInput()
{
var hours = hourNumeric.Value;
var mins = minuteNumeric.Value;

timer = new Timer();
timer.Interval = (1000);

seconds = (hours * 60 * 60) + (mins * 60);
requestedSeconds = seconds;

string cmdtext = InputBox.Text;
string[] bothtext = new string[2];
int mins = 0;
int hours = 0;

if(cmdtext.Contains(":") && selection == 3)
{
bothtext = cmdtext.Split(':');
hours= int.Parse(bothtext[0]);
mins = int.Parse(bothtext[1]);
seconds = (hours * 60 * 60) + (mins * 60);
}
else if (selection == 2)
return seconds > 0;
}
private void ResetUi()
{
StartButton.Text = "Start";
StartButton.BackColor = Color.OliveDrab;
panel1.Visible = true;
progressBar1.Value = 0;
RemainingLabel.Text = "000";
countDownPanel.Visible = false;
}
private void SetActiveUi()
{
StartButton.Text = "Stop";
StartButton.BackColor = Color.Firebrick;
panel1.Visible = false;
RemainingLabel.Text = seconds.ToString();
countDownPanel.Visible = true;
}
private void UpdateUi()
{
RemainingLabel.Text = seconds.ToString();
progressBar1.Value = ((int)(seconds * 100m / requestedSeconds));
}
private void StartButton_Click(object sender, EventArgs e)
{
if (timer.Enabled)
{
hours = int.Parse(cmdtext);
seconds = (hours * 60 * 60);
timer.Stop();
ExecuteCommandSync(ShutdownAbortCmd());
ResetUi();
}
else if(selection == 1)
else
{
mins = int.Parse(cmdtext);
seconds = (mins * 60);
if (ParseInput())
{
ExecuteCommandSync(ShutdownInitiateCmd());
SetActiveUi();
timer.Start();
}
}
//RemainingLabel.Text = hours.ToString() + " : " + mins.ToString();
string command = "shutdown /s /t " + seconds.ToString();
ExecuteCommandSync(command);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}

private void StopButton_Click(object sender, EventArgs e)
{
timer.Stop();
ExecuteCommandSync("shutdown /a");
}
private void timer_Tick(object sender, EventArgs e)
{
seconds -= 1;
RemainingLabel.Text = seconds.ToString() ;
UpdateUi();
Application.DoEvents();
}
/// <span class="code-SummaryComment"><summary></span>
/// Executes a shell command synchronously.
/// <span class="code-SummaryComment"></summary></span>
/// <span class="code-SummaryComment"><param name="command">string command</param></span>
/// <span class="code-SummaryComment"><returns>string, as output of the command.</returns></span>

public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c " + command);

// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
ProcessStartInfo procStartInfo =
new ProcessStartInfo("cmd.exe", "/c " + command);

// redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();

Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();

// Display the command output.
Console.WriteLine(result);
}
Expand All @@ -124,5 +129,27 @@ public void ExecuteCommandSync(object command)
// Log the exception
}
}

private void forceShutdownButton_Click(object sender, EventArgs e)
{
var result = MessageBox.Show("All applications will be forced to close and computer will shutdown NOW. Force shutdown?", "Forced Shutdown", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.OK)
ExecuteCommandSync(ShutdownForceNowCmd());
}

private void minuteNumeric_ValueChanged(object sender, EventArgs e)
{
if (minuteNumeric.Value < 1)
minuteNumeric.Value = 1;

SIT.Properties.Settings.Default.userMinutes = minuteNumeric.Value;
SIT.Properties.Settings.Default.Save();
}

private void hourNumeric_ValueChanged(object sender, EventArgs e)
{
SIT.Properties.Settings.Default.userHours = hourNumeric.Value;
SIT.Properties.Settings.Default.Save();
}
}
}
Loading

0 comments on commit 04695fc

Please sign in to comment.