@@ -96,36 +96,14 @@ by BornToBeRoot
9696 Log . Error ( "Could not load application settings!" ) ;
9797 Log . Error ( ex . Message + "-" + ex . StackTrace ) ;
9898
99- // Create backup of corrupted file
100- var destinationFile =
101- $ "{ TimestampHelper . GetTimestamp ( ) } _corrupted_" + SettingsManager . GetSettingsFileName ( ) ;
102- File . Copy ( SettingsManager . GetSettingsFilePath ( ) ,
103- Path . Combine ( SettingsManager . GetSettingsFolderLocation ( ) , destinationFile ) ) ;
104- Log . Info ( $ "A backup of the corrupted settings file has been saved under { destinationFile } ") ;
105-
106- // Initialize default application settings
107- Log . Info ( "Initialize default application settings..." ) ;
108-
109- SettingsManager . Initialize ( ) ;
110- ConfigurationManager . Current . ShowSettingsResetNoteOnStartup = true ;
99+ HandleCorruptedSettingsFile ( ) ;
111100 }
112101 catch ( JsonException ex )
113102 {
114103 Log . Error ( "Could not load application settings! JSON file is corrupted or invalid." ) ;
115104 Log . Error ( ex . Message + "-" + ex . StackTrace ) ;
116105
117- // Create backup of corrupted file
118- var destinationFile =
119- $ "{ TimestampHelper . GetTimestamp ( ) } _corrupted_" + SettingsManager . GetSettingsFileName ( ) ;
120- File . Copy ( SettingsManager . GetSettingsFilePath ( ) ,
121- Path . Combine ( SettingsManager . GetSettingsFolderLocation ( ) , destinationFile ) ) ;
122- Log . Info ( $ "A backup of the corrupted settings file has been saved under { destinationFile } ") ;
123-
124- // Initialize default application settings
125- Log . Info ( "Initialize default application settings..." ) ;
126-
127- SettingsManager . Initialize ( ) ;
128- ConfigurationManager . Current . ShowSettingsResetNoteOnStartup = true ;
106+ HandleCorruptedSettingsFile ( ) ;
129107 }
130108
131109 // Upgrade settings if necessary
@@ -239,6 +217,25 @@ by BornToBeRoot
239217 }
240218 }
241219
220+ /// <summary>
221+ /// Handles a corrupted settings file by creating a backup and initializing default settings.
222+ /// </summary>
223+ private void HandleCorruptedSettingsFile ( )
224+ {
225+ // Create backup of corrupted file
226+ var destinationFile =
227+ $ "{ TimestampHelper . GetTimestamp ( ) } _corrupted_" + SettingsManager . GetSettingsFileName ( ) ;
228+ File . Copy ( SettingsManager . GetSettingsFilePath ( ) ,
229+ Path . Combine ( SettingsManager . GetSettingsFolderLocation ( ) , destinationFile ) ) ;
230+ Log . Info ( $ "A backup of the corrupted settings file has been saved under { destinationFile } ") ;
231+
232+ // Initialize default application settings
233+ Log . Info ( "Initialize default application settings..." ) ;
234+
235+ SettingsManager . Initialize ( ) ;
236+ ConfigurationManager . Current . ShowSettingsResetNoteOnStartup = true ;
237+ }
238+
242239 private void DispatcherTimer_Tick ( object sender , EventArgs e )
243240 {
244241 Log . Info ( "Run background job..." ) ;
0 commit comments