public string SaveMetaToFile(string outputFileName, bool renameTag)
{
string[] splitOut = outputFileName.Split('\\');
// if the filename contains an extension, remove it from the split list
if (splitOut[splitOut.Length - 1].Contains("."))
{
splitOut[splitOut.Length - 1] = splitOut[splitOut.Length - 1].Substring(0, splitOut[splitOut.Length - 1].IndexOf('.'));
}
string[] splitOrig = this.name.Split('\\');
// use the starting path for the tag name...
string tempName = string.Empty;
for (int i = 0; i < splitOrig.Length; i++)
{
if (splitOrig[i] != splitOrig[splitOrig.Length - 1])
tempName += splitOrig[i];
else
tempName += splitOut[splitOut.Length - 1];
if (i < splitOrig.Length - 1)
tempName += "\\";
}
if (renameTag)
{
tempName = askForTagName(tempName);
if (tempName == string.Empty)
{
return this.name;
}
}
outputFileName = outputFileName.Replace("<", "_");
outputFileName = outputFileName.Replace(">", "_");
// write memorysteam of meta to file
BinaryWriter BW = new BinaryWriter(new FileStream(outputFileName, FileMode.Create));
BW.BaseStream.Position = 0;
BW.BaseStream.Write(this.MS.ToArray(), 0, this.size);
BW.Flush();
BW.Close();
XmlTextWriter xtw = new XmlTextWriter(outputFileName + ".xml", Encoding.Default);
xtw.Formatting = Formatting.Indented;
xtw.WriteStartElement("Meta");
xtw.WriteAttributeString("TagType", this.type);
xtw.WriteAttributeString("TagName", tempName);
xtw.WriteAttributeString("Offset", this.offset.ToString());
xtw.WriteAttributeString("Size", this.size.ToString());
xtw.WriteAttributeString("Magic", this.magic.ToString());
xtw.WriteAttributeString("Parsed", this.parsed.ToString());
xtw.WriteAttributeString("Date", DateTime.Today.ToShortDateString());
xtw.WriteAttributeString("Time", DateTime.Now.ToShortTimeString());
xtw.WriteAttributeString("EntityVersion", "0.1");
xtw.WriteAttributeString("Padding", this.padding.ToString());
// xtw.
for (int x = 0; x < this.items.Count; x++)
{
Item i = this.items[x];
if (i.intagname == this.name)
i.intagname = tempName;
switch (i.type)
{
case ItemType.Reflexive:
Reflexive r = (Reflexive)i;
xtw.WriteStartElement("Reflexive");
xtw.WriteAttributeString("Description", r.description);
xtw.WriteAttributeString("Offset", r.offset.ToString());
xtw.WriteAttributeString("ChunkCount", r.chunkcount.ToString());
xtw.WriteAttributeString("ChunkSize", r.chunksize.ToString());
xtw.WriteAttributeString("Translation", r.translation.ToString());
xtw.WriteAttributeString("PointsToTagType", r.pointstotagtype);
xtw.WriteAttributeString("PointsToTagName", r.pointstotagname);
xtw.WriteAttributeString("TagType", r.intagtype);
xtw.WriteAttributeString("TagName", r.intagname);
xtw.WriteEndElement();
break;
case ItemType.Ident:
Ident id = (Ident)i;
xtw.WriteStartElement("Ident");
xtw.WriteAttributeString("Description", id.description);
xtw.WriteAttributeString("Offset", id.offset.ToString());
xtw.WriteAttributeString("PointsToTagType", id.pointstotagtype);
xtw.WriteAttributeString("PointsToTagName", id.pointstotagname);
xtw.WriteAttributeString("TagType", id.intagtype);
xtw.WriteAttributeString("TagName", id.intagname);
xtw.WriteEndElement();
break;
case ItemType.String:
String s = (String)i;
xtw.WriteStartElement("String");
xtw.WriteAttributeString("Description", s.description);
xtw.WriteAttributeString("Offset", s.offset.ToString());
xtw.WriteAttributeString("StringName", s.name);
xtw.WriteAttributeString("TagType", s.intagtype);
xtw.WriteAttributeString("TagName", s.intagname);
xtw.WriteEndElement();
break;
}
if (i.intagname == tempName)
i.intagname = this.name;
}
xtw.WriteEndElement();
xtw.Flush();
xtw.Close();
if (this.rawType != RawDataContainerType.Empty)
{
this.raw.SaveRawToFile(outputFileName, this);
}
return tempName;
}