From ed9956ba0bf7a7125cef0c030ee9de3bf506cc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danilo=20Gon=C3=A7alves?= Date: Tue, 26 Jul 2016 17:18:39 -0300 Subject: [PATCH] Make the paths compatible with Linux paths by using System.IO.Path.DirectorySeparatorChar --- PoGo.NecroBot.CLI/Program.cs | 3 ++- PoGo.NecroBot.CLI/Settings.cs | 10 ++++++---- PoGo.NecroBot.Logic/Logging/Logger.cs | 4 ++-- PoGo.NecroBot.Logic/State/PositionCheckState.cs | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/PoGo.NecroBot.CLI/Program.cs b/PoGo.NecroBot.CLI/Program.cs index e0e8d375c..31eb09ec6 100644 --- a/PoGo.NecroBot.CLI/Program.cs +++ b/PoGo.NecroBot.CLI/Program.cs @@ -1,6 +1,7 @@ #region using directives using System; +using System.IO; using System.Diagnostics; using System.Threading; using System.Windows.Forms; @@ -38,7 +39,7 @@ private static void Main(string[] args) { string subPath = ""; if (args.Length > 0) - subPath = "\\" + args[0]; + subPath = Path.DirectorySeparatorChar + args[0]; Logger.SetLogger(new ConsoleLogger(LogLevel.Info), subPath); diff --git a/PoGo.NecroBot.CLI/Settings.cs b/PoGo.NecroBot.CLI/Settings.cs index dc4549edc..1d9db15fa 100644 --- a/PoGo.NecroBot.CLI/Settings.cs +++ b/PoGo.NecroBot.CLI/Settings.cs @@ -21,7 +21,9 @@ internal class AuthSettings { public AuthSettings() { - if (File.Exists(Directory.GetCurrentDirectory() + "\\config\\auth.json")) return; + if (File.Exists(Directory.GetCurrentDirectory() + + Path.DirectorySeparatorChar +"config" + + Path.DirectorySeparatorChar + "auth.json")) return; string type; do { @@ -108,9 +110,9 @@ public class GlobalSettings public static GlobalSettings Load(string path) { ProfilePath = Directory.GetCurrentDirectory() + path; - ConfigPath = ProfilePath + "\\config"; + ConfigPath = ProfilePath + Path.DirectorySeparatorChar + "config"; - var fullPath = ConfigPath + "\\config.json"; + var fullPath = ConfigPath + Path.DirectorySeparatorChar + "config.json"; GlobalSettings settings = null; if (File.Exists(fullPath)) @@ -130,7 +132,7 @@ public static GlobalSettings Load(string path) settings = new GlobalSettings(); } settings.Save(fullPath); - settings.Auth.Load(ConfigPath + "\\auth.json"); + settings.Auth.Load(ConfigPath + Path.DirectorySeparatorChar + "auth.json"); return settings; } diff --git a/PoGo.NecroBot.Logic/Logging/Logger.cs b/PoGo.NecroBot.Logic/Logging/Logger.cs index 86c81a1ce..d2f30ab7e 100644 --- a/PoGo.NecroBot.Logic/Logging/Logger.cs +++ b/PoGo.NecroBot.Logic/Logging/Logger.cs @@ -15,13 +15,13 @@ public static class Logger private static void Log(string message) { // maybe do a new log rather than appending? - Directory.CreateDirectory(Directory.GetCurrentDirectory() + _subPath + "\\Logs"); + Directory.CreateDirectory(Directory.GetCurrentDirectory() + _subPath + Path.DirectorySeparatorChar + "Logs"); using ( var log = File.AppendText(Directory.GetCurrentDirectory() + _subPath + - $"\\Logs\\NecroBot-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt") + $"{Path.DirectorySeparatorChar}Logs{Path.DirectorySeparatorChar}NecroBot-{DateTime.Today.ToString("yyyy-MM-dd")}-{DateTime.Now.ToString("HH")}.txt") ) { log.WriteLine(message); diff --git a/PoGo.NecroBot.Logic/State/PositionCheckState.cs b/PoGo.NecroBot.Logic/State/PositionCheckState.cs index ed3bfae11..7734f7fe1 100644 --- a/PoGo.NecroBot.Logic/State/PositionCheckState.cs +++ b/PoGo.NecroBot.Logic/State/PositionCheckState.cs @@ -13,7 +13,7 @@ public class PositionCheckState : IState { public IState Execute(Context ctx, StateMachine machine) { - var coordsPath = Directory.GetCurrentDirectory() + "\\Configs\\Coords.ini"; + var coordsPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Configs"+ Path.DirectorySeparatorChar+ "Coords.ini"; if (File.Exists(coordsPath)) { var latLngFromFile = LoadPositionFromDisk(machine); @@ -63,10 +63,10 @@ public IState Execute(Context ctx, StateMachine machine) private static Tuple LoadPositionFromDisk(StateMachine machine) { - if (File.Exists(Directory.GetCurrentDirectory() + "\\Configs\\Coords.ini") && - File.ReadAllText(Directory.GetCurrentDirectory() + "\\Configs\\Coords.ini").Contains(":")) + if (File.Exists(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Configs"+ Path.DirectorySeparatorChar + "Coords.ini") && + File.ReadAllText(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar+"Configs"+ Path.DirectorySeparatorChar + "Coords.ini").Contains(":")) { - var latlngFromFile = File.ReadAllText(Directory.GetCurrentDirectory() + "\\Configs\\Coords.ini"); + var latlngFromFile = File.ReadAllText(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "Configs"+ Path.DirectorySeparatorChar + "Coords.ini"); var latlng = latlngFromFile.Split(':'); if (latlng[0].Length != 0 && latlng[1].Length != 0) {