private string Generate_SettingsXml() { // remove the ' *' autoload indicator from the addon names var globaladdons = new List <string>(); foreach (var addon in Global_Addons) { globaladdons.Add(addon.Replace(" *", "")); } var xml = "<?xml version=\"1.1\" ?>" + Environment.NewLine; xml += "<settings>" + Environment.NewLine; xml += " <global>" + Environment.NewLine; xml += " <global_addons>" + string.Join(",", globaladdons) + "</global_addons>" + Environment.NewLine; // CHARACTER var playeraddons = new List <CharSettings>(); foreach (var entry in Player_Addons) { var cs = new CharSettings { Name = entry.Name, Addons = new List <string>() }; foreach (var addon in entry.Addons) { cs.Addons.Add(addon.Replace(" *", "")); } playeraddons.Add(cs); } xml += " <player_addons>" + Environment.NewLine; foreach (var entry in playeraddons) { var playername = entry.Name.ToLower(); var addons = string.Join(",", entry.Addons); xml += " <" + playername + ">" + string.Join(",", entry.Addons) + "</" + playername + ">" + Environment.NewLine; } xml += " </player_addons>" + Environment.NewLine; xml += " <player_plugins></player_plugins>" + Environment.NewLine; // JOB var byjob = new List <JobSettings>(); foreach (var entry in By_Job) { var cs = new JobSettings { Job = entry.Job, Addons = new List <string>() }; foreach (var addon in entry.Addons) { cs.Addons.Add(addon.Replace(" *", "")); } byjob.Add(cs); } xml += " <by_job>" + Environment.NewLine; foreach (var entry in byjob) { var job = entry.Job.ToLower(); var addons = string.Join(",", entry.Addons); xml += " <" + job + ">" + Environment.NewLine; xml += " <addons>" + string.Join(",", entry.Addons) + "</addons>" + Environment.NewLine; xml += " <plugins></plugins>" + Environment.NewLine; xml += " <ignore></ignore>" + Environment.NewLine; xml += " </" + job + ">" + Environment.NewLine; } foreach (var entry in All_Jobs) // add empty entries for jobs without addons. { var job = entry.Trim().ToLower(); if (string.IsNullOrEmpty(job) || By_Job.Where(x => x.Job.ToLower() == job).FirstOrDefault() != null) { continue; } xml += " <" + job + ">" + Environment.NewLine; xml += " <addons></addons>" + Environment.NewLine; xml += " <plugins></plugins>" + Environment.NewLine; xml += " <ignore></ignore>" + Environment.NewLine; xml += " </" + job + ">" + Environment.NewLine; } xml += " </by_job>" + Environment.NewLine; // ZONE var byzone = new List <ZoneSettings>(); foreach (var entry in By_Zone) { var cs = new ZoneSettings { GroupId = entry.GroupId, Zones = entry.Zones, Addons = new List <string>() }; foreach (var addon in entry.Addons) { cs.Addons.Add(addon.Replace(" *", "")); } byzone.Add(cs); } xml += " <by_zone>" + Environment.NewLine; foreach (var entry in byzone) { var key = entry.GroupId.ToLower(); var addons = string.Join(",", entry.Addons); xml += " <" + key + ">" + Environment.NewLine; xml += " <zone_names>" + string.Join(",", entry.Zones) + "</zone_names>" + Environment.NewLine; xml += " <addons>" + string.Join(",", entry.Addons) + "</addons>" + Environment.NewLine; xml += " <plugins></plugins>" + Environment.NewLine; xml += " <ignore></ignore>" + Environment.NewLine; xml += " </" + key + ">" + Environment.NewLine; } xml += " </by_zone>" + Environment.NewLine; xml += " <load_delay>5</load_delay>" + Environment.NewLine; xml += " </global>" + Environment.NewLine; xml += "</settings>" + Environment.NewLine; return(xml); }
private void Btn_AddZone_Click(object sender, RoutedEventArgs e) { var groupid = Cb_ZoneGroups.SelectedIndex != -1 ? Cb_ZoneGroups.Items[Cb_ZoneGroups.SelectedIndex].ToString() : string.Empty; var zone = (Cb_Zones.SelectedIndex != -1 && Cb_Zones.Items[Cb_Zones.SelectedIndex].ToString() != Zones_Header) ? Cb_Zones.Items[Cb_Zones.SelectedIndex].ToString() : string.Empty; var addon = lb_Addons.SelectedItem != null?lb_Addons.SelectedItem.ToString() : string.Empty; if (string.IsNullOrEmpty(zone.Trim()) && string.IsNullOrEmpty(addon.Trim())) { return; } ZoneSettings entry = new ZoneSettings(); if (string.IsNullOrEmpty(groupid) || groupid.ToLower() == ZoneGroups_Header.ToLower()) { // Generate a new group id. groupid = Generate_GroupId().ToUpper(); Zone_Groups.Add(groupid); UnsavedChanges = true; entry = new ZoneSettings() { GroupId = groupid, Zones = !string.IsNullOrEmpty(zone) ? new List <string>() { zone } : new List <string>(), Addons = !string.IsNullOrEmpty(addon) ? new List <string>() { addon } : new List <string>() }; By_Zone.Add(entry); Cb_ZoneGroups.Items.Refresh(); } else { entry = By_Zone.Where(x => x.GroupId.ToLower() == groupid.ToLower()).FirstOrDefault(); if (entry != null) { if (!string.IsNullOrEmpty(zone.Trim()) && entry.Zones.Where(x => x.ToLower() == zone.ToLower()).FirstOrDefault() == null) { UnsavedChanges = true; entry.Zones.Add(zone); } if (!string.IsNullOrEmpty(addon.Trim()) && entry.Addons.Where(x => x.ToLower() == addon.ToLower()).FirstOrDefault() == null) { UnsavedChanges = true; entry.Addons.Add(addon); } } else { MessageBox.Show("An error occured while trying to find the GroupId within by_zone.\n" + groupid); } } Set_Status(); lb_Zones.Items.Refresh(); }