private static DataStore _Parse(StreamReader reader) { DataStore newData = new DataStore(); string line; //Read until we see "REACHABLE ITEM LOCATIONS". bool sawReachableItemLocations = false; while ((line = reader.ReadLine()) != null) { if (line.Equals("REACHABLE ITEM LOCATIONS")) { sawReachableItemLocations = true; break; } } if (!sawReachableItemLocations) { throw new HelperLogException("Expected to see 'RECHABLE ITEM LOCATIONS' but hit end of file."); } line = reader.ReadLine(); if (!Regex.Match(line, @"There are [0-9]+ unchecked reachable locations.", RegexOptions.None).Success) { throw new HelperLogException($"Expected to see 'There are N unchecked reachable locations.' but got {line}"); } line = reader.ReadLine(); if (!"".Equals(line)) { throw new HelperLogException($"Expected a blank line but got {line}"); } bool sawCheckedItemLocations = false; Location currentLocation = null; const string itemPrefix = " - "; while ((line = reader.ReadLine()) != null) { if (line.Equals("CHECKED ITEM LOCATIONS")) { sawCheckedItemLocations = true; break; } else if (line.Equals("")) { if (currentLocation != null) { try { newData.AddReachableLocation(currentLocation.Name, currentLocation); } catch (ArgumentException e) { DebugLog.Warn($"Ignoring duplicate entry for location {currentLocation.Name} (old value = {newData.GetReachableLocation(currentLocation.Name)}, new value = {currentLocation}) {e}"); } } currentLocation = null; } else if (line.StartsWith(itemPrefix)) { currentLocation.Items.Add(line.Substring(itemPrefix.Length)); } else { currentLocation = new Location(line); } } if (!sawCheckedItemLocations) { throw new HelperLogException("Expected to see 'CHECKED ITEM LOCATIONS' but reached end of file."); } while ((line = reader.ReadLine()) != null) { if (Regex.Match(line, @"Generated helper log in [0-9.]+ seconds\.", RegexOptions.None).Success) { break; } else if (line.Equals("")) { if (currentLocation != null) { try { newData.AddCheckedLocation(currentLocation.Name, currentLocation); } catch (ArgumentException e) { DebugLog.Warn($"Ignoring duplicate entry for locationg {currentLocation.Name} (old value = {newData.GetCheckedLocation(currentLocation.Name)}, new value = {currentLocation}) {e}"); } } currentLocation = null; } else if (line.StartsWith(itemPrefix)) { currentLocation.Items.Add(line.Substring(itemPrefix.Length)); } else { currentLocation = new Location(line); } } return(newData); }