diff api/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs @ 0:520818033bb6

Initial commit of WarFoundry code
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 15:57:51 +0000
parents
children 0770e5cbba7c
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/api/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs	Fri Dec 19 15:57:51 2008 +0000
@@ -0,0 +1,64 @@
+// AbstractNonNativeFileExtensionWarFoundryFactory.cs
+//
+//  Copyright (C) 2008 IBBoard
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+//
+//
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Factories
+{	
+	public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<FileInfo>
+	{
+		protected abstract string ArmyFileExtension { get; }
+		protected abstract string RaceFileExtension { get; }
+		protected abstract string GameSystemFileExtension { get; }
+		
+		protected override bool CheckCanHandleFileFormat (FileInfo file)
+		{
+			return IsArmyFile(file) || IsRaceFile(file) || IsSystemFile(file);
+		}
+		
+		protected bool IsArmyFile(FileInfo file)
+		{
+			return ArmyFileExtension!=null && file.Name.ToLower().EndsWith(ArmyFileExtension);
+		}
+		
+		protected bool IsRaceFile(FileInfo file)
+		{
+			return RaceFileExtension!=null && file.Name.ToLower().EndsWith(RaceFileExtension);
+		}
+		
+		protected bool IsSystemFile(FileInfo file)
+		{
+			return GameSystemFileExtension!=null && file.Name.ToLower().EndsWith(GameSystemFileExtension);
+		}
+		
+		protected override FileInfo GetFileAsSupportedType (FileInfo file)
+		{
+			return file;
+		} 
+		
+		
+		protected abstract Army CreateArmyFromFile(FileInfo file);
+		protected abstract Race CreateRaceFromFile(FileInfo file);
+		protected abstract GameSystem CreateGameSystemFromFile(FileInfo file);
+	}
+}