From 32a9f8afa61a4d18e0c4453aa1d72a9ce9e5e59d Mon Sep 17 00:00:00 2001 From: C9Glax <13404778+C9Glax@users.noreply.github.com> Date: Sun, 13 Nov 2022 16:53:03 +0100 Subject: [PATCH] Added launch args --- Executable/Program.cs | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/Executable/Program.cs b/Executable/Program.cs index ebe3cd8..7d6e19b 100644 --- a/Executable/Program.cs +++ b/Executable/Program.cs @@ -3,9 +3,47 @@ using Logging; using astar; using OSM_XML_Importer; -Logger logger = new (LogType.CONSOLE, LogLevel.DEBUG); -Graph.Graph graph = Importer.Import(@"C:\Users\glax\Downloads\oberbayern-latest.osm", true, logger); -logger.level = LogLevel.DEBUG; +string[] confirmation = { "yes", "1", "true" }; + +Logger logger = new(LogType.CONSOLE, LogLevel.DEBUG); +string xmlPath; +bool onlyJunctions; +switch (args.Length) +{ + case 0: + xmlPath = @""; + onlyJunctions = true; + break; + case 1: + xmlPath = args[0]; + onlyJunctions = true; + if (!File.Exists(xmlPath)) + { + logger.Log(LogLevel.ERROR, "File {0} does not exist.", xmlPath); + return; + } + break; + case 2: + xmlPath = args[0]; + if (!File.Exists(xmlPath)) + { + logger.Log(LogLevel.ERROR, "File {0} does not exist.", xmlPath); + return; + } + if (confirmation.Contains(args[1].ToLower())) + onlyJunctions = true; + else + onlyJunctions = false; + break; + default: + logger.Log(LogLevel.ERROR, "Invalid Arguments."); + logger.Log(LogLevel.INFO, "Arguments can be:"); + logger.Log(LogLevel.INFO, "arg0 Path to file: string"); + logger.Log(LogLevel.INFO, "arg1 onlyJunctions: 'yes', '1', 'true'"); + return; +} + +Graph.Graph graph = Importer.Import(xmlPath, onlyJunctions, logger); Random r = new(); Route _route; @@ -19,4 +57,4 @@ do _route = new Astar().FindPath(graph, n1, n2, logger); } while (!_route.routeFound); logger.Log(LogLevel.INFO, "Press Enter to find new path."); -} while (Console.ReadKey().Key.Equals(ConsoleKey.Enter)); \ No newline at end of file +} while (Console.ReadKey().Key.Equals(ConsoleKey.Enter));