private void BindData() { FileName = GetStringParameter("f", ""); SettingName = GetStringParameter("gs", ""); if (!FileName.Equals("") && !SettingName.Equals("")) { List <string> presetFileLines = SettingsFiles.GetPresetFileLinesAsList(PTMagicBasePath, SettingName, FileName, PTMagicConfiguration); FileContent = SystemHelper.ConvertListToTokenString(presetFileLines, Environment.NewLine, false); } }
public T Resolve <T>(string name = null) { var matchingOnes = name == null ? SettingsFiles.Where(s => s.Type == typeof(T)) : SettingsFiles.Where(s => s.Name == name); if (!matchingOnes.Any()) { throw new NullReferenceException(string.Format("None of the settings matched for {0}", name == null ? typeof(T).Name : name)); } return((T)matchingOnes.First().ResolveObject(RootFolder)); }
internal void AddOrUpdate(SettingsFile settingsFile, string sectionName, SettingItem item) { if (string.IsNullOrEmpty(sectionName)) { throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(sectionName)); } if (item == null) { throw new ArgumentNullException(nameof(item)); } var currentSettings = Priority.Last(f => f.Equals(settingsFile)); if (settingsFile.IsMachineWide || (currentSettings?.IsMachineWide ?? false)) { throw new InvalidOperationException(Resources.CannotUpdateMachineWide); } if (settingsFile.IsReadOnly || (currentSettings?.IsReadOnly ?? false)) { throw new InvalidOperationException(Resources.CannotUpdateReadOnlyConfig); } if (currentSettings == null) { SettingsFiles.Add(settingsFile); } // If it is an update this will take care of it and modify the underlaying object, which is also referenced by _computedSections. settingsFile.AddOrUpdate(sectionName, item); // AddOrUpdate should have created this section, therefore this should always exist. settingsFile.TryGetSection(sectionName, out var settingFileSection); // If it is an add we have to manually add it to the _computedSections. var computedSectionExists = _computedSections.TryGetValue(sectionName, out var section); if (computedSectionExists && !section.Items.Contains(item)) { var existingItem = settingFileSection.Items.First(i => i.Equals(item)); section.Add(existingItem); } else if (!computedSectionExists) { _computedSections.Add(sectionName, new VirtualSettingSection(settingFileSection)); } }
public static new (List <Dictionary <string, string> >, List <(string, string)>, List <string>) GetConfigurationSections() { Serilog.Log.Debug("{0} {1}: GetConfigurationSections Enter at {2}", "PluginVAGameAOE", "GetConfigurationSections", DateTime.Now.ToString(StringConstantsVA.DATE_FORMAT)); (List <Dictionary <string, string> > lDCs, List <(string, string)> lSFTs, List <string> lEVPs) = ATAP.Utilities.VoiceAttack.Game.Plugin.GetConfigurationSections(); List <Dictionary <string, string> > DefaultConfigurations = new(); List <(string, string)> SettingsFiles = new(); List <string> CustomEnvironmentVariablePrefixs = new(); DefaultConfigurations.AddRange(lDCs); // Use the version of merge that throws an error if a duplicate key exists SettingsFiles.AddRange(lSFTs); CustomEnvironmentVariablePrefixs.AddRange(lEVPs); DefaultConfigurations.Add(ATAP.Utilities.VoiceAttack.Game.AOE.DefaultConfiguration.Production); SettingsFiles.Add((StringConstants.SettingsFileName, StringConstants.SettingsFileNameSuffix)); CustomEnvironmentVariablePrefixs.Add(StringConstants.CustomEnvironmentVariablePrefix); return(DefaultConfigurations, SettingsFiles, CustomEnvironmentVariablePrefixs); }