# HG changeset patch # User IBBoard # Date 1261237250 0 # Node ID c931684f90243b15e50bfd79353b65d6963ab53d # Parent 0d5a17f33a369c3fc66e0ce9e669477d6af51cd7 Re #234: Invalid data file doesn't stop load * Add internal methods to remove game systems or races that fail to load * Add error handling on XML CompleteLoading so that game system or race is removed, but make sure not to affect error diff -r 0d5a17f33a36 -r c931684f9024 api/Factories/Xml/WarFoundryXmlFactory.cs --- a/api/Factories/Xml/WarFoundryXmlFactory.cs Thu Dec 17 20:52:22 2009 +0000 +++ b/api/Factories/Xml/WarFoundryXmlFactory.cs Sat Dec 19 15:40:50 2009 +0000 @@ -118,16 +118,43 @@ public override void CompleteLoading(IWarFoundryStagedLoadObject obj) { - LogNotifier.DebugFormat(GetType(), "Complete loading of {0} with ID {1}", obj.GetType().Name, obj.ID); - - if (obj is GameSystem) - { - gameSystemFactory.CompleteLoading((GameSystem)obj); - } - else if (obj is Race) - { - raceFactory.CompleteLoading((Race)obj); - } + LogNotifier.DebugFormat(GetType(), "Complete loading of {0} with ID {1}", obj.GetType().Name, obj.ID); + + if (obj is GameSystem) + { + CompleteLoadingGameSystem((GameSystem) obj); + } + else if (obj is Race) + { + CompleteLoadingRace((Race) obj); + } + } + + private void CompleteLoadingRace(Race race) + { + try + { + raceFactory.CompleteLoading(race); + } + catch (InvalidFileException ex) + { + WarFoundryLoader.GetDefault().RemoveRace(race); + throw; + } + } + + private void CompleteLoadingGameSystem(GameSystem system) + { + try + { + gameSystemFactory.CompleteLoading(system); + + } + catch (InvalidFileException ex) + { + WarFoundryLoader.GetDefault().RemoveGameSystem(system); + throw; + } } } } \ No newline at end of file diff -r 0d5a17f33a36 -r c931684f9024 api/WarFoundryLoader.cs --- a/api/WarFoundryLoader.cs Thu Dec 17 20:52:22 2009 +0000 +++ b/api/WarFoundryLoader.cs Sat Dec 19 15:40:50 2009 +0000 @@ -588,6 +588,15 @@ GameSystem system; systemsTable.TryGetValue(systemID.ToLower(), out system); return system; + } + + /// + /// Removes a loaded . Used when a GameSystem fails to complete loading + /// + /// The GameSystem to remove + internal void RemoveGameSystem(GameSystem system) + { + systemsTable.Remove(system.ID.ToLower()); } /// @@ -727,26 +736,39 @@ } Race race = null; - - systemID = systemID.ToLower(); - raceID = raceID.ToLower(); - raceSubID = raceSubID.ToLower(); - - Dictionary> races; - racesTable.TryGetValue(systemID, out races); - - if (races!=null) - { - Dictionary subraces; - races.TryGetValue(raceID, out subraces); - - if (subraces!=null) - { - subraces.TryGetValue(raceSubID, out race); - } + + Dictionary subraces = GetRaceTable(systemID, raceID); + + if (subraces != null) + { + subraces.TryGetValue(raceSubID.ToLower(), out race); } - return race; + return race; + } + + private Dictionary GetRaceTable(string systemID, string raceID) + { + Dictionary> races; + racesTable.TryGetValue(systemID.ToLower(), out races); + Dictionary subraces = null; + + if (races != null) + { + races.TryGetValue(raceID.ToLower(), out subraces); + } + + return subraces; + } + + internal void RemoveRace(Race race) + { + Dictionary subraces = GetRaceTable(race.GameSystem.ID, race.ID); + + if (subraces != null) + { + subraces.Remove(race.SubID.ToLower()); + } } /// @@ -873,6 +895,6 @@ } return loadingFactory; - } + } } }