Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison api/Savers/Xml/WarFoundryXmlGameSystemSaver.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 | 3e9b0603afad |
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 WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver | 20 public class WarFoundryXmlGameSystemSaver |
21 { | 21 { |
22 public const string GAMESYSTEM_FILE_EXTENSION = ".system"; | 22 public string CreateXmlString(GameSystem toSave) |
23 | |
24 public bool Save(GameSystem toSave, string savePath) | |
25 { | |
26 bool success = false; | |
27 ZipFile file = null; | |
28 | |
29 if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION)) | |
30 { | |
31 savePath = savePath + GAMESYSTEM_FILE_EXTENSION; | |
32 } | |
33 | |
34 try | |
35 { | |
36 file = ZipFile.Create(savePath); | |
37 file.BeginUpdate(); | |
38 file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx"); | |
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 GameSystem) | |
58 { | |
59 xmlString = CreateGameSystemXmlString((GameSystem)toSave); | |
60 } | |
61 | |
62 return xmlString; | |
63 } | |
64 | |
65 private string CreateGameSystemXmlString(GameSystem 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(); |