@@ -17,6 +17,7 @@ public class SettingsJson
1717 public int FontSize { get ; set ; }
1818 public Size WindowSize { get ; set ; }
1919 public Point ? WindowLocation { get ; set ; }
20+ public FormWindowState WindowState { get ; set ; }
2021 }
2122
2223 internal static class Options
@@ -30,9 +31,6 @@ internal static class Options
3031
3132 internal static SettingsJson CurrentOptions = new SettingsJson ( ) ;
3233
33- // use this to determine if changes have been made
34- static SettingsJson _flag = new SettingsJson ( ) ;
35-
3634 internal static void ApplyTheme ( Form f )
3735 {
3836 switch ( CurrentOptions . Color )
@@ -97,19 +95,16 @@ internal static void SaveSettings()
9795 {
9896 if ( File . Exists ( _settingsFile ) )
9997 {
100- if ( ( _flag . HidePasswords != CurrentOptions . HidePasswords ) || ( _flag . WindowLocation != CurrentOptions . WindowLocation ) || ( _flag . WindowSize != CurrentOptions . WindowSize ) || ( _flag . FontSize != CurrentOptions . FontSize ) || ( _flag . Color != CurrentOptions . Color ) || ( _flag . Authorize != CurrentOptions . Authorize ) || ( _flag . AutoLock != CurrentOptions . AutoLock ) || ( _flag . AutoStart != CurrentOptions . AutoStart ) || ( _flag . Minutes != CurrentOptions . Minutes ) )
101- {
102- File . Delete ( _settingsFile ) ;
98+ File . WriteAllText ( _settingsFile , string . Empty ) ;
10399
104- using ( FileStream fs = File . Open ( _settingsFile , FileMode . OpenOrCreate ) )
105- using ( StreamWriter sw = new StreamWriter ( fs ) )
106- using ( JsonWriter jw = new JsonTextWriter ( sw ) )
107- {
108- jw . Formatting = Formatting . Indented ;
100+ using ( FileStream fs = File . Open ( _settingsFile , FileMode . OpenOrCreate ) )
101+ using ( StreamWriter sw = new StreamWriter ( fs ) )
102+ using ( JsonWriter jw = new JsonTextWriter ( sw ) )
103+ {
104+ jw . Formatting = Formatting . Indented ;
109105
110- JsonSerializer serializer = new JsonSerializer ( ) ;
111- serializer . Serialize ( jw , CurrentOptions ) ;
112- }
106+ JsonSerializer serializer = new JsonSerializer ( ) ;
107+ serializer . Serialize ( jw , CurrentOptions ) ;
113108 }
114109 }
115110 }
@@ -127,6 +122,7 @@ internal static void LoadSettings()
127122 CurrentOptions . WindowLocation = null ;
128123 CurrentOptions . WindowSize = new Size ( 907 , 681 ) ;
129124 CurrentOptions . FontSize = 1 ;
125+ CurrentOptions . WindowState = FormWindowState . Normal ;
130126
131127 using ( FileStream fs = File . Open ( _settingsFile , FileMode . CreateNew ) )
132128 using ( StreamWriter sw = new StreamWriter ( fs ) )
@@ -142,16 +138,11 @@ internal static void LoadSettings()
142138 {
143139 CurrentOptions = JsonConvert . DeserializeObject < SettingsJson > ( File . ReadAllText ( _settingsFile ) ) ;
144140
145- // initialize flag
146- _flag . Color = CurrentOptions . Color ;
147- _flag . Authorize = CurrentOptions . Authorize ;
148- _flag . AutoLock = CurrentOptions . AutoLock ;
149- _flag . AutoStart = CurrentOptions . AutoStart ;
150- _flag . Minutes = CurrentOptions . Minutes ;
151- _flag . WindowLocation = CurrentOptions . WindowLocation ;
152- _flag . WindowSize = CurrentOptions . WindowSize ;
153- _flag . FontSize = CurrentOptions . FontSize ;
154- _flag . HidePasswords = CurrentOptions . HidePasswords ;
141+ if ( CurrentOptions . WindowSize . IsEmpty )
142+ {
143+ CurrentOptions . WindowSize = new Size ( 907 , 681 ) ;
144+ SaveSettings ( ) ;
145+ }
155146 }
156147 }
157148 }
0 commit comments