From e3537aa934749edb4806284d530c9ae347e768e0 Mon Sep 17 00:00:00 2001 From: ReddoKiddo Date: Fri, 22 Jul 2016 21:45:27 +0300 Subject: [PATCH] Added check for valid Coords.txt Added check if file contains ":" and if the length of lat/lng is not 0 (prevent crash from invalid input of coordinate to setcoordinates() function) --- PokemonGo.RocketAPI/Client.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PokemonGo.RocketAPI/Client.cs b/PokemonGo.RocketAPI/Client.cs index aab67df40..f6db3f762 100644 --- a/PokemonGo.RocketAPI/Client.cs +++ b/PokemonGo.RocketAPI/Client.cs @@ -28,11 +28,18 @@ public class Client public Client(ISettings settings) { Settings = settings; - if (File.Exists(Directory.GetCurrentDirectory() + "\\Coords.txt")) + if (File.Exists(Directory.GetCurrentDirectory() + "\\Coords.txt") && File.ReadAllText(Directory.GetCurrentDirectory() + "\\Coords.txt").Contains(":")) { var latlngFromFile = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Coords.txt"); var latlng = latlngFromFile.Split(':'); - SetCoordinates(Convert.ToDouble(latlng[0]), Convert.ToDouble(latlng[1]), Settings.DefaultAltitude); + if (latlng[0].Length != 0 && latlng[1].Length != 0) + { + SetCoordinates(Convert.ToDouble(latlng[0]), Convert.ToDouble(latlng[1]), Settings.DefaultAltitude); + } + else + { + SetCoordinates(Settings.DefaultLatitude, Settings.DefaultLongitude, Settings.DefaultAltitude); + } } else {