comparison api/Savers/Xml/WarFoundryXmlArmySaver.cs @ 325:e0580a009e75

Re #324: Add saving of Race and System data to files * Remove extra interfaces, as their replacements would be implementation specific and the break-down is now only a clean coding issue * Strip out extra code from Army and GameSystem saver
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Mar 2011 20:32:08 +0000
parents 8a64b36d36b8
children
comparison
equal deleted inserted replaced
324:e09a8d9c95f6 325:e0580a009e75
15 using IBBoard.WarFoundry.API.Util; 15 using IBBoard.WarFoundry.API.Util;
16 using ICSharpCode.SharpZipLib.Zip; 16 using ICSharpCode.SharpZipLib.Zip;
17 17
18 namespace IBBoard.WarFoundry.API.Savers.Xml 18 namespace IBBoard.WarFoundry.API.Savers.Xml
19 { 19 {
20 public class WarFoundryXmlArmySaver : IWarFoundryArmySaver 20 public class WarFoundryXmlArmySaver
21 { 21 {
22 public const string ARMY_FILE_EXTENSION = ".army"; 22 public string CreateXmlString(Army toSave)
23
24 public bool Save(Army toSave, string savePath)
25 {
26 bool success = false;
27 ZipFile file = null;
28
29 if (!savePath.EndsWith(ARMY_FILE_EXTENSION))
30 {
31 savePath = savePath + ARMY_FILE_EXTENSION;
32 }
33
34 try
35 {
36 file = ZipFile.Create(savePath);
37 file.BeginUpdate();
38 file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.armyx");
39 file.CommitUpdate();
40 success = true;
41 }
42 finally
43 {
44 if (file != null)
45 {
46 file.Close();
47 }
48 }
49
50 return success;
51 }
52
53 public string CreateXmlString(WarFoundryObject toSave)
54 {
55 string xmlString = "";
56
57 if (toSave is Army)
58 {
59 xmlString = CreateArmyXmlString((Army)toSave);
60 }
61
62 return xmlString;
63 }
64
65 private string CreateArmyXmlString(Army toSave)
66 { 23 {
67 XmlDocument doc = new XmlDocument(); 24 XmlDocument doc = new XmlDocument();
68 XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); 25 XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
69 doc.AppendChild(declaration); 26 doc.AppendChild(declaration);
70 XmlSchema schema = new XmlSchema(); 27 XmlSchema schema = new XmlSchema();