annotate api/Factories/AbstractNativeWarFoundryFactory.cs @ 151:1d13820b3d96

Fixes #176: Bug when saving recently edited army * Add loaded file cleanup to AbstractWarFoundryFactory * Add override of method with Zip reference closing to WarFoundryXmlFactory WarFoundry now no longer ends up with trailing handles to files, although why they only caused problems in some situations is unknown Also: * Some line ending fixes (curse cross-platform development and different line terminators!)
author IBBoard <dev@ibboard.co.uk>
date Sat, 26 Sep 2009 18:48:36 +0000
parents b36cc4af435b
children 70ba3bee0c2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
1 // This file (AbstractNativeWarFoundryFactory.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
104
2f3cafb69799 Re #121: Migrate to AGPL license
IBBoard <dev@ibboard.co.uk>
parents: 82
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
6 using System.IO;
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using System.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using System.Xml.Schema;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.Collections.Generic;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using System.Text;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using IBBoard;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using IBBoard.IO;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 using IBBoard.Lang;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 using IBBoard.Logging;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 using IBBoard.Xml;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 using IBBoard.WarFoundry.API.Objects;
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
17 using ICSharpCode.SharpZipLib.Zip;
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
18
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
19 namespace IBBoard.WarFoundry.API.Factories
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
20 {
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
21 /// <summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
22 /// Base abstract class for all factories that load native WarFoundry data.
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
23 /// </summary>
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
24 public abstract class AbstractNativeWarFoundryFactory : AbstractWarFoundryFactory<ZipFile>, INativeWarFoundryFactory
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 {
115
d0c60b3204c1 Re #53: Add XML army saving
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
26 public static readonly string SYSTEM_ZIP_IDENTIFIER = "WarFoundry_System";
d0c60b3204c1 Re #53: Add XML army saving
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
27 public static readonly string RACE_ZIP_IDENTIFIER = "WarFoundry_Race";
d0c60b3204c1 Re #53: Add XML army saving
IBBoard <dev@ibboard.co.uk>
parents: 104
diff changeset
28 public static readonly string ARMY_ZIP_IDENTIFIER = "WarFoundry_Army";
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
30 protected AbstractNativeWarFoundryFactory()
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 {
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
32 //Do nothing - just make the constructor non-public
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 }
8
613bc5eaac59 Re #9 - Make WarFoundry loading granular
IBBoard <dev@ibboard.co.uk>
parents: 7
diff changeset
34
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 protected override ZipFile GetFileAsSupportedType (FileInfo file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 ZipFile zip = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 zip = new ZipFile(file.FullName);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 }
7
895c8a2378a1 Code cleanup - remove warning about unused exception
IBBoard <dev@ibboard.co.uk>
parents: 0
diff changeset
43 catch(ZipException)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 {
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
45 //Silently dispose as per spec for the method
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }
27
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
47 catch (IOException)
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
48 {
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
49 //Silently dispose as per spec for the method
e7de5c96f5c2 Re #44 - Fix API tests
IBBoard <dev@ibboard.co.uk>
parents: 15
diff changeset
50 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 return zip;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 protected override bool CheckCanHandleFileFormat (ZipFile file)
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
56 {
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
57 return CheckCanHandleFileAsGameSystem(file) || CheckCanHandleFileAsRace(file) || CheckCanHandleFileAsArmy(file);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
60 protected override bool CheckCanHandleFileAsGameSystem(ZipFile file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 return file.ZipFileComment.StartsWith(SYSTEM_ZIP_IDENTIFIER) && CheckCanFindSystemFileContent(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 protected abstract bool CheckCanFindSystemFileContent(ZipFile file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
67 protected override bool CheckCanHandleFileAsRace(ZipFile file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 return file.ZipFileComment.StartsWith(RACE_ZIP_IDENTIFIER) && CheckCanFindRaceFileContent(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 protected abstract bool CheckCanFindRaceFileContent(ZipFile file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73
14
0770e5cbba7c Closes #21 - File loading in order
IBBoard <dev@ibboard.co.uk>
parents: 8
diff changeset
74 protected override bool CheckCanHandleFileAsArmy(ZipFile file)
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 return file.ZipFileComment.StartsWith(ARMY_ZIP_IDENTIFIER) && CheckCanFindArmyFileContent(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 protected abstract bool CheckCanFindArmyFileContent(ZipFile file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 ICollection<IWarFoundryObject> objects = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 string comment = file.ZipFileComment;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 IWarFoundryObject obj = null;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 if (comment.StartsWith(SYSTEM_ZIP_IDENTIFIER))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 obj = CreateGameSystemFromFile(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 else if (comment.StartsWith(RACE_ZIP_IDENTIFIER))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 obj = CreateRaceFromFile(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 else if (comment.StartsWith(ARMY_ZIP_IDENTIFIER))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 obj = CreateArmyFromFile(file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 if (obj!=null)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 objects = new List<IWarFoundryObject>();
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 objects.Add(obj);
151
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
104 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
105
150
b36cc4af435b Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 148
diff changeset
106 file.Close();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 return objects;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 protected Army CreateArmyFromFile(ZipFile file)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 {
151
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
113 Stream dataStream = GetArmyDataStream(file);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
114
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
115 try
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
116 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
117 return CreateArmyFromStream(file, dataStream);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
118 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
119 catch (InvalidFileException ex)
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
120 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
121 throw new InvalidFileException("Data file " + file.Name + " was not a valid army file", ex);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
122 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
123 finally
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
124 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
125 dataStream.Close();
148
8e636443aa8e Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 115
diff changeset
126 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 protected abstract Stream GetArmyDataStream(ZipFile file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 protected Race CreateRaceFromFile(ZipFile file)
151
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
133 {
148
8e636443aa8e Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 115
diff changeset
134 Stream dataStream = GetRaceDataStream(file);
8e636443aa8e Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 115
diff changeset
135
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
136 try
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
137 {
148
8e636443aa8e Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 115
diff changeset
138 return CreateRaceFromStream(file, dataStream);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140 catch (InvalidFileException ex)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
141 {
151
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
142 throw new InvalidFileException("Data file "+file.Name+" was not a valid race file", ex);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
143 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
144 finally
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
145 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
146 dataStream.Close();
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
148 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 protected abstract Stream GetRaceDataStream(ZipFile file);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 protected abstract Race CreateRaceFromStream(ZipFile file, Stream dataStream);
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 protected GameSystem CreateGameSystemFromFile(ZipFile file)
151
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
154 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
155 Stream dataStream = GetGameSystemDataStream(file);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
156
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
157 try
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
158 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
159 return CreateGameSystemFromStream(file, dataStream);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
160 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
161 catch (InvalidFileException ex)
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
162 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
163 throw new InvalidFileException("Data file " + file.Name + " was not a valid game system file", ex);
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
164 }
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
165 finally
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
166 {
1d13820b3d96 Fixes #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 150
diff changeset
167 dataStream.Close();
148
8e636443aa8e Re #176: Bug when saving recently edited army
IBBoard <dev@ibboard.co.uk>
parents: 115
diff changeset
168 }
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 protected abstract Stream GetGameSystemDataStream(ZipFile file);
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
172 protected abstract GameSystem CreateGameSystemFromStream(ZipFile file, Stream dataStream);
0
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174 public override bool Equals (object o)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
176 if (o == this)
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
177 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 return true;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
179 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 else if (o == null || !(this.GetType().Equals(o.GetType())))
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
182 return false;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
183 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 return true;
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 }
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
188 public override int GetHashCode ()
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 {
520818033bb6 Initial commit of WarFoundry code
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 return GetType().FullName.GetHashCode();
82
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
191 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
192 }
3ea0ab04352b * Fix line terminators
IBBoard <dev@ibboard.co.uk>
parents: 27
diff changeset
193 }