diff options
Diffstat (limited to 'src/Program')
-rw-r--r-- | src/Program/Program.cs | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/Program/Program.cs b/src/Program/Program.cs index f4c83d1..9985c10 100644 --- a/src/Program/Program.cs +++ b/src/Program/Program.cs @@ -9,13 +9,14 @@ namespace ClosestPair { public static void Main(string[] args) { - FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : new FileInfo("points1.txt"); + FileInfo inputFile = (args.Length > 0) ? new FileInfo(args[0]) : ReadFileName(); - if (!inputFile.Exists) { + if (!inputFile.Exists) + { Console.WriteLine($"Failed to open {inputFile}: File does not exist."); return; } - + Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Point[] points = PointFile.ReadFile(inputFile.FullName); @@ -28,6 +29,28 @@ namespace ClosestPair Console.WriteLine($"Closest Points: {closestPair.ToString("F3")}"); Console.WriteLine($"Runtime: {ts.ToString("mm\\:ss\\.ff")}"); } + public static FileInfo ReadFileName() + { + FileInfo file = new FileInfo(" "); + string? filePath; + + while (true) + { + Console.Write("Enter a path to a points file: "); + filePath = Console.ReadLine(); + + if (String.IsNullOrEmpty(filePath)) + Console.WriteLine("File path cannot be empty!"); + else if (!System.IO.File.Exists(filePath)) + Console.WriteLine($"{filePath} does not exist."); + else + break; + } + + file = new FileInfo(filePath); + + return file; + } } }
\ No newline at end of file |