# HG changeset patch # User IBBoard # Date 1253990916 0 # Node ID 1d13820b3d96fd49484f908c1c33a4a2357239c7 # Parent b36cc4af435b986741443b051574a424f0ef04ea 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!) diff -r b36cc4af435b -r 1d13820b3d96 api/Factories/AbstractNativeWarFoundryFactory.cs --- a/api/Factories/AbstractNativeWarFoundryFactory.cs Sat Sep 26 10:43:28 2009 +0000 +++ b/api/Factories/AbstractNativeWarFoundryFactory.cs Sat Sep 26 18:48:36 2009 +0000 @@ -101,8 +101,8 @@ { objects = new List(); objects.Add(obj); - } - + } + file.Close(); return objects; @@ -110,19 +110,19 @@ protected Army CreateArmyFromFile(ZipFile 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(); + 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(); } } @@ -130,7 +130,7 @@ protected abstract Army CreateArmyFromStream(ZipFile file, Stream dataStream); protected Race CreateRaceFromFile(ZipFile file) - { + { Stream dataStream = GetRaceDataStream(file); try @@ -139,11 +139,11 @@ } catch (InvalidFileException ex) { - throw new InvalidFileException("Data file "+file.Name+" was not a valid race file", ex); - } - finally - { - dataStream.Close(); + throw new InvalidFileException("Data file "+file.Name+" was not a valid race file", ex); + } + finally + { + dataStream.Close(); } } @@ -151,20 +151,20 @@ protected abstract Race CreateRaceFromStream(ZipFile file, Stream dataStream); protected GameSystem CreateGameSystemFromFile(ZipFile 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(); + { + 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(); } } diff -r b36cc4af435b -r 1d13820b3d96 api/Factories/AbstractWarFoundryFactory.cs --- a/api/Factories/AbstractWarFoundryFactory.cs Sat Sep 26 10:43:28 2009 +0000 +++ b/api/Factories/AbstractWarFoundryFactory.cs Sat Sep 26 18:48:36 2009 +0000 @@ -19,26 +19,59 @@ public bool CanHandleFileFormat (FileInfo file) { - FILE_TYPE typedFile = GetFileAsSupportedType(file); - return typedFile != null && CheckCanHandleFileFormat(typedFile); + FILE_TYPE typedFile = GetFileAsSupportedType(file); + bool canHandle = typedFile != null && CheckCanHandleFileFormat(typedFile); + + if (typedFile != null) + { + CleanUpFileAsSupportedType(typedFile); + } + + return canHandle; } public bool CanHandleFileAsRace(FileInfo file) { - FILE_TYPE typedFile = GetFileAsSupportedType(file); - return typedFile != null && CheckCanHandleFileAsRace(typedFile); + FILE_TYPE typedFile = GetFileAsSupportedType(file); + bool canHandle = typedFile != null && CheckCanHandleFileAsRace(typedFile); + + if (typedFile != null) + { + CleanUpFileAsSupportedType(typedFile); + } + + return canHandle; } public bool CanHandleFileAsGameSystem(FileInfo file) { - FILE_TYPE typedFile = GetFileAsSupportedType(file); - return typedFile != null && CheckCanHandleFileAsGameSystem(typedFile); + FILE_TYPE typedFile = GetFileAsSupportedType(file); + bool canHandle = typedFile != null && CheckCanHandleFileAsGameSystem(typedFile); + + if (typedFile != null) + { + CleanUpFileAsSupportedType(typedFile); + } + + return canHandle; } public bool CanHandleFileAsArmy(FileInfo file) { FILE_TYPE typedFile = GetFileAsSupportedType(file); - return typedFile != null && CheckCanHandleFileAsArmy(typedFile); + bool canHandle = typedFile != null && CheckCanHandleFileAsArmy(typedFile); + + if (typedFile != null) + { + CleanUpFileAsSupportedType(typedFile); + } + + return canHandle; + } + + protected virtual void CleanUpFileAsSupportedType(FILE_TYPE typedFile) + { + //Do nothing by default } /// diff -r b36cc4af435b -r 1d13820b3d96 api/Factories/Xml/WarFoundryXmlFactory.cs --- a/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Sep 26 10:43:28 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Sep 26 18:48:36 2009 +0000 @@ -108,7 +108,12 @@ { XmlElement elem = GetRootElementFromStream(dataStream, WarFoundryXmlElementName.RACE_ELEMENT); LogNotifier.Debug(GetType(), "Create Race"); - return raceFactory.CreateRaceFromElement(file, elem); + return raceFactory.CreateRaceFromElement(file, elem); + } + + protected override void CleanUpFileAsSupportedType(ZipFile typedFile) + { + typedFile.Close(); } public override void CompleteLoading(IWarFoundryStagedLoadObject obj) diff -r b36cc4af435b -r 1d13820b3d96 api/Objects/Unit.cs --- a/api/Objects/Unit.cs Sat Sep 26 10:43:28 2009 +0000 +++ b/api/Objects/Unit.cs Sat Sep 26 18:48:36 2009 +0000 @@ -86,11 +86,11 @@ if (CanEquipWithItem(unitEquip)) { if (unitEquip.IsRatioLimit) - { + { SetEquipmentRatio(unitEquip, unitEquip.MinPercentage); } else - { + { SetEquipmentAmount(unitEquip, unitEquip.MinNumber); } }