# HG changeset patch # User IBBoard # Date 1257195481 0 # Node ID 70ba3bee0c2e0f661e0017d9a872be1e64df50de # Parent c4cf4c7db7d5d644cb4636a8df8d6355ce8d5d3a Fixes #207: WarFoundry still keeps file handles on failure * Move close of zip file into a "finally" block * Remove unnecessary extra Close() diff -r c4cf4c7db7d5 -r 70ba3bee0c2e api/Factories/AbstractNativeWarFoundryFactory.cs --- a/api/Factories/AbstractNativeWarFoundryFactory.cs Sat Oct 31 20:55:19 2009 +0000 +++ b/api/Factories/AbstractNativeWarFoundryFactory.cs Mon Nov 02 20:58:01 2009 +0000 @@ -82,19 +82,26 @@ { ICollection objects = null; string comment = file.ZipFileComment; - IWarFoundryObject obj = null; - - if (comment.StartsWith(SYSTEM_ZIP_IDENTIFIER)) - { - obj = CreateGameSystemFromFile(file); - } - else if (comment.StartsWith(RACE_ZIP_IDENTIFIER)) - { - obj = CreateRaceFromFile(file); - } - else if (comment.StartsWith(ARMY_ZIP_IDENTIFIER)) - { - obj = CreateArmyFromFile(file); + IWarFoundryObject obj = null; + + try + { + if (comment.StartsWith(SYSTEM_ZIP_IDENTIFIER)) + { + obj = CreateGameSystemFromFile(file); + } + else if (comment.StartsWith(RACE_ZIP_IDENTIFIER)) + { + obj = CreateRaceFromFile(file); + } + else if (comment.StartsWith(ARMY_ZIP_IDENTIFIER)) + { + obj = CreateArmyFromFile(file); + } + } + finally + { + file.Close(); } if (obj!=null) @@ -102,8 +109,6 @@ objects = new List(); objects.Add(obj); } - - file.Close(); return objects; } diff -r c4cf4c7db7d5 -r 70ba3bee0c2e api/Factories/Xml/WarFoundryXmlFactory.cs --- a/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Oct 31 20:55:19 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Mon Nov 02 20:58:01 2009 +0000 @@ -76,7 +76,7 @@ private XmlElement GetRootElementFromStream(Stream stream, WarFoundryXmlElementName elementName) { XmlDocument doc = WarFoundryXmlFactoryUtils.CreateXmlDocumentFromStream(stream); - stream.Close(); + XmlElement elem = (XmlElement)doc.LastChild; if (!elem.LocalName.Equals(elementName.Value)) @@ -108,12 +108,12 @@ { XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT); LogNotifier.Debug(GetType(), "Create Race"); - return raceFactory.CreateRaceFromElement(file, elem); - } - - protected override void CleanUpFileAsSupportedType(ZipFile typedFile) - { - typedFile.Close(); + return raceFactory.CreateRaceFromElement(file, elem); + } + + protected override void CleanUpFileAsSupportedType(ZipFile typedFile) + { + typedFile.Close(); } public override void CompleteLoading(IWarFoundryStagedLoadObject obj)