Mercurial > repos > IBDev-IBBoard.WarFoundry.API
comparison API/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs @ 482:1ed2f3ab5e35
Re #419: Remove assumptions of a file-based install
* Swap API to using new "loadable object" and "loadable object source" wrappers to allow file-based or memory-based loading
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 07 Jul 2012 21:01:32 +0100 |
parents | cbeee87dc2d3 |
children |
comparison
equal
deleted
inserted
replaced
481:81f32062c9fa | 482:1ed2f3ab5e35 |
---|---|
3 // 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 // 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 using System; | 4 using System; |
5 using System.Collections.Generic; | 5 using System.Collections.Generic; |
6 using System.IO; | 6 using System.IO; |
7 using IBBoard.WarFoundry.API.Objects; | 7 using IBBoard.WarFoundry.API.Objects; |
8 using IBBoard.WarFoundry.API.Loading; | |
8 | 9 |
9 namespace IBBoard.WarFoundry.API.Factories | 10 namespace IBBoard.WarFoundry.API.Factories |
10 { | 11 { |
11 public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<FileInfo> | 12 public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<ILoadableObject> |
12 { | 13 { |
13 protected abstract string ArmyFileExtension { get; } | 14 protected abstract string ArmyFileExtension { get; } |
14 | 15 |
15 protected abstract string RaceFileExtension { get; } | 16 protected abstract string RaceFileExtension { get; } |
16 | 17 |
17 protected abstract string GameSystemFileExtension { get; } | 18 protected abstract string GameSystemFileExtension { get; } |
18 | 19 |
19 protected override bool CheckCanHandleFileFormat(FileInfo file) | 20 protected override bool CheckCanHandleFileFormat(ILoadableObject file) |
20 { | 21 { |
21 return CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file); | 22 return CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file); |
22 } | 23 } |
23 | 24 |
24 protected override bool CheckCanHandleFileAsArmy(FileInfo file) | 25 protected override bool CheckCanHandleFileAsArmy(ILoadableObject file) |
25 { | 26 { |
26 return ArmyFileExtension != null && file.Name.ToLower().EndsWith(ArmyFileExtension); | 27 return ArmyFileExtension != null && file.Name.ToLower().EndsWith(ArmyFileExtension); |
27 } | 28 } |
28 | 29 |
29 protected override bool CheckCanHandleFileAsRace(FileInfo file) | 30 protected override bool CheckCanHandleFileAsRace(ILoadableObject file) |
30 { | 31 { |
31 return RaceFileExtension != null && file.Name.ToLower().EndsWith(RaceFileExtension); | 32 return RaceFileExtension != null && file.Name.ToLower().EndsWith(RaceFileExtension); |
32 } | 33 } |
33 | 34 |
34 protected override bool CheckCanHandleFileAsGameSystem(FileInfo file) | 35 protected override bool CheckCanHandleFileAsGameSystem(ILoadableObject file) |
35 { | 36 { |
36 return GameSystemFileExtension != null && file.Name.ToLower().EndsWith(GameSystemFileExtension); | 37 return GameSystemFileExtension != null && file.Name.ToLower().EndsWith(GameSystemFileExtension); |
37 } | 38 } |
38 | 39 |
39 protected override FileInfo GetFileAsSupportedType(FileInfo file) | 40 protected override ILoadableObject GetFileAsSupportedType(ILoadableObject file) |
40 { | 41 { |
41 return file; | 42 return file; |
42 } | 43 } |
43 | 44 |
44 protected abstract Army CreateArmyFromFile(FileInfo file); | 45 protected abstract Army CreateArmyFromFile(ILoadableObject file); |
45 | 46 |
46 protected abstract Race CreateRaceFromFile(FileInfo file); | 47 protected abstract Race CreateRaceFromFile(ILoadableObject file); |
47 | 48 |
48 protected abstract GameSystem CreateGameSystemFromFile(FileInfo file); | 49 protected abstract GameSystem CreateGameSystemFromFile(ILoadableObject file); |
49 | 50 |
50 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(FileInfo file) | 51 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(ILoadableObject file) |
51 { | 52 { |
52 IWarFoundryObject obj = null; | 53 IWarFoundryObject obj = null; |
53 | 54 |
54 if (CheckCanHandleFileAsGameSystem(file)) | 55 if (CheckCanHandleFileAsGameSystem(file)) |
55 { | 56 { |