comparison api/Savers/Xml/WarFoundryXmlFileSaver.cs @ 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
comparison
equal deleted inserted replaced
321:2ba88d5fb881 322:3e9b0603afad
1 using System; 1 using System;
2 using IBBoard.WarFoundry.API.Savers; 2 using IBBoard.WarFoundry.API.Savers;
3 using IBBoard.WarFoundry.API.Objects; 3 using IBBoard.WarFoundry.API.Objects;
4 using ICSharpCode.SharpZipLib.Zip; 4 using ICSharpCode.SharpZipLib.Zip;
5 using System.IO; 5 using System.IO;
6 using IBBoard.IO;
7 using IBBoard.Lang;
6 8
7 namespace IBBoard.WarFoundry.API.Savers.Xml 9 namespace IBBoard.WarFoundry.API.Savers.Xml
8 { 10 {
9 public class WarFoundryXmlFileSaver : IWarFoundryFileSaver 11 public class WarFoundryXmlFileSaver : IWarFoundryFileSaver
10 { 12 {
30 32
31 public void AddFile(ZipOutputStream zipStream, WarFoundryLoadedObject obj) 33 public void AddFile(ZipOutputStream zipStream, WarFoundryLoadedObject obj)
32 { 34 {
33 ZipEntry entry = new ZipEntry(GetZipEntryName(obj)); 35 ZipEntry entry = new ZipEntry(GetZipEntryName(obj));
34 zipStream.PutNextEntry(entry); 36 zipStream.PutNextEntry(entry);
37 byte[] bytes = GetObjectBytes(obj);
38 zipStream.Write(bytes, 0, bytes.Length);
35 } 39 }
40
41 public byte[] GetObjectBytes (WarFoundryLoadedObject obj)
42 {
43 string xmlString = "";
44
45 if (obj is GameSystem)
46 {
47 xmlString = GetGameSystemString((GameSystem)obj);
48 }
49
50 return StringManipulation.StringToBytes(xmlString);
51 }
52
53 public string GetGameSystemString (GameSystem obj)
54 {
55 return new WarFoundryXmlGameSystemSaver().CreateXmlString(obj);
56 }
36 57
37 private string GetZipEntryName(WarFoundryLoadedObject obj) 58 private string GetZipEntryName(WarFoundryLoadedObject obj)
38 { 59 {
39 return obj.ID + GetFileExtension(obj); 60 return obj.ID + GetFileExtension(obj);
40 } 61 }