Added custom-file functionality

This commit is contained in:
C9Glax 2022-05-11 21:13:33 +02:00
parent 69a97d628f
commit e0f17c1953
2 changed files with 17 additions and 4 deletions

View File

@ -1,3 +1,3 @@
Logging.Logger logger = new (Logging.LogType.CONSOLE, Logging.LogLevel.DEBUG); Logging.Logger logger = new (Logging.LogType.CONSOLE, Logging.LogLevel.DEBUG);
Dictionary<UInt64, Graph.Node> nodes = OpenStreetMap_Importer.Importer.Import(logger); Dictionary<UInt64, Graph.Node> nodes = OpenStreetMap_Importer.Importer.Import("", logger);
astar.Astar astar = new(nodes, logger); astar.Astar astar = new(nodes, logger);

View File

@ -7,8 +7,21 @@ namespace OpenStreetMap_Importer
public class Importer public class Importer
{ {
public static Dictionary<ulong, Node> Import(Logger ?logger = null) public static Dictionary<ulong, Node> 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<Way> ways = new(); List<Way> ways = new();
Dictionary<ulong, Node> nodes = new(); Dictionary<ulong, Node> nodes = new();
@ -26,7 +39,7 @@ namespace OpenStreetMap_Importer
IgnoreWhitespace = true, IgnoreWhitespace = true,
IgnoreComments = true IgnoreComments = true
}; };
XmlReader reader = XmlReader.Create(new MemoryStream(OSM_Data.map), readerSettings); XmlReader reader = XmlReader.Create(mapData, readerSettings);
reader.MoveToContent(); reader.MoveToContent();
while (reader.Read()) while (reader.Read())
{ {
@ -94,7 +107,7 @@ namespace OpenStreetMap_Importer
logger?.Log(LogLevel.DEBUG, "Ways: {0} Nodes: {1}", ways.Count, nodes.Count); logger?.Log(LogLevel.DEBUG, "Ways: {0} Nodes: {1}", ways.Count, nodes.Count);
reader.Close(); reader.Close();
reader = XmlReader.Create(new MemoryStream(OSM_Data.map), readerSettings); reader = XmlReader.Create(mapData, readerSettings);
reader.MoveToContent(); reader.MoveToContent();
/* /*