/// <summary> /// Writing data in an XML format. /// </summary> /// <param name="fileName"></param> private void SaveToXmlFile(string fileName) { int totalCount = StringRefs.Count(); int count = 0; int lastProgress = -1; XmlTextWriter xr = new XmlTextWriter(fileName, Encoding.UTF8); xr.Formatting = Formatting.Indented; xr.Indentation = 4; xr.WriteStartDocument(); xr.WriteStartElement("tlkFile"); xr.WriteAttributeString("TLKToolVersion", App.GetVersion()); xr.WriteComment("Male entries section begin"); foreach (var s in StringRefs) { if (s.position == Header.MaleEntryCount) { xr.WriteComment("Male entries section end"); xr.WriteComment("Female entries section begin"); } xr.WriteStartElement("String"); xr.WriteStartAttribute("id"); xr.WriteValue(s.StringID); xr.WriteEndAttribute(); if (s.BitOffset < 0) { xr.WriteStartAttribute("calculatedID"); xr.WriteValue(-(Int32.MinValue - s.StringID)); xr.WriteEndAttribute(); xr.WriteString("-1"); } else { xr.WriteString(s.Data); } xr.WriteEndElement(); // </string> int progress = (++count * 100) / totalCount; if (progress > lastProgress) { lastProgress = progress; OnProgressChanged(lastProgress); } } xr.WriteComment("Female entries section end"); xr.WriteEndElement(); // </tlkFile> xr.Flush(); xr.Close(); }
/// <summary> /// Writing data in an XML format. /// </summary> /// <param name="fileName"></param> private void SaveToXmlFile(string fileName) { int totalCount = StringRefs.Count(); int count = 0; int lastProgress = -1; XmlTextWriter xr = new XmlTextWriter(fileName, Encoding.UTF8); xr.Formatting = Formatting.Indented; xr.Indentation = 4; xr.WriteStartDocument(); xr.WriteStartElement("tlkFile"); xr.WriteAttributeString("TLKToolVersion", App.GetVersion()); xr.WriteComment("Male entries section begin (ends at position " + (Header.entry1Count - 1) + ")"); foreach (var s in StringRefs) { if (s.position == Header.entry1Count) { xr.WriteComment("Male entries section end"); xr.WriteComment("Female entries section begin (ends at position " + (Header.entry1Count + Header.entry2Count - 1) + ")"); } xr.WriteStartElement("string"); xr.WriteStartElement("id"); xr.WriteValue(s.StringID); xr.WriteEndElement(); // </id> xr.WriteStartElement("position"); xr.WriteValue(s.position); xr.WriteEndElement(); // </position> if (s.BitOffset < 0) xr.WriteElementString("data", "-1"); else xr.WriteElementString("data", s.Data); xr.WriteEndElement(); // </string> int progress = (++count * 100) / totalCount; if (progress > lastProgress) { lastProgress = progress; OnProgressChanged(lastProgress); } } xr.WriteComment("Female entries section end"); xr.WriteEndElement(); // </tlkFile> xr.Flush(); xr.Close(); }
/// <summary> /// Writes data stored in memory to an appriopriate text format. /// </summary> /// <param name="fileName"></param> public void DumpToFile(string fileName) { File.Delete(fileName); /* for now, it's better not to sort, to preserve original order */ // StringRefs.Sort(CompareTlkStringRef); int totalCount = StringRefs.Count(); int count = 0; int lastProgress = -1; XmlTextWriter xr = new XmlTextWriter(fileName, Encoding.UTF8); xr.Formatting = Formatting.Indented; xr.Indentation = 4; xr.WriteStartDocument(); xr.WriteStartElement("tlkFile"); xr.WriteAttributeString("TLKToolVersion", App.GetVersion()); xr.WriteComment("Male entries section begin"); foreach (var s in StringRefs) { if (s.Index == Header.MaleEntryCount) { xr.WriteComment("Male entries section end"); xr.WriteComment("Female entries section begin"); } xr.WriteStartElement("String"); xr.WriteStartAttribute("id"); xr.WriteValue(s.StringID); xr.WriteEndAttribute(); if (s.BitOffset < 0) { xr.WriteStartAttribute("calculatedID"); xr.WriteValue(-(Int32.MinValue - s.StringID)); xr.WriteEndAttribute(); xr.WriteString("-1"); } else { xr.WriteString(s.Data); } xr.WriteEndElement(); // </string> int progress = (++count * 100) / totalCount; if (progress > lastProgress) { lastProgress = progress; OnProgressChanged(lastProgress); } } xr.WriteComment("Female entries section end"); xr.WriteEndElement(); // </tlkFile> xr.Flush(); xr.Close(); }