Mercurial > repos > IBBoard.WarFoundry.API
view API/Loading/LoadableObjectSourceDirectory.cs @ 483:4d6c92744254
Re #419: Remove assumptions of a file-based install
* Embed sample files as resources
* Load the sample files as a "hack"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 11 Jul 2012 20:39:34 +0100 |
parents | 1ed2f3ab5e35 |
children |
line wrap: on
line source
// This file (LoadableObjectSourceDirectory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2012 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 System.IO; using System.Collections.Generic; namespace IBBoard.WarFoundry.API.Loading { public class LoadableObjectSourceDirectory : ILoadableObjectSource { private DirectoryInfo dir; public LoadableObjectSourceDirectory(string directory) : this(new DirectoryInfo(directory)) { //Do nothing extra } public LoadableObjectSourceDirectory(DirectoryInfo directory) { dir = directory; } public ICollection<ILoadableObject> GetLoadableObjects() { ICollection<ILoadableObject> loadables; dir.Refresh(); if (dir.Exists) { loadables = GetLoadableObjectsFromDirectory(dir); } else { loadables = new List<ILoadableObject>(); } return loadables; } private ICollection<ILoadableObject> GetLoadableObjectsFromDirectory(DirectoryInfo directory) { List<ILoadableObject> loadables = new List<ILoadableObject>(); foreach (FileInfo file in directory.GetFiles()) { loadables.Add(new LoadableFileObject(file)); } foreach (DirectoryInfo subdir in directory.GetDirectories()) { loadables.AddRange(GetLoadableObjectsFromDirectory(subdir)); } return loadables; } public override bool Equals(object obj) { if (obj == null || !obj.GetType().Equals(GetType())) { return false; } LoadableObjectSourceDirectory other = (LoadableObjectSourceDirectory)obj; return this.dir.FullName.Equals(other.dir.FullName); } public override int GetHashCode() { return dir.FullName.GetHashCode() + 17; } } }