# HG changeset patch # User IBBoard # Date 1299961928 0 # Node ID e0580a009e7586d0d68a12a17f92bc60a3688733 # Parent e09a8d9c95f61e0cf484cae4625b7ae57398e0fe 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 diff -r e09a8d9c95f6 -r e0580a009e75 IBBoard.WarFoundry.API.csproj --- a/IBBoard.WarFoundry.API.csproj Sat Mar 12 20:00:13 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sat Mar 12 20:32:08 2011 +0000 @@ -116,7 +116,6 @@ - @@ -182,8 +181,6 @@ - - diff -r e09a8d9c95f6 -r e0580a009e75 api/Savers/IWarFoundryArmySaver.cs --- a/api/Savers/IWarFoundryArmySaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -// This file (IWarFoundryArmySaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Savers -{ - public interface IWarFoundryArmySaver - { - /// - /// Saves an to a file on disk. - /// - /// - /// The to save - /// - /// - /// The path to save the army to - /// - /// - /// TRUE if saving succedes, else FALSE - /// - bool Save(Army army, string path); - } -} - diff -r e09a8d9c95f6 -r e0580a009e75 api/Savers/IWarFoundryGameSystemSaver.cs --- a/api/Savers/IWarFoundryGameSystemSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -// This file (IWarFoundryGameSystemSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009, 2011 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API.Savers -{ - public interface IWarFoundryGameSystemSaver - { - /// - /// Saves a to a file on disk. - /// - /// - /// The to save - /// - /// - /// The path to save the system to - /// - /// - /// TRUE if saving succedes, else FALSE - /// - bool Save(GameSystem system, string path); - } -} \ No newline at end of file diff -r e09a8d9c95f6 -r e0580a009e75 api/Savers/IWarFoundryRaceSaver.cs --- a/api/Savers/IWarFoundryRaceSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -// This file (IWarFoundryRaceSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard. -// -// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. - -using System; -using IBBoard.WarFoundry.API.Objects; - -namespace IBBoard.WarFoundry.API -{ - public interface IWarFoundryRaceSaver - { - /// - /// Saves an to a file on disk. - /// - /// - /// The to save - /// - /// - /// The path to save the army to - /// - /// - /// TRUE if saving succedes, else FALSE - /// - bool Save(Race race, string path); - } -} - diff -r e09a8d9c95f6 -r e0580a009e75 api/Savers/Xml/WarFoundryXmlArmySaver.cs --- a/api/Savers/Xml/WarFoundryXmlArmySaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlArmySaver.cs Sat Mar 12 20:32:08 2011 +0000 @@ -17,52 +17,9 @@ namespace IBBoard.WarFoundry.API.Savers.Xml { - public class WarFoundryXmlArmySaver : IWarFoundryArmySaver + public class WarFoundryXmlArmySaver { - public const string ARMY_FILE_EXTENSION = ".army"; - - public bool Save(Army toSave, string savePath) - { - bool success = false; - ZipFile file = null; - - if (!savePath.EndsWith(ARMY_FILE_EXTENSION)) - { - savePath = savePath + ARMY_FILE_EXTENSION; - } - - try - { - file = ZipFile.Create(savePath); - file.BeginUpdate(); - file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.armyx"); - file.CommitUpdate(); - success = true; - } - finally - { - if (file != null) - { - file.Close(); - } - } - - return success; - } - - public string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is Army) - { - xmlString = CreateArmyXmlString((Army)toSave); - } - - return xmlString; - } - - private string CreateArmyXmlString(Army toSave) + public string CreateXmlString(Army toSave) { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); diff -r e09a8d9c95f6 -r e0580a009e75 api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs --- a/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 12 20:00:13 2011 +0000 +++ b/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs Sat Mar 12 20:32:08 2011 +0000 @@ -17,52 +17,9 @@ namespace IBBoard.WarFoundry.API.Savers.Xml { - public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver + public class WarFoundryXmlGameSystemSaver { - public const string GAMESYSTEM_FILE_EXTENSION = ".system"; - - public bool Save(GameSystem toSave, string savePath) - { - bool success = false; - ZipFile file = null; - - if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION)) - { - savePath = savePath + GAMESYSTEM_FILE_EXTENSION; - } - - try - { - file = ZipFile.Create(savePath); - file.BeginUpdate(); - file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx"); - file.CommitUpdate(); - success = true; - } - finally - { - if (file != null) - { - file.Close(); - } - } - - return success; - } - - public string CreateXmlString(WarFoundryObject toSave) - { - string xmlString = ""; - - if (toSave is GameSystem) - { - xmlString = CreateGameSystemXmlString((GameSystem)toSave); - } - - return xmlString; - } - - private string CreateGameSystemXmlString(GameSystem toSave) + public string CreateXmlString(GameSystem toSave) { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);