Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Factories/AbstractNativeWarFoundryFactory.cs @ 426:61fae5cbba02
Re #338: WarFoundry.API - Save System Data
* Fix copy-and-paste errors to pass test
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 28 Oct 2011 20:52:29 +0100 |
parents | 2a36ebb7b6a9 |
children | 86725e88052e |
rev | line source |
---|---|
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
1 // This file (AbstractNativeWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
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. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.IO; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Xml; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Xml.Schema; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using System.Collections.Generic; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using System.Text; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 using IBBoard; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 using IBBoard.IO; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 using IBBoard.Lang; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 using IBBoard.Logging; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 using IBBoard.Xml; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 using IBBoard.WarFoundry.API.Objects; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 using ICSharpCode.SharpZipLib.Zip; |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
18 using IBBoard.Collections; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
20 namespace IBBoard.WarFoundry.API.Factories |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 /// Base abstract class for all factories that load native WarFoundry data. |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 public abstract class AbstractNativeWarFoundryFactory : AbstractWarFoundryFactory<ZipFile>, INativeWarFoundryFactory |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 protected AbstractNativeWarFoundryFactory() |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 //Do nothing - just make the constructor non-public |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 protected override ZipFile GetFileAsSupportedType (FileInfo file) |
416
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
33 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
34 ZipFile zip = null; |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
35 string ext = file.Extension.ToLower(); |
416
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
36 |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
37 if (ext == ".race" || ext == ".army" || ext == ".system") |
416
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
38 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
39 try |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
40 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
41 zip = new ZipFile(file.FullName); |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
42 } |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
43 catch (ZipException) |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
44 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
45 //Silently dispose as per spec for the method |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
46 } |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
47 catch (IOException) |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
48 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
49 //Silently dispose as per spec for the method |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
50 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
52 return zip; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
53 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
54 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
55 protected override bool CheckCanHandleFileFormat (ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
56 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 return CheckCanHandleFileAsGameSystem(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsArmy(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
59 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 protected override bool CheckCanHandleFileAsGameSystem(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
61 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
62 return CheckCanFindSystemFileContent(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
64 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 protected abstract bool CheckCanFindSystemFileContent(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
66 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 protected override bool CheckCanHandleFileAsRace(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
68 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
69 return CheckCanFindRaceFileContent(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
71 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 protected abstract bool CheckCanFindRaceFileContent(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
73 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 protected override bool CheckCanHandleFileAsArmy(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
75 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
76 return CheckCanFindArmyFileContent(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
78 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
79 protected abstract bool CheckCanFindArmyFileContent(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
80 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
81 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
82 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
83 ICollection<IWarFoundryObject> objects = new List<IWarFoundryObject>(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
84 |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
85 if (file != null) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
86 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
87 DoCreateObjectsFromZip(file, objects); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
88 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
89 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
90 return objects; |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
91 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
92 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
93 private void DoCreateObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
94 { |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
95 try |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
96 { |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
97 CreateSystemObjectsFromZip (file, objects); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
98 CreateRaceObjectsFromZip (file, objects); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
99 CreateArmyObjectsFromZip (file, objects); |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
100 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
101 finally |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
103 file.Close(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
104 } |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
105 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
106 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
107 private void CreateSystemObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
108 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
109 if (CheckCanFindSystemFileContent(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
110 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
111 foreach (GameSystem system in CreateGameSystemsFromFile(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
112 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
113 OnGameSystemLoaded(system); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
114 objects.Add(system); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
115 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
116 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
117 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
118 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
119 void CreateRaceObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
120 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
121 if (CheckCanFindRaceFileContent(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
122 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
123 foreach(Race race in CreateRacesFromFile(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
124 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
125 OnRaceLoaded(race); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
126 objects.Add(race); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
127 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
128 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
129 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
130 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
131 void CreateArmyObjectsFromZip (ZipFile file, ICollection<IWarFoundryObject> objects) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
132 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
133 if (CheckCanFindArmyFileContent(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
134 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
135 foreach (Army army in CreateArmiesFromFile(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
136 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
137 OnArmyLoaded(army); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
138 objects.Add(army); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
139 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
140 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
141 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
142 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
143 protected ICollection<Army> CreateArmiesFromFile(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
144 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
145 ICollection<ZipEntry> dataStreams = GetArmyZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
146 ICollection<Army> armies = new List<Army>(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
147 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
148 foreach (ZipEntry entry in dataStreams) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
149 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
150 using (Stream dataStream = file.GetInputStream(entry)) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
151 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
152 armies.Add(CreateArmyFromStream(file, dataStream)); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
153 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
154 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
155 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
156 return armies; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
157 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
158 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
159 protected abstract ICollection<ZipEntry> GetArmyZipEntries(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
160 protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
161 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
162 protected ICollection<Race> CreateRacesFromFile(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
163 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
164 ICollection<ZipEntry> dataStreams = GetRaceZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
165 ICollection<Race> races = new List<Race>(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
166 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
167 foreach (ZipEntry entry in dataStreams) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
168 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
169 using (Stream dataStream = file.GetInputStream(entry)) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
170 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
171 races.Add(CreateRaceFromStream(file, dataStream)); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
172 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
173 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
174 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
175 return races; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
176 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
177 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
178 protected abstract ICollection<ZipEntry> GetRaceZipEntries(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
179 protected abstract Race CreateRaceFromStream(ZipFile file, Stream dataStream); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
180 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
181 protected ICollection<GameSystem> CreateGameSystemsFromFile(ZipFile file) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
182 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
183 ICollection<ZipEntry> dataStreams = GetGameSystemZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
184 ICollection<GameSystem> systems = new List<GameSystem>(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
185 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
186 foreach (ZipEntry entry in dataStreams) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
187 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
188 using (Stream dataStream = file.GetInputStream(entry)) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
189 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
190 systems.Add(CreateGameSystemFromStream(file, dataStream)); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
191 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
192 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
193 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
194 return systems; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
195 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
196 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
197 protected abstract ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
198 protected abstract GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
199 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
200 public override bool Equals (object o) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
201 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
202 if (o == this) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
203 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
204 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
205 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
206 else if (o == null || !(this.GetType().Equals(o.GetType()))) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
207 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
208 return false; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
209 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
210 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
211 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
212 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
213 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
214 public override int GetHashCode () |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
215 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
216 return GetType().FullName.GetHashCode(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
217 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
218 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
219 } |