File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 22using System . Diagnostics ;
33using System . IO ;
44using System . Linq ;
5+ using System . Text . Json ;
56using System . Threading ;
67using System . Windows ;
78using System . Windows . Threading ;
@@ -108,6 +109,24 @@ by BornToBeRoot
108109 SettingsManager . Initialize ( ) ;
109110 ConfigurationManager . Current . ShowSettingsResetNoteOnStartup = true ;
110111 }
112+ catch ( JsonException ex )
113+ {
114+ Log . Error ( "Could not load application settings! JSON file is corrupted or invalid." ) ;
115+ Log . Error ( ex . Message + "-" + ex . StackTrace ) ;
116+
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 ;
129+ }
111130
112131 // Upgrade settings if necessary
113132 var settingsVersion = Version . Parse ( SettingsManager . Current . Version ) ;
You can’t perform that action at this time.
0 commit comments