Mercurial > repos > IBBoard.WarFoundry.API
annotate API/Factories/AbstractNativeWarFoundryFactory.cs @ 473:0d032c04210e
Re #359: Add "only contained" attribute to unit types
* Make sure remove handles sub-units as well
Note: warning the user that the unit has sub-units rather than just removing them is left to the UI
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 16 Apr 2012 20:47:14 +0100 |
parents | cbeee87dc2d3 |
children | 1ed2f3ab5e35 |
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 using System; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using System.IO; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using System.Xml; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using System.Xml.Schema; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using System.Collections.Generic; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using System.Text; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 using IBBoard; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 using IBBoard.IO; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 using IBBoard.Lang; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 using IBBoard.Xml; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 using IBBoard.WarFoundry.API.Objects; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 using ICSharpCode.SharpZipLib.Zip; |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
16 using IBBoard.Collections; |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 namespace IBBoard.WarFoundry.API.Factories |
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 /// <summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 /// 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
|
22 /// </summary> |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 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
|
24 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 protected AbstractNativeWarFoundryFactory() |
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 //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
|
28 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
30 protected override ZipFile GetFileAsSupportedType(FileInfo file) |
416
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
31 { |
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
32 ZipFile zip = null; |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
33 string ext = file.Extension.ToLower(); |
416
c70973b65090
Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents:
337
diff
changeset
|
34 |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
35 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
|
36 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
37 try |
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 zip = new ZipFile(file.FullName); |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
40 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
41 catch (ZipException) |
416
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 //Silently dispose as per spec for the method |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
44 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
45 catch (IOException) |
416
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 //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
|
48 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 return zip; |
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 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
53 protected override bool CheckCanHandleFileFormat(ZipFile file) |
337
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 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
|
56 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
57 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
58 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
|
59 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
60 return CheckCanFindSystemFileContent(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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
63 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
|
64 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
65 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
|
66 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
67 return CheckCanFindRaceFileContent(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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
70 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
|
71 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
72 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
|
73 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
74 return CheckCanFindArmyFileContent(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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
77 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
|
78 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
79 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile(ZipFile file) |
337
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 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
|
82 |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
83 if (file != null) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
84 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
85 DoCreateObjectsFromZip(file, objects); |
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 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
88 return objects; |
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 |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
91 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
|
92 { |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
93 try |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
94 { |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
95 CreateSystemObjectsFromZip(file, objects); |
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
96 CreateRaceObjectsFromZip(file, objects); |
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
97 CreateArmyObjectsFromZip(file, objects); |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
98 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
99 finally |
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 file.Close(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
102 } |
417
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
103 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
104 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
105 private void CreateSystemObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) |
417
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 if (CheckCanFindSystemFileContent(file)) |
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 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
|
110 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
111 OnGameSystemLoaded(system); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
112 objects.Add(system); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
113 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
114 } |
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 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
117 void CreateRaceObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) |
417
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 if (CheckCanFindRaceFileContent(file)) |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
120 { |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
121 foreach (Race race in CreateRacesFromFile(file)) |
417
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 OnRaceLoaded(race); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
124 objects.Add(race); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
125 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
126 } |
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 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
129 void CreateArmyObjectsFromZip(ZipFile file, ICollection<IWarFoundryObject> objects) |
417
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 if (CheckCanFindArmyFileContent(file)) |
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 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
|
134 { |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
135 OnArmyLoaded(army); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
136 objects.Add(army); |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
137 } |
2a36ebb7b6a9
Re #358: Handle factory.CreateObjectsFromFile where GetFileAsSupportedType returns null
IBBoard <dev@ibboard.co.uk>
parents:
416
diff
changeset
|
138 } |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
139 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
140 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
141 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
|
142 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
143 ICollection<ZipEntry> dataStreams = GetArmyZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
144 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
|
145 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
146 foreach (ZipEntry entry in dataStreams) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
147 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
148 if (IsDotFile(entry)) |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
149 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
150 continue; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
151 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
152 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
153 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
|
154 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
155 armies.Add(CreateArmyFromStream(file, dataStream)); |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
156 } |
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 return armies; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
160 } |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
161 |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
162 private bool IsDotFile(ZipEntry entry) |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
163 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
164 string name = entry.Name; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
165 int slashIdx = name.LastIndexOf('/'); |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
166 return (slashIdx != -1 && slashIdx == name.LastIndexOf("/.")) || (name.Length > 0 && name[0] == '.'); |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
167 } |
337
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 protected abstract ICollection<ZipEntry> GetArmyZipEntries(ZipFile file); |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
170 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
171 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
|
172 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
173 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
|
174 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
175 ICollection<ZipEntry> dataStreams = GetRaceZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
176 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
|
177 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
178 foreach (ZipEntry entry in dataStreams) |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
179 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
180 if (IsDotFile(entry)) |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
181 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
182 continue; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
183 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
184 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
185 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
|
186 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
187 races.Add(CreateRaceFromStream(file, dataStream)); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
188 } |
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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
191 return races; |
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 protected abstract ICollection<ZipEntry> GetRaceZipEntries(ZipFile file); |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
195 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
196 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
|
197 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
198 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
|
199 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
200 ICollection<ZipEntry> dataStreams = GetGameSystemZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
201 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
|
202 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
203 foreach (ZipEntry entry in dataStreams) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
204 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
205 if (IsDotFile(entry)) |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
206 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
207 continue; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
208 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
209 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
210 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
|
211 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
212 systems.Add(CreateGameSystemFromStream(file, dataStream)); |
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 } |
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 systems; |
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 protected abstract ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file); |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
220 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
221 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
|
222 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
223 public override bool Equals(object o) |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
224 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
225 if (o == this) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
226 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
227 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
228 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
229 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
|
230 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
231 return false; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
232 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
233 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
234 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
235 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
236 |
463
cbeee87dc2d3
Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents:
443
diff
changeset
|
237 public override int GetHashCode() |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
238 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
239 return GetType().FullName.GetHashCode(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
240 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
241 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
242 } |