comparison api/Factories/AbstractNativeWarFoundryFactory.cs @ 199:70ba3bee0c2e

Fixes #207: WarFoundry still keeps file handles on failure * Move close of zip file into a "finally" block * Remove unnecessary extra Close()
author IBBoard <dev@ibboard.co.uk>
date Mon, 02 Nov 2009 20:58:01 +0000
parents 1d13820b3d96
children 3e287b6b5244
comparison
equal deleted inserted replaced
198:c4cf4c7db7d5 199:70ba3bee0c2e
81 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (ZipFile file) 81 protected override ICollection<IWarFoundryObject> DoCreateObjectsFromFile (ZipFile file)
82 { 82 {
83 ICollection<IWarFoundryObject> objects = null; 83 ICollection<IWarFoundryObject> objects = null;
84 string comment = file.ZipFileComment; 84 string comment = file.ZipFileComment;
85 IWarFoundryObject obj = null; 85 IWarFoundryObject obj = null;
86 86
87 if (comment.StartsWith(SYSTEM_ZIP_IDENTIFIER)) 87 try
88 { 88 {
89 obj = CreateGameSystemFromFile(file); 89 if (comment.StartsWith(SYSTEM_ZIP_IDENTIFIER))
90 {
91 obj = CreateGameSystemFromFile(file);
92 }
93 else if (comment.StartsWith(RACE_ZIP_IDENTIFIER))
94 {
95 obj = CreateRaceFromFile(file);
96 }
97 else if (comment.StartsWith(ARMY_ZIP_IDENTIFIER))
98 {
99 obj = CreateArmyFromFile(file);
100 }
90 } 101 }
91 else if (comment.StartsWith(RACE_ZIP_IDENTIFIER)) 102 finally
92 { 103 {
93 obj = CreateRaceFromFile(file); 104 file.Close();
94 }
95 else if (comment.StartsWith(ARMY_ZIP_IDENTIFIER))
96 {
97 obj = CreateArmyFromFile(file);
98 } 105 }
99 106
100 if (obj!=null) 107 if (obj!=null)
101 { 108 {
102 objects = new List<IWarFoundryObject>(); 109 objects = new List<IWarFoundryObject>();
103 objects.Add(obj); 110 objects.Add(obj);
104 } 111 }
105
106 file.Close();
107 112
108 return objects; 113 return objects;
109 } 114 }
110 115
111 protected Army CreateArmyFromFile(ZipFile file) 116 protected Army CreateArmyFromFile(ZipFile file)