using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; using System.Xml; namespace ScreenConnect; public abstract class SettingsProviderEx : SettingsProvider { public override string ApplicationName { get; set; } protected static IEnumerable GetSectionNamesPrimaryFirst(SettingsContext context) { Type type = ((Hashtable)(object)context)[(object)"SettingsClassType"].To().AssertArgumentNonNull("SettingsClassType"); ConfigurationSectionAttribute attribute = type.GetCustomAttribute(); yield return attribute?.PrimarySectionName ?? type.FullName; if (attribute == null) { yield break; } foreach (string item in attribute.AlternativeSectionNames.SafeEnumerate()) { yield return item; } } protected static SettingsPropertyValueCollection GetPropertyValues(SettingsPropertyCollection settingsPropertyCollection, IList prioritizedConfigurationSectionInfos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) SettingsPropertyValueCollection val = new SettingsPropertyValueCollection(); foreach (SettingsProperty item in ((IEnumerable?)settingsPropertyCollection).OfType()) { bool restrictToTrustworthySources = ((Hashtable)(object)item.Attributes)[(object)typeof(RestrictToTrustworthySourcesAttribute)] != null; SettingsPropertyValue val2 = new SettingsPropertyValue(item); XmlNode xmlNode = TryGetSettingValueXml(prioritizedConfigurationSectionInfos, item.Name, restrictToTrustworthySources); if (xmlNode != null) { val2.SerializedValue = DeserializeFromXml(xmlNode, val2.Property.SerializeAs); } val.Add(val2); } return val; } protected static object? DeserializeFromXml(XmlNode xmlNode, SettingsSerializeAs serializeAs) { string innerText = xmlNode.InnerText; if (!(innerText == string.Empty)) { return innerText; } return null; } protected static XmlNode SerializeToXml(object? value, SettingsSerializeAs serializeAs) { XmlElement element = new XmlDocument().CreateElement("value"); value?.ToString()?.Pass(delegate(string it) { element.InnerText = it; }); return element; } protected static XmlNode? TryGetSettingValueXml(IEnumerable prioritizedConfigurationSectionInfos, string settingName, bool restrictToTrustworthySources) { foreach (ConfigurationSectionInfo prioritizedConfigurationSectionInfo in prioritizedConfigurationSectionInfos) { if (prioritizedConfigurationSectionInfo.Section == null || (restrictToTrustworthySources && !prioritizedConfigurationSectionInfo.IsTrustworthy)) { continue; } foreach (SettingElement item in ((ICollection)prioritizedConfigurationSectionInfo.Section.Settings).Cast()) { if (item.Name == settingName) { return item.Value.ValueXml; } } } return null; } protected static (Configuration Configuration, IList<(string Name, ClientSettingsSection? Section)> SectionInfos) GetConfigurationWithSectionInfos(string filePath, IList sectionNames) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = filePath }, (ConfigurationUserLevel)0); return (Configuration: configuration, SectionInfos: sectionNames.Select(delegate(string it) { ConfigurationSection section = configuration.GetSection(it); return (it: it, (ClientSettingsSection)(object)((section is ClientSettingsSection) ? section : null)); }).ToList()); } protected static (Configuration? Configuration, IList<(string Name, ClientSettingsSection? Section)>? SectionInfos) TryGetConfigurationWithSectionInfos(ConfigurationFileInfo fileInfo, IList sectionNames, int deleteIfWriteableAfterFailureCount = 4, int giveUpAfterFailureCount = 6) { int num = 0; while (true) { try { return GetConfigurationWithSectionInfos(fileInfo.FilePath, sectionNames); } catch { num++; if (num == deleteIfWriteableAfterFailureCount && fileInfo.IsWriteable) { Extensions.Try(delegate { File.Delete(fileInfo.FilePath); }); } else if (num == giveUpAfterFailureCount) { return default((Configuration, IList<(string, ClientSettingsSection)>)); } } } } protected static IList GetPrioritizedConfigurationSectionInfos(SettingsContext context, IEnumerable prioritizedConfigurationFileInfos) { List sectionNames = GetSectionNamesPrimaryFirst(context).ToList(); return (from configurationFileInfo in prioritizedConfigurationFileInfos let configurationWithSectionInfos = TryGetConfigurationWithSectionInfos(configurationFileInfo, sectionNames) from sectionInfo in configurationWithSectionInfos.SectionInfos.SafeEnumerate() select new ConfigurationSectionInfo(configurationFileInfo.FilePath, sectionInfo.Name, configurationFileInfo.IsWriteable, configurationFileInfo.IsTrustworthy, configurationWithSectionInfos.Configuration, sectionInfo.Section)).ToList(); } protected static void WriteApplicablePropertyValuesToConfiguration(IEnumerable settingsPropertyValues, IList prioritizedConfigurationSectionInfos) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Expected O, but got Unknown //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Expected O, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) int writableIndex = prioritizedConfigurationSectionInfos.IndexOf((ConfigurationSectionInfo it) => it.IsWriteable && it.Configuration != null); if (writableIndex == -1) { throw new ConfigurationErrorsException("No writable configuration sections"); } ConfigurationSectionInfo writableConfigurationSectionInfo = prioritizedConfigurationSectionInfos[writableIndex]; Configuration writableConfiguration = writableConfigurationSectionInfo.Configuration; List source = (from it in prioritizedConfigurationSectionInfos.Where((ConfigurationSectionInfo _, int i) => i != writableIndex) where it.Section != null select it).ToList(); object obj = writableConfigurationSectionInfo.Section; if (obj == null) { ConfigurationSection section = writableConfiguration.GetSection(writableConfigurationSectionInfo.SectionName); obj = ((object)((section is ClientSettingsSection) ? section : null)) ?? ((object)FunctionalExtensions.Mutate(new ClientSettingsSection(), delegate(ClientSettingsSection it) { writableConfiguration.Sections.Add(writableConfigurationSectionInfo.SectionName, (ConfigurationSection)(object)it); })); } ClientSettingsSection val = (ClientSettingsSection)obj; foreach (SettingsPropertyValue settingsPropertyValue in settingsPropertyValues) { SettingElement val2 = val.Settings.Get(settingsPropertyValue.Name); bool restrictToTrustworthySources = ((Hashtable)(object)settingsPropertyValue.Property.Attributes)[(object)typeof(RestrictToTrustworthySourcesAttribute)] != null; if (!settingsPropertyValue.UsingDefaultValue && !(from it in source where it.IsTrustworthy || !restrictToTrustworthySources select it.Section.Settings.Get(settingsPropertyValue.Name).ToNullable()).WhereNotNull().FirstOrDefault().SafePipe(delegate(SettingElement it) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) return object.Equals(DeserializeFromXml(it.Value.ValueXml, settingsPropertyValue.Property.SerializeAs), settingsPropertyValue.SerializedValue); })) { if (restrictToTrustworthySources && !writableConfigurationSectionInfo.IsTrustworthy) { throw new ConfigurationErrorsException("The configuration section " + writableConfigurationSectionInfo.FilePath + " [" + writableConfigurationSectionInfo.SectionName + "] is not trustworthy enough for setting " + settingsPropertyValue.Name); } if (val2 == null) { val2 = new SettingElement { Name = settingsPropertyValue.Name }; val.Settings.Add(val2); } val2.SerializeAs = settingsPropertyValue.Property.SerializeAs; val2.Value.ValueXml = SerializeToXml(settingsPropertyValue.SerializedValue, val2.SerializeAs); } else if (val2 != null) { val.Settings.Remove(val2); } } Extensions.Try(delegate { writableConfiguration.Save(); }); } }