From e0f17c1953aa24fc8b7fb12b3b298ffd27b4346f Mon Sep 17 00:00:00 2001 From: C9Glax Date: Wed, 11 May 2022 21:13:33 +0200 Subject: [PATCH] Added custom-file functionality --- Executable/Program.cs | 2 +- OpenStreetMap Importer/Importer.cs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Executable/Program.cs b/Executable/Program.cs index 8a82e22..d31efc2 100644 --- a/Executable/Program.cs +++ b/Executable/Program.cs @@ -1,3 +1,3 @@ Logging.Logger logger = new (Logging.LogType.CONSOLE, Logging.LogLevel.DEBUG); -Dictionary nodes = OpenStreetMap_Importer.Importer.Import(logger); +Dictionary nodes = OpenStreetMap_Importer.Importer.Import("", logger); astar.Astar astar = new(nodes, logger); \ No newline at end of file diff --git a/OpenStreetMap Importer/Importer.cs b/OpenStreetMap Importer/Importer.cs index c1b9cbd..a1921ca 100644 --- a/OpenStreetMap Importer/Importer.cs +++ b/OpenStreetMap Importer/Importer.cs @@ -7,8 +7,21 @@ namespace OpenStreetMap_Importer public class Importer { - public static Dictionary Import(Logger ?logger = null) + public static Dictionary Import(string filePath = "", Logger ?logger = null) { + + Stream mapData; + if (!File.Exists(filePath)) + { + mapData = new MemoryStream(OSM_Data.map); + logger?.Log(LogLevel.INFO, "Filepath '{0}' does not exist.", filePath); + } + else + { + mapData = new FileStream(filePath, FileMode.Open, FileAccess.Read); + logger?.Log(LogLevel.INFO, "File '{0}' loaded.", filePath); + } + List ways = new(); Dictionary nodes = new(); @@ -26,7 +39,7 @@ namespace OpenStreetMap_Importer IgnoreWhitespace = true, IgnoreComments = true }; - XmlReader reader = XmlReader.Create(new MemoryStream(OSM_Data.map), readerSettings); + XmlReader reader = XmlReader.Create(mapData, readerSettings); reader.MoveToContent(); while (reader.Read()) { @@ -94,7 +107,7 @@ namespace OpenStreetMap_Importer logger?.Log(LogLevel.DEBUG, "Ways: {0} Nodes: {1}", ways.Count, nodes.Count); reader.Close(); - reader = XmlReader.Create(new MemoryStream(OSM_Data.map), readerSettings); + reader = XmlReader.Create(mapData, readerSettings); reader.MoveToContent(); /*