public static SiteScript ConvertListSchema(Stream xmlStream) { dynamic document = DynamicXml.Load(xmlStream); return(ConvertListSchema(document)); }
private void LoadDynamicXml(string path, bool debugVersion = false) { var tlkFile = new TlkFile(); var tlkStrings = new List <TlkString>(); using (var stream = new FileStream(path, FileMode.Open)) { dynamic tlkXml = DynamicXml.Load(stream); tlkXml.TlkFile(DynamicXml.GetElement(tlkfile => { if (tlkfile["id"] != null) { tlkFile.Id = tlkfile["id"]; } if (tlkfile["name"] != null) { tlkFile.Name = tlkfile["name"]; } if (tlkfile["source"] != null) { tlkFile.Source = tlkfile["source"]; } if (tlkfile.Includes != null) { tlkfile.Includes(DynamicXml.GetElement(includes => { var order = -1; foreach (var include in includes.Include) { if (include["order"] != null) { order = Convert.ToInt32(include["order"]); } var source = include["source"]; if (order >= 0) { tlkFile.Includes.Insert(order, source); } else { tlkFile.Includes.Add(source); } } })); } if (tlkfile.Strings != null) { tlkfile.Strings(DynamicXml.GetElement(strings => { if (strings.String == null) { return; } var i = 0; foreach (var str in strings.String) { var strId = InvalidIdRegex.Replace(str["id"], ""); var id = Convert.ToInt32(strId); var value = str.Value.Replace("\r\n", "\n"); var alwaysAdd = false; if (str["alwaysAdd"] != null) { alwaysAdd = Convert.ToBoolean(str["alwaysAdd"]); } if (id >= 0) { value += '\0'; } if (id >= 0 && debugVersion && (id & 0x8000000) != 0x8000000) { value = "(#" + id + ") " + value; } tlkStrings.Add(new TlkString(id, value, i++)); } })); } })); } var index = 0; foreach (var include in tlkFile.Includes) { var includePath = Path.GetDirectoryName(path); if (includePath == null) { continue; } includePath = Path.Combine(includePath, include); if (!File.Exists(includePath)) { continue; } using (var stream = new FileStream(includePath, FileMode.Open)) { dynamic tlkXml = DynamicXml.Load(stream); tlkXml.TlkFile(DynamicXml.GetElement(tlkfile => { if (tlkfile.Strings == null) { return; } tlkfile.Strings(DynamicXml.GetElement(strings => { if (strings.String == null) { return; } foreach (var str in strings.String) { var strId = InvalidIdRegex.Replace(str["id"], ""); var id = Convert.ToInt32(strId); var value = str.Value.Replace("\r\n", "\n"); var alwaysAdd = false; if (str["alwaysAdd"] != null) { alwaysAdd = Convert.ToBoolean(str["alwaysAdd"]); } if (id >= 0) { value += '\0'; } if (id >= 0 && debugVersion && (id & 0x8000000) != 0x8000000) { value = "(#" + id + ") " + value; } /*if (alwaysAdd || _inputData.Count(s => s.Id == id) == 0) * { * _inputData.Add(new TlkString(id, value, index++)); * } * else * { * var strIndex = _inputData.FindIndex(s => s.Id == id); * * if (strIndex >= 0) * { * _inputData[strIndex] = value; * } * }*/ _maleStrings.Add(new TlkString(id, value, index++)); } })); })); } } foreach (var tlkString in tlkStrings) { _maleStrings.Add(new TlkString(tlkString.Id, tlkString.Value, tlkString.Position + index++)); } }
public static SiteScript ConvertListSchema(string filePath) { dynamic document = DynamicXml.Load(filePath); return(ConvertListSchema(document)); }