@@ -67,6 +67,7 @@ private void LoadProperties()
6767 try
6868 {
6969 //General
70+ ChbAutoStart . IsChecked = AutoStartUp ( ) ;
7071 ChbAutoUpdate . IsChecked = Properties . Settings . Default . AutoUpdate ;
7172 ChbStartMinimized . IsChecked = Properties . Settings . Default . HideOnStart ;
7273 if ( Properties . Settings . Default . Topmost )
@@ -119,6 +120,15 @@ private void LoadProperties()
119120 _logController . AddLog ( new ApplicationLog ( "Done loading SettingsWindow properties" ) ) ;
120121 }
121122
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+
122132 /// <summary>
123133 /// Save all properties
124134 /// </summary>
@@ -128,6 +138,17 @@ private void SaveProperties()
128138 try
129139 {
130140 //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+ }
131152 if ( ChbAutoUpdate . IsChecked != null ) Properties . Settings . Default . AutoUpdate = ChbAutoUpdate . IsChecked . Value ;
132153 if ( ChbTopmost . IsChecked != null ) Properties . Settings . Default . Topmost = ChbTopmost . IsChecked . Value ;
133154 if ( ChbStartMinimized . IsChecked != null ) Properties . Settings . Default . HideOnStart = ChbStartMinimized . IsChecked . Value ;
0 commit comments