/// <summary> /// Checks the settings file for required settings. /// If not all required settings are present, a backup is made, valid settings are moved over, and an automated resolution is attempted. /// In an event of only one required setting missing with one setting in the file unrecognized, the two settings are considered related and the situation is resolved. /// Otherwise direct intervention is necessary to move unrecognized settings over to the newly generated file. /// </summary> private void ValidateFileSettings() { var missingSettingNames = _requiredSettingNames.Except(_settings.Keys); var recognizedSettingNames = _requiredSettingNames.Intersect(_settings.Keys); var unrecognizedSettingNames = _settings.Keys.Except(recognizedSettingNames); if (missingSettingNames.Any()) { _fileManager.BackUpFile(_settingsFile); GenerateSettingsFile(); foreach (var recognizedSettingName in recognizedSettingNames) { Save(recognizedSettingName, _settings[recognizedSettingName]); } if (missingSettingNames.HasSingle() && unrecognizedSettingNames.HasSingle()) // It is assumed that a setting was renamed. { var missingSettingName = missingSettingNames.First(); var unrecognizedSettingName = unrecognizedSettingNames.First(); var settingValue = _settings[unrecognizedSettingName]; Save(missingSettingName, settingValue); _settings.Add(missingSettingName, settingValue); _settings.Remove(unrecognizedSettingName); SettingsFileStatus = ESettingsFileStatus.FoundAndAutomaticallyUpdated; } else { SettingsFileStatus = ESettingsFileStatus.FoundAndNeedsManualUpdate; throw new SettingsFileRegeneratedException(); } } else { SettingsFileStatus = ESettingsFileStatus.FoundAndUpToDate; } }