private void LoadPacks() { _allPathableResourceManagers = new List <PathableResourceManager>(); var iconProgressIndicator = new Progress <string>((report) => { GameService.Pathing.Icon.LoadingMessage = report; }); var dirDataReader = new DirectoryReader(_markerDirectory); var dirResourceManager = new PathableResourceManager(dirDataReader); _allPathableResourceManagers.Add(dirResourceManager); dirDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { PackFormat.TacO.Readers.MarkerPackReader.ReadFromXmlPack(fileStream, dirResourceManager); }, ".xml", iconProgressIndicator); // TODO: Cleanup string[] packFiles = Directory.GetFiles(_markerDirectory, "*.zip", SearchOption.AllDirectories); foreach (string packFile in packFiles) { // Potentially contains many packs within var zipDataReader = new ZipArchiveReader(packFile); var zipResourceManager = new PathableResourceManager(zipDataReader); _allPathableResourceManagers.Add(zipResourceManager); zipDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { PackFormat.TacO.Readers.MarkerPackReader.ReadFromXmlPack(fileStream, zipResourceManager); }, ".xml", iconProgressIndicator); } }
public void ReadFromXmlPack(Stream xmlPackStream, PathableResourceManager pathableResourceManager) { string xmlPackContents; using (var xmlReader = new StreamReader(xmlPackStream)) { xmlPackContents = xmlReader.ReadToEnd(); } NanoXml.NanoXmlDocument packDocument = null; bool packLoaded = false; try { packDocument = NanoXmlDocument.LoadFromXml(xmlPackContents); packLoaded = true; } catch (XmlException ex) { Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} at line: {xmlExceptionLine} position: {xmlExceptionPosition} due to an XML error.", pathableResourceManager.DataReader.GetPathRepresentation(), ex.LineNumber, ex.LinePosition); } catch (Exception ex) { Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} due to an unexpected exception.", pathableResourceManager.DataReader.GetPathRepresentation()); } if (packLoaded) { int currentPathablesCount = this.Pathables.Count; TryLoadCategories(packDocument); TryLoadPOIs(packDocument, pathableResourceManager, Categories); Logger.Info("{pathableDelta} pathables were loaded from {pathableResourceManager}.", this.Pathables.Count - currentPathablesCount, pathableResourceManager.DataReader.GetPathRepresentation()); } }
public static void ReadFromXmlPack(Stream xmlPackStream, PathableResourceManager pathableResourceManager) { string xmlPackContents; using (var xmlReader = new StreamReader(xmlPackStream)) { xmlPackContents = xmlReader.ReadToEnd(); } var packDocument = new XmlDocument(); string packSrc = SanitizeXml(xmlPackContents); bool packLoaded = false; try { packDocument.LoadXml(packSrc); packLoaded = true; } catch (XmlException ex) { Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} from {xmlPackContentsType} due to an XML error.", pathableResourceManager, xmlPackContents); } catch (Exception ex) { Logger.Warn(ex, "Could not load tacO overlay file {pathableResourceManager} from {xmlPackContentsType} due to an unexpected exception.", pathableResourceManager, xmlPackContents); } if (packLoaded) { TryLoadCategories(packDocument); TryLoadPOIs(packDocument, pathableResourceManager, Categories); } }
private void LoadPacks() { _currentReader = new MarkerPackReader(); _allPathableResourceManagers = new List <PathableResourceManager>(); var iconProgressIndicator = new Progress <string>((report) => { _mapIcon.LoadingMessage = report; }); var dirDataReader = new DirectoryReader(_markerDirectory); var dirResourceManager = new PathableResourceManager(dirDataReader); _allPathableResourceManagers.Add(dirResourceManager); dirDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { _currentReader.ReadFromXmlPack(fileStream, dirResourceManager); }, ".xml", iconProgressIndicator); // Load archive marker packs List <string> zipPackFiles = new List <string>(); zipPackFiles.AddRange(Directory.GetFiles(_markerDirectory, "*.zip", SearchOption.AllDirectories)); zipPackFiles.AddRange(Directory.GetFiles(_markerDirectory, "*.taco", SearchOption.AllDirectories)); foreach (string packFile in zipPackFiles) { // Potentially contains many packs within var zipDataReader = new ZipArchiveReader(packFile); var zipResourceManager = new PathableResourceManager(zipDataReader); _allPathableResourceManagers.Add(zipResourceManager); zipDataReader.LoadOnFileType((Stream fileStream, IDataReader dataReader) => { _currentReader.ReadFromXmlPack(fileStream, zipResourceManager); }, ".xml", iconProgressIndicator); } _packsLoaded = true; }
public void RegisterPathableResourceManager(PathableResourceManager pathableContext) { if (pathableContext == null) { return; } this.PackManagers.Add(pathableContext); }
public static void UnpackPathable(NanoXmlNode pathableNode, PathableResourceManager pathableResourceManager, PathingCategory rootCategory) { switch (pathableNode.Name.ToLowerInvariant()) { case ELEMENT_POITYPE_POI: var poiAttributes = AttributeBuilder.FromNanoXmlNode(pathableNode); var newPoiMarker = new Pathables.TacOMarkerPathable(poiAttributes, pathableResourceManager, rootCategory); if (newPoiMarker.SuccessfullyLoaded) { MarkersAndPathsModule.ModuleInstance._currentReader.RegisterPathable(newPoiMarker); } else { Logger.Warn("Failed to load marker: {markerInfo}", poiAttributes); } break; case ELEMENT_POITYPE_TRAIL: var trailAttributes = AttributeBuilder.FromNanoXmlNode(pathableNode); var newPathTrail = new Pathables.TacOTrailPathable(trailAttributes, pathableResourceManager, rootCategory); if (newPathTrail.SuccessfullyLoaded) { MarkersAndPathsModule.ModuleInstance._currentReader.RegisterPathable(newPathTrail); } else { Logger.Warn("Failed to load trail: {trailInfo}", trailAttributes); } break; case ELEMENT_POITYPE_ROUTE: var poiNodes = pathableNode.SelectNodes("poi"); foreach (var poiNode in poiNodes) { UnpackPathable(poiNode, pathableResourceManager, rootCategory); } break; default: Logger.Warn("Tried to pack {pathableNodeName} as a POI!", pathableNode.Name); break; } }
private static void TryLoadPOIs(XmlDocument packDocument, PathableResourceManager pathableResourceManager, PathingCategory rootCategory) { var poiNodes = packDocument.DocumentElement?.SelectSingleNode("/OverlayData/POIs"); if (poiNodes == null) { return; } Logger.Info("Found {poiCount} markers to load.", poiNodes.ChildNodes.Count); foreach (XmlNode poiNode in poiNodes) { Builders.PoiBuilder.UnpackPathable(poiNode, pathableResourceManager, rootCategory); } }
private void TryLoadPOIs(NanoXmlDocument packDocument, PathableResourceManager pathableResourceManager, PathingCategory rootCategory) { var poisNodes = packDocument.RootNode.SelectNodes("pois"); for (int pSet = 0; pSet < poisNodes.Length; pSet++) { //ref var poisNode = ref poisNodes[pSet]; var poisNode = poisNodes[pSet]; Logger.Info("Found {poiCount} POIs to load.", poisNode.SubNodes.Count()); for (int i = 0; i < poisNode.SubNodes.Count; i++) { Builders.PoiBuilder.UnpackPathable(poisNode.SubNodes[i], pathableResourceManager, rootCategory); } } }
public static void UnpackPathable(XmlNode pathableNode, PathableResourceManager pathableResourceManager, PathingCategory rootCategory) { switch (pathableNode.Name.ToLower()) { case ELEMENT_POITYPE_POI: var newPoiMarker = new Pathables.TacOMarkerPathable(pathableNode, pathableResourceManager, rootCategory); if (newPoiMarker.SuccessfullyLoaded) { //Logger.Info("Marker {markerGuid} was successfully loaded!", newPoiMarker.Guid); Readers.MarkerPackReader.RegisterPathable(newPoiMarker); } else { Logger.Warn("Failed to load marker!"); } break; case ELEMENT_POITYPE_TRAIL: var newPathTrail = new Pathables.TacOTrailPathable(pathableNode, pathableResourceManager, rootCategory); if (newPathTrail.SuccessfullyLoaded) { //Logger.Info("Trail {trailGuid} was successfully loaded!", newPathTrail.Guid); Readers.MarkerPackReader.RegisterPathable(newPathTrail); } else { Logger.Warn("Failed to load trail!"); } break; case ELEMENT_POITYPE_ROUTE: Logger.Warn("Support for routes has not been added yet. They have been skipped."); break; default: Logger.Warn("Tried to pack {pathableNodeName} as a POI!", pathableNode.Name); break; } }
public void UnregisterPathableResourceManager(PathableResourceManager pathableContext) { this.PackManagers.Remove(pathableContext); }