Skip to content

Commit

Permalink
Make Form Position Save
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague authored Mar 23, 2021
1 parent 18c274d commit 8822ea2
Showing 1 changed file with 113 additions and 18 deletions.
131 changes: 113 additions & 18 deletions Auto Restart Process/Auto Restart Process/Auto Restart.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
using Microsoft.Win32;
using Libraries;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
using Libraries;

namespace Auto_Restart_Process
{
public partial class AutoRestartForm : Form
{
public AutoRestartForm()
{
InitializeComponent();

Instance = this;

JsonConfig.LoadConfig(ref Config);

InitializeComponent();
}

public static AutoRestartForm Instance;
Expand All @@ -31,43 +29,129 @@ public class Configuration
public bool IsAutoRestarting
{
get => Instance.checkBox1.Checked;
set => Instance.checkBox1.Checked = value;
set
{
try
{
Instance.checkBox1.Checked = value;
}
catch
{

}
}
}

public decimal Interval
{
get => Instance.numericUpDown1.Value;
set => Instance.numericUpDown1.Value = value;
set
{
try
{
Instance.numericUpDown1.Value = value;
}
catch
{

}
}
}

public bool RunOnStartup
{
get => Instance.checkBox2.Checked;
set => Instance.checkBox2.Checked = value;
set
{
try
{
Instance.checkBox2.Checked = value;
}
catch
{

}
}
}

public string MaintainThis
{
get => Instance.textBox1.Text;
set => Instance.textBox1.Text = value;
set
{
try
{
Instance.textBox1.Text = value;
}
catch
{

}
}
}

public string Arguments
{
get => Instance.textBox2.Text;
set => Instance.textBox2.Text = value;
set
{
try
{
Instance.textBox2.Text = value;
}
catch
{

}
}
}

public bool CreateNoWindow
{
get => Instance.checkBox3.Checked;
set => Instance.checkBox3.Checked = value;
set
{
try
{
Instance.checkBox3.Checked = value;
}
catch
{

}
}
}

public int WindowStartState
{
get => Instance.comboBox1.SelectedIndex;
set => Instance.comboBox1.SelectedIndex = value;
set
{
try
{
Instance.comboBox1.SelectedIndex = value;
}
catch
{

}
}
}

public Point Pos
{
get => Instance.Location;
set
{
try
{
Instance.Location = value;
}
catch
{

}
}
}
}

Expand Down Expand Up @@ -103,14 +187,14 @@ public bool IsUserAdministrator()

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
if (checkBox1.Checked && !RestartWorker.IsBusy)
{
RestartWorker.RunWorkerAsync();
}

JsonConfig.SaveConfig(Config);
}

private void button1_Click(object sender, EventArgs e)
{
try
Expand All @@ -135,6 +219,8 @@ private void Form1_Load(object sender, EventArgs e)
{
IsUserAdministrator();

comboBox1.SelectedIndex = 0;

JsonConfig.LoadConfig(ref Config);
}

Expand Down Expand Up @@ -168,6 +254,8 @@ public void Log(string text)

private Process Proc;

private int RestartCount = 0;

private void RestartWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Log("RestartWorker Init!");
Expand Down Expand Up @@ -203,6 +291,8 @@ private void RestartWorker_DoWork(object sender, System.ComponentModel.DoWorkEve
Log("Process Died" + (checkBox1.Checked ? " - Restarting Soon" : "") + "!");

TimePassed.Restart();

label5.Text = "Restart Count: " + RestartCount++;
}
}
}
Expand Down Expand Up @@ -236,5 +326,10 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
JsonConfig.SaveConfig(Config);
}

private void AutoRestartForm_LocationChanged(object sender, EventArgs e)
{
JsonConfig.SaveConfig(Config);
}
}
}

0 comments on commit 8822ea2

Please sign in to comment.