Mercurial > repos > snowblizz-super-API-ideas
changeset 322:3e9b0603afad
Re #338: WarFoundry.API - Save System Data
* Alter visibility in GameSystem saver to allow for re-use of code
* Add encoding to XML
* Make use of GameSystem saver within FileSaver
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 09 Mar 2011 20:32:08 +0000 |
parents | 2ba88d5fb881 |
children | 8a64b36d36b8 |
files | api/Savers/Xml/WarFoundryXmlFileSaver.cs api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs |
diffstat | 2 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Savers/Xml/WarFoundryXmlFileSaver.cs Sat Mar 05 20:08:41 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlFileSaver.cs Wed Mar 09 20:32:08 2011 +0000 @@ -3,6 +3,8 @@ using IBBoard.WarFoundry.API.Objects; using ICSharpCode.SharpZipLib.Zip; using System.IO; +using IBBoard.IO; +using IBBoard.Lang; namespace IBBoard.WarFoundry.API.Savers.Xml { @@ -32,7 +34,26 @@ { ZipEntry entry = new ZipEntry(GetZipEntryName(obj)); zipStream.PutNextEntry(entry); + byte[] bytes = GetObjectBytes(obj); + zipStream.Write(bytes, 0, bytes.Length); } + + public byte[] GetObjectBytes (WarFoundryLoadedObject obj) + { + string xmlString = ""; + + if (obj is GameSystem) + { + xmlString = GetGameSystemString((GameSystem)obj); + } + + return StringManipulation.StringToBytes(xmlString); + } + + public string GetGameSystemString (GameSystem obj) + { + return new WarFoundryXmlGameSystemSaver().CreateXmlString(obj); + } private string GetZipEntryName(WarFoundryLoadedObject obj) {
--- a/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 05 20:08:41 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Wed Mar 09 20:32:08 2011 +0000 @@ -50,7 +50,7 @@ return success; } - private string CreateXmlString(WarFoundryObject toSave) + public string CreateXmlString(WarFoundryObject toSave) { string xmlString = ""; @@ -65,7 +65,7 @@ private string CreateGameSystemXmlString(GameSystem toSave) { XmlDocument doc = new XmlDocument(); - XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", null, null); + XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(declaration); XmlSchema schema = new XmlSchema(); schema.Namespaces.Add("", "http://ibboard.co.uk/warfoundry/system");