annotate API/Factories/AbstractNativeWarFoundryFactory.cs @ 483:4d6c92744254

Re #419: Remove assumptions of a file-based install * Embed sample files as resources * Load the sample files as a "hack"
author IBBoard <dev@ibboard.co.uk>
date Wed, 11 Jul 2012 20:39:34 +0100
parents 1ed2f3ab5e35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
482
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
17 using IBBoard.WarFoundry.API.Loading;
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 namespace IBBoard.WarFoundry.API.Factories
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 /// <summary>
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 /// 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
23 /// </summary>
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 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
25 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 protected AbstractNativeWarFoundryFactory()
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 //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
29 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
482
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
31 protected override ZipFile GetFileAsSupportedType(ILoadableObject file)
416
c70973b65090 Fixes #94: Loading files is too slow
IBBoard <dev@ibboard.co.uk>
parents: 337
diff changeset
32 {
482
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
33 ZipFile zip = null;
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
34 string name = file.Name;
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
35 string ext = file.Name.Substring(name.LastIndexOf('.')).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 {
482
1ed2f3ab5e35 Re #419: Remove assumptions of a file-based install
IBBoard <dev@ibboard.co.uk>
parents: 463
diff changeset
41 zip = new ZipFile(file.GetStream());
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
55 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
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
81 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
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 {
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
97 CreateSystemObjectsFromZip(file, objects);
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
98 CreateRaceObjectsFromZip(file, objects);
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
107 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
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
119 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
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 {
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
123 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
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
131 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
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);
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
172
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 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
174
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 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
176 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 ICollection<ZipEntry> dataStreams = GetRaceZipEntries(file);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 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
179
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 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
181 {
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
182 if (IsDotFile(entry))
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 continue;
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
185 }
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
186
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 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
188 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 races.Add(CreateRaceFromStream(file, dataStream));
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
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 return races;
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
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 protected abstract ICollection<ZipEntry> GetRaceZipEntries(ZipFile file);
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
197
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 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
199
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 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
201 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202 ICollection<ZipEntry> dataStreams = GetGameSystemZipEntries(file);
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 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
204
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
205 foreach (ZipEntry entry in dataStreams)
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 {
443
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
207 if (IsDotFile(entry))
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 continue;
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
210 }
86725e88052e Re #380: WarFoundry chokes on zips written by Mac OS X
IBBoard <dev@ibboard.co.uk>
parents: 417
diff changeset
211
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
212 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
213 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
214 systems.Add(CreateGameSystemFromStream(file, dataStream));
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 }
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 return systems;
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
220
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
221 protected abstract ICollection<ZipEntry> GetGameSystemZipEntries(ZipFile file);
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
222
337
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
223 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
224
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
225 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
226 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 if (o == this)
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 return true;
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 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
232 {
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 return false;
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 return true;
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
463
cbeee87dc2d3 Re #58: Remove LogNotifier from API
IBBoard <dev@ibboard.co.uk>
parents: 443
diff changeset
239 public override int GetHashCode()
337
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 return GetType().FullName.GetHashCode();
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243 }
3c4a6403a88c * Fix capitalisation so that new files are in the namespace
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 }