public LoadMetaFromFile ( string inputFileName ) : void | ||
inputFileName | string | The XML file name. |
Результат | void |
public void LoadMetaFromFile(string inputFileName)
{
// write memorysteam of meta to file
FileStream FS = new FileStream(inputFileName, FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
this.size = (int)FS.Length;
this.MS = new MemoryStream(this.size);
BR.BaseStream.Position = 0;
this.MS.Write(BR.ReadBytes(this.size), 0, this.size);
BR.Close();
FS.Close();
// write idents,strings,reflexives
XmlTextReader xtr = new XmlTextReader(inputFileName + ".xml");
xtr.WhitespaceHandling = WhitespaceHandling.None;
while (xtr.Read())
{
// MessageBox.Show(xtr.Name);
switch (xtr.NodeType)
{
case XmlNodeType.Element:
if (xtr.Name == "Meta")
{
this.type = xtr.GetAttribute("TagType");
this.name = xtr.GetAttribute("TagName");
this.parsed = xtr.GetAttribute("Parsed") == "True" ? true : false;
this.size = Convert.ToInt32(xtr.GetAttribute("Size"));
this.magic = Convert.ToInt32(xtr.GetAttribute("Magic"));
this.padding = Convert.ToChar(xtr.GetAttribute("Padding"));
this.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
}
else if (xtr.Name == "Reflexive")
{
Reflexive r = new Reflexive();
r.description = xtr.GetAttribute("Description");
r.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
r.chunkcount = Convert.ToInt32(xtr.GetAttribute("ChunkCount"));
r.chunksize = Convert.ToInt32(xtr.GetAttribute("ChunkSize"));
r.translation = Convert.ToInt32(xtr.GetAttribute("Translation"));
r.pointstotagtype = xtr.GetAttribute("PointsToTagType");
r.pointstotagname = xtr.GetAttribute("PointsToTagName");
r.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType(
r.pointstotagtype, r.pointstotagname);
r.intagtype = xtr.GetAttribute("TagType");
r.intagname = xtr.GetAttribute("TagName");
r.intag = Map.Functions.ForMeta.FindByNameAndTagType(r.intagtype, r.intagname);
this.items.Add(r);
}
else if (xtr.Name == "Ident")
{
Ident id = new Ident();
id.description = xtr.GetAttribute("Description");
id.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
id.pointstotagtype = xtr.GetAttribute("PointsToTagType");
id.pointstotagname = xtr.GetAttribute("PointsToTagName");
id.pointstoTagIndex = Map.Functions.ForMeta.FindByNameAndTagType(
id.pointstotagtype, id.pointstotagname);
id.intagtype = xtr.GetAttribute("TagType");
id.intagname = xtr.GetAttribute("TagName");
id.intag = Map.Functions.ForMeta.FindByNameAndTagType(id.intagtype, id.intagname);
this.items.Add(id);
}
else if (xtr.Name == "String")
{
String s = new String();
s.description = xtr.GetAttribute("Description");
s.offset = Convert.ToInt32(xtr.GetAttribute("Offset"));
s.name = xtr.GetAttribute("StringName");
s.intagtype = xtr.GetAttribute("TagType");
s.intagname = xtr.GetAttribute("TagName");
s.intag = Map.Functions.ForMeta.FindByNameAndTagType(s.intagtype, s.intagname);
this.items.Add(s);
}
break;
default:
break;
}
}
xtr.Close();
//
///check for raw
this.rawType = Map.Functions.ForMeta.CheckForRaw(this.type);
if (this.rawType != RawDataContainerType.Empty)
{
this.raw = new RawDataContainer();
this.raw = this.raw.LoadRawFromFile(inputFileName, this);
}
}
/// <summary> /// The build map from info file. /// </summary> /// <param name="inputFile">The input file.</param> /// <param name="layout">The layout.</param> /// <param name="map">The map.</param> /// <param name="addsounds">The addsounds.</param> /// <remarks></remarks> public void BuildMapFromInfoFile(string inputFile, ref MapLayout layout, Map map, bool addsounds) { ArrayList metas = new ArrayList(0); string[] split = inputFile.Split('.'); if (split[split.Length - 1] == "info") { FileStream FS = new FileStream(inputFile, FileMode.Open); StreamReader SR = new StreamReader(FS); string temps = string.Empty; do { temps = SR.ReadLine(); if (temps == null) { break; } Meta m = new Meta(map); m.LoadMetaFromFile(temps); if (addsounds == false) { if (m.type == "snd!") { continue; } } bool exists = false; for (int x = 0; x < map.IndexHeader.metaCount; x++) { if (map.FileNames.Name[x] == m.name && map.MetaInfo.TagType[x] == m.type) { exists = true; break; } } if (exists == false) { for (int x = 0; x < metas.Count; x++) { if (((Meta)metas[x]).name == m.name && ((Meta)metas[x]).type == m.type) { exists = true; break; } } } if (exists == false) { metas.Add(m); } } while (temps != null); SR.Close(); FS.Close(); } else { Meta m = new Meta(map); m.LoadMetaFromFile(inputFile); bool exists = false; for (int x = 0; x < map.IndexHeader.metaCount; x++) { if (map.FileNames.Name[x] == m.name && map.MetaInfo.TagType[x] == m.type) { exists = true; break; } } if (exists == false) { metas.Add(m); } } MapBuilder(metas, ref layout, map, addsounds); }