public void InitLuaSetting() { LuaSettings = new Dictionary <string, LuaSet>(); List <XElement> invalids = new List <XElement>(); foreach (XElement element in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { var fe = element.Element(SettingConstants.SettingKeys.FileEncoding); var encoding = EncodingName.UTF8; if (fe == null) { element.Add(new XElement(SettingConstants.SettingKeys.FileEncoding, encoding)); } else { encoding = (EncodingName)Enum.Parse(typeof(EncodingName), fe.Value); } var wp = string.Empty; var workingpath = element.Element(SettingConstants.SettingKeys.WorkingPath); if (workingpath == null) { element.Add(new XElement(SettingConstants.SettingKeys.WorkingPath, "")); } else { wp = workingpath.Value; } LuaSet set = new LuaSet( element.Element(SettingConstants.SettingKeys.LuaFolder).Value, element.Element(SettingConstants.SettingKeys.LuaExec).Value, wp, element.Element(SettingConstants.SettingKeys.LuaExecArg).Value, encoding ); if (Directory.Exists(set.Folder)) { LuaSettings.Add(element.Element(SettingConstants.SettingKeys.SetName).Value, set); } else { invalids.Add(element); } } foreach (XElement element in invalids) { element.Remove(); } Save(); }
public void AddSetting(string Name, string Folder, string LuaExecutable, string WorkingPath, string CommandLine, EncodingName Encoding) { var set = new LuaSet(Folder, LuaExecutable, WorkingPath, CommandLine, Encoding); if (LuaSettings.ContainsKey(Name)) { LuaSettings[Name] = set; } else { LuaSettings.Add(Name, set); } XElement element = null; foreach (var xl in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { if (xl.Element(SettingConstants.SettingKeys.SetName).Value.Contains(Name)) { element = xl; break; } } if (element == null) { element = new XElement(SettingConstants.SettingKeys.Set); element.Add(new XElement(SettingConstants.SettingKeys.SetName, Name)); element.Add(new XElement(SettingConstants.SettingKeys.LuaFolder, Folder)); element.Add(new XElement(SettingConstants.SettingKeys.LuaExec, LuaExecutable)); element.Add(new XElement(SettingConstants.SettingKeys.WorkingPath, WorkingPath)); element.Add(new XElement(SettingConstants.SettingKeys.LuaExecArg, CommandLine)); element.Add(new XElement(SettingConstants.SettingKeys.FileEncoding, Encoding)); XMLLuaSettings.Add(element); } else { element.ReplaceNodes( new XElement(SettingConstants.SettingKeys.SetName, Name), new XElement(SettingConstants.SettingKeys.LuaFolder, Folder), new XElement(SettingConstants.SettingKeys.LuaExec, LuaExecutable), new XElement(SettingConstants.SettingKeys.WorkingPath, WorkingPath), new XElement(SettingConstants.SettingKeys.LuaExecArg, CommandLine), new XElement(SettingConstants.SettingKeys.FileEncoding, Encoding) ); } }
void InitLuaSetting() { if (XMLLuaSettings.Element(SettingConstants.SettingKeys.CurrentSet) == null) { XMLLuaSettings.Add(new XElement(SettingConstants.SettingKeys.CurrentSet)); } LuaSettings = new Dictionary <string, LuaSet>(); if (XMLLuaSettings.Elements().Count() > 1 && XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set).Count() == 0) { var node = XMLLuaSettings.FirstNode as XElement; while (node.NextNode != null) { node = node.NextNode as XElement; node.Add(new XElement(SettingConstants.SettingKeys.SetName, node.Name.LocalName)); node.Name = SettingConstants.SettingKeys.Set; } Save(); } List <XElement> invalids = new List <XElement>(); foreach (XElement element in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { var fe = element.Element(SettingConstants.SettingKeys.FileEncoding); var encoding = EncodingName.UTF8; if (fe == null) { element.Add(new XElement(SettingConstants.SettingKeys.FileEncoding, encoding)); } else { encoding = (EncodingName)Enum.Parse(typeof(EncodingName), fe.Value); } var wp = string.Empty; var workingpath = element.Element(SettingConstants.SettingKeys.WorkingPath); if (workingpath == null) { element.Add(new XElement(SettingConstants.SettingKeys.WorkingPath, "")); } else { wp = workingpath.Value; } LuaSet set = new LuaSet( element.Element(SettingConstants.SettingKeys.LuaFolder).Value, element.Element(SettingConstants.SettingKeys.LuaExec).Value, wp, element.Element(SettingConstants.SettingKeys.LuaExecArg).Value, encoding ); if (Directory.Exists(set.Folder)) { LuaSettings.Add(element.Element(SettingConstants.SettingKeys.SetName).Value, set); } else { invalids.Add(element); } } foreach (XElement element in invalids) { element.Remove(); } Save(); }
public void InitLuaSetting() { LuaSettings = new Dictionary<string, LuaSet>(); List<XElement> invalids = new List<XElement>(); foreach (XElement element in XMLLuaSettings.Elements(SettingConstants.SettingKeys.Set)) { var fe = element.Element(SettingConstants.SettingKeys.FileEncoding); var encoding = EncodingName.UTF8; if (fe == null) { element.Add(new XElement(SettingConstants.SettingKeys.FileEncoding, encoding)); } else { encoding = (EncodingName)Enum.Parse(typeof(EncodingName), fe.Value); } var wp = string.Empty; var workingpath = element.Element(SettingConstants.SettingKeys.WorkingPath); if (workingpath == null) { element.Add(new XElement(SettingConstants.SettingKeys.WorkingPath, "")); } else { wp = workingpath.Value; } LuaSet set = new LuaSet( element.Element(SettingConstants.SettingKeys.LuaFolder).Value, element.Element(SettingConstants.SettingKeys.LuaExec).Value, wp, element.Element(SettingConstants.SettingKeys.LuaExecArg).Value, encoding ); if (Directory.Exists(set.Folder)) { LuaSettings.Add(element.Element(SettingConstants.SettingKeys.SetName).Value, set); } else { invalids.Add(element); } } foreach (XElement element in invalids) { element.Remove(); } Save(); }