11using System ;
22using System . IO ;
3+ using System . Runtime . CompilerServices ;
34
45namespace CodeRedLauncher
56{
@@ -136,11 +137,11 @@ private static bool ParseConfigFile()
136137 {
137138 if ( _storageFile . Exists ( ) )
138139 {
139- string [ ] fileLines = File . ReadAllLines ( _storageFile . GetPath ( ) ) ;
140-
141- if ( fileLines . Length > 0 )
140+ using ( StreamReader stream = new StreamReader ( _storageFile . GetPath ( ) ) )
142141 {
143- foreach ( string line in fileLines )
142+ string line ;
143+
144+ while ( ( line = stream . ReadLine ( ) ) != null )
144145 {
145146 try
146147 {
@@ -162,22 +163,18 @@ private static bool ParseConfigFile()
162163 if ( line . Contains ( "Manual" ) ) { InjectionType . SetValue ( InjectionTypes . Manual . ToString ( ) ) ; continue ; }
163164 }
164165
165- if ( line . Contains ( InjectionTimeout . Name ) ) { InjectionTimeout . SetValue ( line . Substring ( ( InjectionTimeout . Name . Length + 1 ) , ( line . Length - ( InjectionTimeout . Name . Length + 1 ) ) ) ) ; continue ; }
166+ if ( line . Contains ( InjectionTimeout . Name ) ) { InjectionTimeout . SetValue ( line . Substring ( ( InjectionTimeout . Name . Length + 1 ) , ( line . Length - ( InjectionTimeout . Name . Length + 1 ) ) ) ) ; continue ; }
166167 if ( line . Contains ( LightMode . Name ) ) { LightMode . SetValue ( line . Contains ( "True" ) ? "True" : "False" ) ; continue ; }
167168 }
168169 catch
169170 {
170171 SetDefaultSettings ( true ) ;
171- return true ;
172+ break ;
172173 }
173174 }
174-
175- return true ;
176- }
177- else
178- {
179- SetDefaultSettings ( true ) ;
180175 }
176+
177+ return true ;
181178 }
182179 else
183180 {
@@ -266,22 +263,26 @@ public async static void SaveChanges()
266263 await File . Create ( _storageFile . GetPath ( ) ) . DisposeAsync ( ) ;
267264 }
268265
269- string file = _storageFile . GetPath ( ) ;
270- File . WriteAllText ( file , string . Empty ) ; // "Truncuating" the file without needing to open it in a stream.
271- File . AppendAllText ( file , PrivacyPolicy . Name + " " + PrivacyPolicy . GetStringValue ( ) + "\n " ) ;
272- File . AppendAllText ( file , TermsOfUse . Name + " " + TermsOfUse . GetStringValue ( ) + "\n " ) ;
273- File . AppendAllText ( file , PrivacyHash . Name + " " + PrivacyHash . GetStringValue ( ) + "\n " ) ;
274- File . AppendAllText ( file , TermsHash . Name + " " + TermsHash . GetStringValue ( ) + "\n " ) ;
275- File . AppendAllText ( file , AutoCheckUpdates . Name + " " + AutoCheckUpdates . GetStringValue ( ) + "\n " ) ;
276- File . AppendAllText ( file , AutoInstallUpdates . Name + " " + AutoInstallUpdates . GetStringValue ( ) + "\n " ) ;
277- File . AppendAllText ( file , PreventInjection . Name + " " + PreventInjection . GetStringValue ( ) + "\n " ) ;
278- File . AppendAllText ( file , RunOnStartup . Name + " " + RunOnStartup . GetStringValue ( ) + "\n " ) ;
279- File . AppendAllText ( file , MinimizeOnStartup . Name + " " + MinimizeOnStartup . GetStringValue ( ) + "\n " ) ;
280- File . AppendAllText ( file , HideWhenMinimized . Name + " " + HideWhenMinimized . GetStringValue ( ) + "\n " ) ;
281- File . AppendAllText ( file , InjectAllInstances . Name + " " + InjectAllInstances . GetStringValue ( ) + "\n " ) ;
282- File . AppendAllText ( file , InjectionType . Name + " " + InjectionType . GetStringValue ( ) + "\n " ) ;
283- File . AppendAllText ( file , InjectionTimeout . Name + " " + InjectionTimeout . GetStringValue ( ) + "\n " ) ;
284- File . AppendAllText ( file , LightMode . Name + " " + LightMode . GetStringValue ( ) ) ;
266+ string fileConents = "" ;
267+ fileConents += ( PrivacyPolicy . Name + " " + PrivacyPolicy . GetStringValue ( ) + Environment . NewLine ) ;
268+ fileConents += ( TermsOfUse . Name + " " + TermsOfUse . GetStringValue ( ) + Environment . NewLine ) ;
269+ fileConents += ( PrivacyHash . Name + " " + PrivacyHash . GetStringValue ( ) + Environment . NewLine ) ;
270+ fileConents += ( TermsHash . Name + " " + TermsHash . GetStringValue ( ) + Environment . NewLine ) ;
271+ fileConents += ( AutoCheckUpdates . Name + " " + AutoCheckUpdates . GetStringValue ( ) + Environment . NewLine ) ;
272+ fileConents += ( AutoInstallUpdates . Name + " " + AutoInstallUpdates . GetStringValue ( ) + Environment . NewLine ) ;
273+ fileConents += ( PreventInjection . Name + " " + PreventInjection . GetStringValue ( ) + Environment . NewLine ) ;
274+ fileConents += ( RunOnStartup . Name + " " + RunOnStartup . GetStringValue ( ) + Environment . NewLine ) ;
275+ fileConents += ( MinimizeOnStartup . Name + " " + MinimizeOnStartup . GetStringValue ( ) + Environment . NewLine ) ;
276+ fileConents += ( HideWhenMinimized . Name + " " + HideWhenMinimized . GetStringValue ( ) + Environment . NewLine ) ;
277+ fileConents += ( InjectAllInstances . Name + " " + InjectAllInstances . GetStringValue ( ) + Environment . NewLine ) ;
278+ fileConents += ( InjectionType . Name + " " + InjectionType . GetStringValue ( ) + Environment . NewLine ) ;
279+ fileConents += ( InjectionTimeout . Name + " " + InjectionTimeout . GetStringValue ( ) + Environment . NewLine ) ;
280+ fileConents += ( LightMode . Name + " " + LightMode . GetStringValue ( ) ) ;
281+
282+ using ( StreamWriter stream = new StreamWriter ( _storageFile . GetPath ( ) , false ) )
283+ {
284+ stream . Write ( fileConents ) ;
285+ }
285286 }
286287 else
287288 {
0 commit comments