comparison api/Savers/Xml/WarFoundryXmlFileSaver.cs @ 323:8a64b36d36b8

Re #324: Add saving of Race and System data to files * As per GameSystem changes for using existing code: * Make XML creation method public * Make sure we're encoding in UTF-8 * Implement saving method for Army
author IBBoard <dev@ibboard.co.uk>
date Wed, 09 Mar 2011 20:59:34 +0000
parents 3e9b0603afad
children
comparison
equal deleted inserted replaced
322:3e9b0603afad 323:8a64b36d36b8
36 zipStream.PutNextEntry(entry); 36 zipStream.PutNextEntry(entry);
37 byte[] bytes = GetObjectBytes(obj); 37 byte[] bytes = GetObjectBytes(obj);
38 zipStream.Write(bytes, 0, bytes.Length); 38 zipStream.Write(bytes, 0, bytes.Length);
39 } 39 }
40 40
41 public byte[] GetObjectBytes (WarFoundryLoadedObject obj) 41 public byte[] GetObjectBytes(WarFoundryLoadedObject obj)
42 { 42 {
43 string xmlString = ""; 43 string xmlString = "";
44 44
45 if (obj is GameSystem) 45 if (obj is GameSystem)
46 { 46 {
47 xmlString = GetGameSystemString((GameSystem)obj); 47 xmlString = GetGameSystemString((GameSystem)obj);
48 } 48 }
49 else if (obj is Army)
50 {
51 xmlString = GetArmyString((Army)obj);
52 }
49 53
50 return StringManipulation.StringToBytes(xmlString); 54 return StringManipulation.StringToBytes(xmlString);
51 } 55 }
52 56
53 public string GetGameSystemString (GameSystem obj) 57 public string GetGameSystemString(GameSystem obj)
54 { 58 {
55 return new WarFoundryXmlGameSystemSaver().CreateXmlString(obj); 59 return new WarFoundryXmlGameSystemSaver().CreateXmlString(obj);
56 } 60 }
57 61
62 public string GetArmyString(Army obj)
63 {
64 return new WarFoundryXmlArmySaver().CreateXmlString(obj);
65 }
66
58 private string GetZipEntryName(WarFoundryLoadedObject obj) 67 private string GetZipEntryName(WarFoundryLoadedObject obj)
59 { 68 {
60 return obj.ID + GetFileExtension(obj); 69 return obj.ID + GetFileExtension(obj);
61 } 70 }
62 71
63 public string GetFileExtension (WarFoundryLoadedObject obj) 72 public string GetFileExtension(WarFoundryLoadedObject obj)
64 { 73 {
65 string ext = ""; 74 string ext = "";
66 75
67 if (obj is Army) 76 if (obj is Army)
68 { 77 {