Bloom.Program.CheckForCorruptUserConfig C# (CSharp) Method

CheckForCorruptUserConfig() private static method

private static CheckForCorruptUserConfig ( ) : void
return void
        private static void CheckForCorruptUserConfig()
        {
            //First check the user.config we get through using the palaso stuff.  This is the one in a folder with a name like Bloom/3.5.0.0
            var palasoSettings = new SIL.Settings.CrossPlatformSettingsProvider();
            palasoSettings.Initialize(null,null);
            var error = palasoSettings.CheckForErrorsInSettingsFile();
            if (error != null)
            {
                //Note: this is probably too early to do anything more complicated that writing to a log...
                //Enhance: we might be able to do a MessageBox.Show(), but it would be better to save this error
                //and inform the user later when the UI can interact with them.
                Logger.WriteEvent("error reading palaso user config: "+error.Message);
                Logger.WriteEvent("Should self-heal");
            }

            //Now check the plain .net user.config we also use (sigh). This is the one in a folder with a name like Bloom.exe_Url_avygitvf1lws5lpjrmoh5j0ggsx4tkj0

            //roughly from http://stackoverflow.com/questions/9572243/what-causes-user-config-to-empty-and-how-do-i-restore-without-restarting
            try
            {
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
            }
            catch (ConfigurationErrorsException ex)
            {
                Logger.WriteEvent("Cannot open user config file "+ex.Filename);
                Logger.WriteEvent(ex.Message);

                if (RobustFile.Exists(ex.Filename))
                {
                    Logger.WriteEvent("Config file content:\n{0}", RobustFile.ReadAllText(ex.Filename));
                    Logger.WriteEvent("Deleting "+ ex.Filename);
                    RobustFile.Delete(ex.Filename);
                    Properties.Settings.Default.Upgrade();
                    // Properties.Settings.Default.Reload();
                    // you could optionally restart the app instead
                }
                else
                {
                    Logger.WriteEvent("Config file {0} does not exist", ex.Filename);
                }
            }
        }