annotate api/Factories/AbstractNonNativeFileExtensionWarFoundryFactory.cs @ 313:f00a57369aaa

Re #253: Allow multiple data files in a single zip * Add event-based mechanism to allow GameSystem to be registered before Race is loaded from a single zip
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Feb 2011 15:54:13 +0000
parents 2f3cafb69799
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
1 // This file (AbstractNonNativeFileExtensionWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 20
diff changeset
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.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.IO;
20
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
8 using IBBoard.Logging;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API.Objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Factories
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 public abstract class AbstractNonNativeFileExtensionWarFoundryFactory : AbstractNonNativeWarFoundryFactory<FileInfo>
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 protected abstract string ArmyFileExtension { get; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 protected abstract string RaceFileExtension { get; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 protected abstract string GameSystemFileExtension { get; }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 protected override bool CheckCanHandleFileFormat (FileInfo file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
21 return CheckCanHandleFileAsArmy(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsGameSystem(file);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
24 protected override bool CheckCanHandleFileAsArmy(FileInfo file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 return ArmyFileExtension!=null && file.Name.ToLower().EndsWith(ArmyFileExtension);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
29 protected override bool CheckCanHandleFileAsRace(FileInfo file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 return RaceFileExtension!=null && file.Name.ToLower().EndsWith(RaceFileExtension);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
34 protected override bool CheckCanHandleFileAsGameSystem(FileInfo file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 return GameSystemFileExtension!=null && file.Name.ToLower().EndsWith(GameSystemFileExtension);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 protected override FileInfo GetFileAsSupportedType (FileInfo file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 return file;
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
42 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 protected abstract Army CreateArmyFromFile(FileInfo file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 protected abstract Race CreateRaceFromFile(FileInfo file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 protected abstract GameSystem CreateGameSystemFromFile(FileInfo file);
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
47
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
48 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (FileInfo file)
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
49 {
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
50 IWarFoundryObject obj = null;
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
51
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
52 if (CheckCanHandleFileAsGameSystem(file))
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
53 {
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
54 GameSystem gameSystem = CreateGameSystemFromFile (file);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
55 OnGameSystemLoaded(gameSystem);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
56 obj = gameSystem;
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
57 }
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
58 else if (CheckCanHandleFileAsRace(file))
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
59 {
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
60 Race race = CreateRaceFromFile (file);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
61 OnRaceLoaded(race);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
62 obj = race;
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
63 }
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
64 else if (CheckCanHandleFileAsArmy(file))
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
65 {
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
66 Army army = CreateArmyFromFile (file);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
67 OnArmyLoaded(army);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
68 obj = army;
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
69 }
20
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
70 else
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
71 {
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
72 LogNotifier.Warn(GetType(), "Failed trying to create from "+file.FullName+" - not a Race, Army or GameSystem");
b7c93a5821cd * Remove unnecessary project dependency
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
73 }
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
74
313
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
75 ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>();
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
76
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
77 if (obj != null)
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
78 {
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
79 objects.Add(obj);
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
80 }
f00a57369aaa Re #253: Allow multiple data files in a single zip
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
81
18
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
82 return objects;
3c228f093a71 Re #16 - Complete Rollcall file loading
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
83 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 }