Mercurial > repos > snowblizz-super-API-ideas
changeset 148:8e636443aa8e
Re #176: Bug when saving recently edited army
* Try to make sure that we clear up our open streams
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 26 Sep 2009 10:14:04 +0000 |
parents | 938409fc24cc |
children | c01366bd1627 |
files | api/Factories/AbstractNativeWarFoundryFactory.cs |
diffstat | 1 files changed, 38 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/api/Factories/AbstractNativeWarFoundryFactory.cs Fri Sep 25 19:17:54 2009 +0000 +++ b/api/Factories/AbstractNativeWarFoundryFactory.cs Sat Sep 26 10:14:04 2009 +0000 @@ -108,21 +108,40 @@ protected Army CreateArmyFromFile(ZipFile file) { - return CreateArmyFromStream(file, GetArmyDataStream(file)); + Stream dataStream = GetArmyDataStream(file); + + try + { + return CreateArmyFromStream(file, dataStream); + } + catch (InvalidFileException ex) + { + throw new InvalidFileException("Data file " + file.Name + " was not a valid army file", ex); + } + finally + { + dataStream.Close(); + } } protected abstract Stream GetArmyDataStream(ZipFile file); protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream); protected Race CreateRaceFromFile(ZipFile file) - { + { + Stream dataStream = GetRaceDataStream(file); + try { - return CreateRaceFromStream(file, GetRaceDataStream(file)); + return CreateRaceFromStream(file, dataStream); } catch (InvalidFileException ex) { - throw new InvalidFileException("Data file "+file.Name+" was not a valid race file", ex); + throw new InvalidFileException("Data file "+file.Name+" was not a valid race file", ex); + } + finally + { + dataStream.Close(); } } @@ -130,8 +149,21 @@ protected abstract Race CreateRaceFromStream(ZipFile file, Stream dataStream); protected GameSystem CreateGameSystemFromFile(ZipFile file) - { - return CreateGameSystemFromStream(file, GetGameSystemDataStream(file)); + { + Stream dataStream = GetGameSystemDataStream(file); + + try + { + return CreateGameSystemFromStream(file, dataStream); + } + catch (InvalidFileException ex) + { + throw new InvalidFileException("Data file " + file.Name + " was not a valid game system file", ex); + } + finally + { + dataStream.Close(); + } } protected abstract Stream GetGameSystemDataStream(ZipFile file);