@@ -67,6 +67,7 @@ private void LoadProperties()
67
67
try
68
68
{
69
69
//General
70
+ ChbAutoStart . IsChecked = AutoStartUp ( ) ;
70
71
ChbAutoUpdate . IsChecked = Properties . Settings . Default . AutoUpdate ;
71
72
ChbStartMinimized . IsChecked = Properties . Settings . Default . HideOnStart ;
72
73
if ( Properties . Settings . Default . Topmost )
@@ -119,6 +120,15 @@ private void LoadProperties()
119
120
_logController . AddLog ( new ApplicationLog ( "Done loading SettingsWindow properties" ) ) ;
120
121
}
121
122
123
+ /// <summary>
124
+ /// Check if the program starts automatically.
125
+ /// </summary>
126
+ /// <returns>A boolean to represent whether the program starts automatically or not.</returns>
127
+ private static bool AutoStartUp ( )
128
+ {
129
+ return Registry . GetValue ( @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" , "MemPlus" , "" ) . ToString ( ) == AppDomain . CurrentDomain . BaseDirectory ;
130
+ }
131
+
122
132
/// <summary>
123
133
/// Save all properties
124
134
/// </summary>
@@ -128,6 +138,17 @@ private void SaveProperties()
128
138
try
129
139
{
130
140
//General
141
+ if ( ChbAutoStart . IsChecked != null && ChbAutoStart . IsChecked . Value )
142
+ {
143
+ Registry . SetValue ( @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" , "MemPlus" , AppDomain . CurrentDomain . BaseDirectory ) ;
144
+ } else if ( ChbAutoStart . IsChecked != null && ! ChbAutoStart . IsChecked . Value )
145
+ {
146
+ if ( Registry . GetValue ( @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" , "MemPlus" , "" ) . ToString ( ) == "" ) return ;
147
+ using ( RegistryKey key = Registry . CurrentUser . OpenSubKey ( @"Software\Microsoft\Windows\CurrentVersion\Run" , true ) )
148
+ {
149
+ key ? . DeleteValue ( "MemPlus" ) ;
150
+ }
151
+ }
131
152
if ( ChbAutoUpdate . IsChecked != null ) Properties . Settings . Default . AutoUpdate = ChbAutoUpdate . IsChecked . Value ;
132
153
if ( ChbTopmost . IsChecked != null ) Properties . Settings . Default . Topmost = ChbTopmost . IsChecked . Value ;
133
154
if ( ChbStartMinimized . IsChecked != null ) Properties . Settings . Default . HideOnStart = ChbStartMinimized . IsChecked . Value ;
0 commit comments