Skip to content

Commit

Permalink
* Added code behind auto startup
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDead committed Feb 18, 2018
1 parent 36f600a commit d016862
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions MemPlus/Windows/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private void LoadProperties()
try
{
//General
ChbAutoStart.IsChecked = AutoStartUp();
ChbAutoUpdate.IsChecked = Properties.Settings.Default.AutoUpdate;
ChbStartMinimized.IsChecked = Properties.Settings.Default.HideOnStart;
if (Properties.Settings.Default.Topmost)
Expand Down Expand Up @@ -119,6 +120,15 @@ private void LoadProperties()
_logController.AddLog(new ApplicationLog("Done loading SettingsWindow properties"));
}

/// <summary>
/// Check if the program starts automatically.
/// </summary>
/// <returns>A boolean to represent whether the program starts automatically or not.</returns>
private static bool AutoStartUp()
{
return Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "MemPlus", "").ToString() == AppDomain.CurrentDomain.BaseDirectory;
}

/// <summary>
/// Save all properties
/// </summary>
Expand All @@ -128,6 +138,17 @@ private void SaveProperties()
try
{
//General
if (ChbAutoStart.IsChecked != null && ChbAutoStart.IsChecked.Value)
{
Registry.SetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "MemPlus", AppDomain.CurrentDomain.BaseDirectory);
} else if (ChbAutoStart.IsChecked != null && !ChbAutoStart.IsChecked.Value)
{
if (Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "MemPlus", "").ToString() == "") return;
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
{
key?.DeleteValue("MemPlus");
}
}
if (ChbAutoUpdate.IsChecked != null) Properties.Settings.Default.AutoUpdate = ChbAutoUpdate.IsChecked.Value;
if (ChbTopmost.IsChecked != null) Properties.Settings.Default.Topmost = ChbTopmost.IsChecked.Value;
if (ChbStartMinimized.IsChecked != null) Properties.Settings.Default.HideOnStart = ChbStartMinimized.IsChecked.Value;
Expand Down

0 comments on commit d016862

Please sign in to comment.