public void import(XmlDocument doc) { XmlNode blk = null; if (doc.DocumentElement.Name == "lure-strings") { blk = LureCommon.findNode(doc.DocumentElement, "block"); } else if (doc.DocumentElement.Name == "lure-texts") { blk = LureCommon.findNode(LureCommon.findNode(doc.DocumentElement, "file", "id", resnum.ToString()), "block"); } else { throw new Exception("bad strings xml"); } ushort count = BinaryHelper.readU16_LE(data, 0); int curofs = 2; for (int i = 0; i < count; i++) { XmlNode nd = LureCommon.findNode(blk, "text", "id", i.ToString()); string val = ""; if (nd.ChildNodes.Count > 0) { val = LureConfig.get().convert(nd.ChildNodes[0].Value); } data = LureCommon.checkArrLength(data, curofs + val.Length + 1); BinaryHelper.writeZString(data, ref curofs, val); } LureDisks.setResource(resnum, data); }
public void import(XmlDocument xml) { XmlNode blkhld = null; if (xml.DocumentElement.Name == "lure-text") { blkhld = xml.DocumentElement; } else if (xml.DocumentElement.Name == "lure-texts") { blkhld = LureCommon.findNode(xml.DocumentElement, "file", "id", resnum.ToString()); } else { throw new Exception("Bad text xml"); } TextDecoder.get().readDecoder(true); XmlDocument prev = export(true); TextDecoder.get().readDecoder(false); uint bitbuf = 0; int bitpos = 0; List <byte> txtdata = new List <byte>(); List <UInt16> bs = new List <UInt16>(); List <byte> skp = new List <byte>(); int prevblk = 0; foreach (XmlNode nd in prev.DocumentElement.ChildNodes) { XmlNode blk = LureCommon.findNode(blkhld, "block", "id", nd.Attributes["id"].Value); int prevtxt = prevblk; foreach (XmlNode tnd in nd.ChildNodes) { //bool art = tnd.Attributes["art"].Value == "1"; XmlNode txt = LureCommon.findNode(blk, "text", "id", tnd.Attributes["id"].Value); string val = ""; if (txt.ChildNodes.Count > 0) { val = txt.ChildNodes[0].Value; } val = LureNames.get().processNames(LureConfig.get().convert(val)); addText(val, txtdata, ref bitbuf, ref bitpos, tnd.Attributes["art"].Value == "1"); if (bitpos % 2 == 1) { addbit(false, txtdata, ref bitbuf, ref bitpos); } // if (tnd != nd.LastChild) { int ofs = (txtdata.Count << 2) + bitpos / 2; int d = ofs - prevtxt; if (d > 0x7F) { while ((d & 7) != 0) { addbit(false, txtdata, ref bitbuf, ref bitpos); ofs = (txtdata.Count << 2) + bitpos / 2; d = ofs - prevtxt; } d = (d >> 3) | 0x80; } skp.Add((byte)d); prevtxt = ofs; } } if (nd != prev.DocumentElement.LastChild) { int offset = (txtdata.Count << 2) + bitpos / 2; bs.Add((UInt16)(offset - prevblk)); prevblk = offset; } } while (bitpos != 0) { addbit(false, txtdata, ref bitbuf, ref bitpos); } data = new byte[4 + bs.Count * 2 + skp.Count + txtdata.Count]; int o = 4; for (int i = 0; i < bs.Count; i++) { BinaryHelper.write_LE(data, o, bs[i]); o += 2; } BinaryHelper.write_LE(data, 0, (UInt16)o); for (int i = 0; i < skp.Count; i++) { data[o++] = skp[i]; } BinaryHelper.write_LE(data, 2, (UInt16)o); for (int i = 0; i < txtdata.Count; i++) { data[o++] = txtdata[i]; } LureDisks.setResource(resnum, data); }