view api/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs @ 14:0770e5cbba7c

Closes #21 - File loading in order * Reworked LoadFiles to smaller methods for readability (also re #10) and structure * Now determine expected load return before loading then load all "expected GameSystem" before "expected Race" * Make "can load as race/game system/army" methods public in interface Re #22 - Get errored file loading * Created FileLoadFailure class and made LoadFiles return a list of them Also * Some code cleanup * Change to DictionaryUtils calls
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Jan 2009 14:03:20 +0000
parents 520818033bb6
children 306558904c2a
line wrap: on
line source

// 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 CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file);
		}
		
		protected override bool CheckCanHandleFileAsArmy(FileInfo file)
		{
			return ArmyFileExtension!=null && file.Name.ToLower().EndsWith(ArmyFileExtension);
		}
		
		protected override bool CheckCanHandleFileAsRace(FileInfo file)
		{
			return RaceFileExtension!=null && file.Name.ToLower().EndsWith(RaceFileExtension);
		}
		
		protected override bool CheckCanHandleFileAsGameSystem(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);
	}
}