Mercurial > repos > IBDev-IBBoard.WarFoundry.API
annotate API/Factories/AbstractNativeWarFoundryFactory.cs @ 443:86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
* Add "is dot-file" check to behave like Linux and Mac and ignore files with name ".something"
Also:
* Fix load failure message argument order
* Save some regex checks by making sure zip entry is a file first
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 04 Dec 2011 20:40:31 +0000 |
parents | 2a36ebb7b6a9 |
children | cbeee87dc2d3 |
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 |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
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 |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
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 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
39 try |
416
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); |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
42 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
43 catch (ZipException) |
416
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 |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
46 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
47 catch (IOException) |
416
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 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
150 if (IsDotFile(entry)) |
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 continue; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
153 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
154 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
155 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
|
156 { |
443
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
157 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
|
158 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
159 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
160 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
161 return armies; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
162 } |
443
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 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
|
165 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 } |
337
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 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
|
172 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
|
173 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
174 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
|
175 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
176 ICollection<ZipEntry> dataStreams = GetRaceZipEntries(file); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
177 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
|
178 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
179 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
|
180 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
181 if (IsDotFile(entry)) |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
182 { |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
183 continue; |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
184 } |
86725e88052e
Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents:
417
diff
changeset
|
185 |
337
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
186 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
|
187 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
188 races.Add(CreateRaceFromStream(file, dataStream)); |
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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
192 return races; |
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 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
195 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
|
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); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
220 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
|
221 |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
222 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
|
223 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
224 if (o == this) |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
225 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
226 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
227 } |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
228 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
|
229 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
230 return false; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
231 } |
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 return true; |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
234 } |
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 public override int GetHashCode () |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
237 { |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
238 return GetType().FullName.GetHashCode(); |
3c4a6403a88c
* Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
239 } |
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 } |