changeset 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 e09a8d9c95f6
children 331995582990
files IBBoard.WarFoundry.API.csproj api/Savers/IWarFoundryArmySaver.cs api/Savers/IWarFoundryGameSystemSaver.cs api/Savers/IWarFoundryRaceSaver.cs api/Savers/Xml/WarFoundryXmlArmySaver.cs api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs
diffstat 6 files changed, 4 insertions(+), 173 deletions(-) [+]
line diff
     1.1 --- a/IBBoard.WarFoundry.API.csproj	Sat Mar 12 20:00:13 2011 +0000
     1.2 +++ b/IBBoard.WarFoundry.API.csproj	Sat Mar 12 20:32:08 2011 +0000
     1.3 @@ -116,7 +116,6 @@
     1.4      <Compile Include="api\Requirements\UnitRequirementMinNumber.cs" />
     1.5      <Compile Include="api\Requirements\UnitRequiresAtLeastRequirement.cs" />
     1.6      <Compile Include="api\Savers\IWarFoundryFileSaver.cs" />
     1.7 -    <Compile Include="api\Savers\IWarFoundryGameSystemSaver.cs" />
     1.8      <Compile Include="api\Savers\WarFoundrySaver.cs" />
     1.9      <Compile Include="api\Util\UnitEquipmentUtil.cs" />
    1.10      <Compile Include="api\WarFoundryCore.cs" />
    1.11 @@ -182,8 +181,6 @@
    1.12      <Compile Include="api\Objects\UnitMemberType.cs" />
    1.13      <Compile Include="api\Factories\Xml\WarFoundryXmlLimitParser.cs" />
    1.14      <Compile Include="api\Factories\DummyWarFoundryFactory.cs" />
    1.15 -    <Compile Include="api\Savers\IWarFoundryArmySaver.cs" />
    1.16 -    <Compile Include="api\Savers\IWarFoundryRaceSaver.cs" />
    1.17      <Compile Include="api\Objects\WarFoundryLoadedObject.cs" />
    1.18      <Compile Include="api\Savers\Xml\WarFoundryXmlArmySaver.cs" />
    1.19      <Compile Include="api\Savers\Xml\WarFoundryXmlGameSystemSaver.cs" />
     2.1 --- a/api/Savers/IWarFoundryArmySaver.cs	Sat Mar 12 20:00:13 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,27 +0,0 @@
     2.4 -// This file (IWarFoundryArmySaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard.
     2.5 -//
     2.6 -// 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.
     2.7 -
     2.8 -using System;
     2.9 -using IBBoard.WarFoundry.API.Objects;
    2.10 -
    2.11 -namespace IBBoard.WarFoundry.API.Savers
    2.12 -{
    2.13 -	public interface IWarFoundryArmySaver
    2.14 -	{
    2.15 -		/// <summary>
    2.16 -		/// Saves an <see cref="Army"/> to a file on disk.
    2.17 -		/// </summary>
    2.18 -		/// <param name="army">
    2.19 -		/// The <see cref="Army"/> to save
    2.20 -		/// </param>
    2.21 -		/// <param name="path">
    2.22 -		/// The path to save the army to
    2.23 -		/// </param>
    2.24 -		/// <returns>
    2.25 -		/// TRUE if saving succedes, else FALSE
    2.26 -		/// </returns>
    2.27 -		bool Save(Army army, string path);
    2.28 -	}
    2.29 -}
    2.30 -
     3.1 --- a/api/Savers/IWarFoundryGameSystemSaver.cs	Sat Mar 12 20:00:13 2011 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,26 +0,0 @@
     3.4 -// This file (IWarFoundryGameSystemSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2008, 2009, 2011 IBBoard.
     3.5 -//
     3.6 -// 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.
     3.7 -
     3.8 -using System;
     3.9 -using IBBoard.WarFoundry.API.Objects;
    3.10 -
    3.11 -namespace IBBoard.WarFoundry.API.Savers
    3.12 -{
    3.13 -	public interface IWarFoundryGameSystemSaver
    3.14 -	{
    3.15 -		/// <summary>
    3.16 -		/// Saves a <see cref="GameSystem"/> to a file on disk.
    3.17 -		/// </summary>
    3.18 -		/// <param name="system">
    3.19 -		/// The <see cref="GameSystem"/> to save
    3.20 -		/// </param>
    3.21 -		/// <param name="path">
    3.22 -		/// The path to save the system to
    3.23 -		/// </param>
    3.24 -		/// <returns>
    3.25 -		/// TRUE if saving succedes, else FALSE
    3.26 -		/// </returns>
    3.27 -		bool Save(GameSystem system, string path);
    3.28 -	}
    3.29 -}
    3.30 \ No newline at end of file
     4.1 --- a/api/Savers/IWarFoundryRaceSaver.cs	Sat Mar 12 20:00:13 2011 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,27 +0,0 @@
     4.4 -// This file (IWarFoundryRaceSaver.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard.
     4.5 -//
     4.6 -// 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.
     4.7 -
     4.8 -using System;
     4.9 -using IBBoard.WarFoundry.API.Objects;
    4.10 -
    4.11 -namespace IBBoard.WarFoundry.API
    4.12 -{
    4.13 -	public interface IWarFoundryRaceSaver
    4.14 -	{
    4.15 -		/// <summary>
    4.16 -		/// Saves an <see cref="Race"/> to a file on disk.
    4.17 -		/// </summary>
    4.18 -		/// <param name="race">
    4.19 -		/// The <see cref="Race"/> to save
    4.20 -		/// </param>
    4.21 -		/// <param name="path">
    4.22 -		/// The path to save the army to
    4.23 -		/// </param>
    4.24 -		/// <returns>
    4.25 -		/// TRUE if saving succedes, else FALSE
    4.26 -		/// </returns>
    4.27 -		bool Save(Race race, string path);
    4.28 -	}
    4.29 -}
    4.30 -
     5.1 --- a/api/Savers/Xml/WarFoundryXmlArmySaver.cs	Sat Mar 12 20:00:13 2011 +0000
     5.2 +++ b/api/Savers/Xml/WarFoundryXmlArmySaver.cs	Sat Mar 12 20:32:08 2011 +0000
     5.3 @@ -17,52 +17,9 @@
     5.4  
     5.5  namespace IBBoard.WarFoundry.API.Savers.Xml
     5.6  {
     5.7 -	public class WarFoundryXmlArmySaver : IWarFoundryArmySaver
     5.8 +	public class WarFoundryXmlArmySaver
     5.9  	{
    5.10 -		public const string ARMY_FILE_EXTENSION = ".army";
    5.11 -		
    5.12 -		public bool Save(Army toSave, string savePath)
    5.13 -		{
    5.14 -			bool success = false;
    5.15 -			ZipFile file = null;
    5.16 -			
    5.17 -			if (!savePath.EndsWith(ARMY_FILE_EXTENSION))
    5.18 -			{
    5.19 -				savePath = savePath + ARMY_FILE_EXTENSION;
    5.20 -			}
    5.21 -
    5.22 -			try
    5.23 -			{
    5.24 -				file = ZipFile.Create(savePath);
    5.25 -				file.BeginUpdate();
    5.26 -				file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.armyx");
    5.27 -				file.CommitUpdate();
    5.28 -				success = true;
    5.29 -			}
    5.30 -			finally
    5.31 -			{
    5.32 -				if (file != null)
    5.33 -				{
    5.34 -					file.Close();
    5.35 -				}
    5.36 -			}
    5.37 -
    5.38 -			return success;
    5.39 -		}
    5.40 -
    5.41 -		public string CreateXmlString(WarFoundryObject toSave)
    5.42 -		{
    5.43 -			string xmlString = "";
    5.44 -
    5.45 -			if (toSave is Army)
    5.46 -			{
    5.47 -				xmlString = CreateArmyXmlString((Army)toSave);
    5.48 -			}
    5.49 -
    5.50 -			return xmlString;
    5.51 -		}
    5.52 -
    5.53 -		private string CreateArmyXmlString(Army toSave)
    5.54 +		public string CreateXmlString(Army toSave)
    5.55  		{
    5.56  			XmlDocument doc = new XmlDocument();
    5.57  			XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
     6.1 --- a/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs	Sat Mar 12 20:00:13 2011 +0000
     6.2 +++ b/api/Savers/Xml/WarFoundryXmlGameSystemSaver.cs	Sat Mar 12 20:32:08 2011 +0000
     6.3 @@ -17,52 +17,9 @@
     6.4  
     6.5  namespace IBBoard.WarFoundry.API.Savers.Xml
     6.6  {
     6.7 -	public class WarFoundryXmlGameSystemSaver : IWarFoundryGameSystemSaver
     6.8 +	public class WarFoundryXmlGameSystemSaver
     6.9  	{
    6.10 -		public const string GAMESYSTEM_FILE_EXTENSION = ".system";
    6.11 -
    6.12 -		public bool Save(GameSystem toSave, string savePath)
    6.13 -		{
    6.14 -			bool success = false;
    6.15 -			ZipFile file = null;
    6.16 -
    6.17 -			if (!savePath.EndsWith(GAMESYSTEM_FILE_EXTENSION))
    6.18 -			{
    6.19 -				savePath = savePath + GAMESYSTEM_FILE_EXTENSION;
    6.20 -			}
    6.21 -
    6.22 -			try
    6.23 -			{
    6.24 -				file = ZipFile.Create(savePath);
    6.25 -				file.BeginUpdate();
    6.26 -				file.Add(new StringZipEntrySource(CreateXmlString(toSave)), "data.systemx");
    6.27 -				file.CommitUpdate();
    6.28 -				success = true;
    6.29 -			}
    6.30 -			finally
    6.31 -			{
    6.32 -				if (file != null)
    6.33 -				{
    6.34 -					file.Close();
    6.35 -				}
    6.36 -			}
    6.37 -
    6.38 -			return success;
    6.39 -		}
    6.40 -
    6.41 -		public string CreateXmlString(WarFoundryObject toSave)
    6.42 -		{
    6.43 -			string xmlString = "";
    6.44 -
    6.45 -			if (toSave is GameSystem)
    6.46 -			{
    6.47 -				xmlString = CreateGameSystemXmlString((GameSystem)toSave);
    6.48 -			}
    6.49 -
    6.50 -			return xmlString;
    6.51 -		}
    6.52 -
    6.53 -		private string CreateGameSystemXmlString(GameSystem toSave)
    6.54 +		public string CreateXmlString(GameSystem toSave)
    6.55  		{
    6.56  			XmlDocument doc = new XmlDocument();
    6.57  			XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);