private void SaveUserDataFile()
{
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
writer.Formatting = Formatting.Indented;
writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + Encoding.Default.WebName + "\"");
writer.WriteComment("DO NOT EDIT THIS FILE. It is automatically generated by the AGS Editor, changing it manually could break your game");
writer.WriteStartElement(XML_USER_DATA_ROOT_NODE_NAME);
writer.WriteAttributeString(XML_ATTRIBUTE_VERSION, LATEST_USER_DATA_VERSION);
writer.WriteAttributeString(XML_ATTRIBUTE_VERSION_INDEX, LATEST_USER_DATA_XML_VERSION_INDEX.ToString());
writer.WriteAttributeString(XML_ATTRIBUTE_EDITOR_VERSION, AGS.Types.Version.AGS_EDITOR_FRIENDLY_VERSION);
Factory.Events.OnSavingUserData(writer);
_game.WorkspaceState.ToXml(writer);
writer.WriteEndElement();
writer.Flush();
try
{
StreamWriter fileOutput = new StreamWriter(USER_DATA_FILE_NAME, false, Encoding.Default);
fileOutput.Write(sw.ToString());
fileOutput.Close();
writer.Close();
}
catch (UnauthorizedAccessException ex)
{
Factory.GUIController.ShowMessage("Unable to write the user data file. Ensure that you have write access to the game folder, and that the file is not already open.\n\n" + ex.Message, MessageBoxIcon.Warning);
}
catch (IOException ex)
{
Factory.GUIController.ShowMessage("Unable to write the user data file. Ensure that you have write access to the game folder, and that the file is not already open.\n\n" + ex.Message, MessageBoxIcon.Warning);
}
}