I have a problem. I am making a plugin that let's you convert normal maps into lava maps.
And for that, you must insert a piece of XML code in maps.txt.
I am doing that with streamwriter and reader, because that allows you more options(custom code).
The code must be inserted after <Maps> in maps.txt.
But the string(the code) doesn't insert it after that. It even doesn't insert!
Here is the code:
- Code: Select all
public void saveToXML()
{
string path = string.Format(@"{0}\lava\maps.txt", Application.StartupPath);
string all;
string indx = "<Maps>"; // <-- that thing is the start of the XML code, after that it must be inserted.
string finalXmlCode;
//generate the code
string XmlCode = System.Environment.NewLine + " <Map name=\"" + levelName + "\" phase1=\"0\" phase2=\"0\" author=\"" + textBoxAuthor.Text + "\">" + System.Environment.NewLine
+ " <Source block=\"" + textBoxStartingBlock + "\" x=\"" + textBox_x + "\" y=\"" + textBox_y + "\" z=\"" + textBox_z + "\" type=\"" + textBoxType + "\" delay=\"0\" />" + System.Environment.NewLine
+ " </Map>";
if (customCode)
{
finalXmlCode = XmlCode + System.Environment.NewLine + textBoxCustomCode;
}
else
{
finalXmlCode = XmlCode;
}
//read the thing, and set all.
using (StreamReader read = new StreamReader(path))
{
all = read.ReadToEnd();
}
//here goes the magic wrong: it doesn't get inserted in the maps.txt
int indxOf = all.IndexOf(indx);
all.Insert(indxOf + indx.Length, finalXmlCode);
//writing stuff
using (StreamWriter write = new StreamWriter(path))
{
write.Write(all);
}
}
Please don't use this to make your own lava map converter and publish it before I made my converter.
Thanks for the help!